diff --git a/plugins/orchestrator/package.json b/plugins/orchestrator/package.json index 80db5b5d22..f5dc506768 100644 --- a/plugins/orchestrator/package.json +++ b/plugins/orchestrator/package.json @@ -107,7 +107,8 @@ "ts-loader": "^8.4.0", "url-loader": "^3.0.0", "webpack": "^5.70.0", - "webpack-cli": "^4.10.0" + "webpack-cli": "^4.10.0", + "@storybook/preview-api": "^7.5.3" }, "peerDependencies": { "react": "^16.13.1 || ^17.0.0", diff --git a/plugins/orchestrator/src/components/InfoDialog.stories.tsx b/plugins/orchestrator/src/components/InfoDialog.stories.tsx new file mode 100644 index 0000000000..9c0ea98116 --- /dev/null +++ b/plugins/orchestrator/src/components/InfoDialog.stories.tsx @@ -0,0 +1,96 @@ +import React from 'react'; + +import { Button } from '@material-ui/core'; +import { useArgs } from '@storybook/preview-api'; +import { Meta, StoryObj } from '@storybook/react'; + +import { InfoDialog } from './InfoDialog'; + +const meta = { + title: 'Orchestrator/InfoDialog', + component: InfoDialog, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +const handleSubmit = () => {}; + +const ConfirmationDialogContent = () => ( +
+ Are you sure you want to submit? By clicking the submit button, you cannot + change the action +
+); +const AlertDialogContent = () => ( +
+ This app sends anonymous location data, even when it is not running. +
+); + +export const ConfirmDialogStory: Story = { + name: 'Confirm Dialog', + args: { + title: 'Confirm', + open: true, + children: , + }, + render: function Render(args) { + const [{ open }, updateArgs] = useArgs(); + + const handleClose = () => { + updateArgs({ open: !open }); + }; + + const DialogActions = () => ( + <> + + + + ); + + return ( + } + /> + ); + }, +}; + +export const AlertDialogStory: Story = { + name: 'Alert Dialog', + args: { + title: 'Alert', + open: true, + children: , + }, + render: function Render(args) { + const [{ open }, updateArgs] = useArgs(); + + const handleClose = () => { + updateArgs({ open: !open }); + }; + + const DialogActions = () => ( + <> + + + ); + + return ( + } + /> + ); + }, +}; diff --git a/plugins/orchestrator/src/components/InfoDialog.tsx b/plugins/orchestrator/src/components/InfoDialog.tsx new file mode 100644 index 0000000000..37a99c911c --- /dev/null +++ b/plugins/orchestrator/src/components/InfoDialog.tsx @@ -0,0 +1,62 @@ +import React, { forwardRef, ForwardRefRenderFunction } from 'react'; + +import { + Box, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + IconButton, + makeStyles, + Typography, +} from '@material-ui/core'; +import CloseIcon from '@material-ui/icons/Close'; + +export type InfoDialogProps = { + title: string; + open: boolean; + onClose?: () => void; + dialogActions?: React.ReactNode; + children: React.ReactNode; +}; + +export type ParentComponentRef = HTMLElement; + +const useStyles = makeStyles(_theme => ({ + closeBtn: { + position: 'absolute', + right: 8, + top: 8, + }, +})); + +export const RefForwardingInfoDialog: ForwardRefRenderFunction< + ParentComponentRef, + InfoDialogProps +> = (props, forwardedRef): JSX.Element | null => { + const { title, open = false, onClose, children, dialogActions } = props; + const classes = useStyles(); + + return ( + onClose} open={open} ref={forwardedRef}> + + + {title} + + + + + + + {children} + + {dialogActions} + + ); +}; + +export const InfoDialog = forwardRef(RefForwardingInfoDialog);