import { Box, Dialog } from '@mui/material'; import { forwardRef, useImperativeHandle, useMemo, useState } from 'react'; import { BLUE, TEXT } from '../lib/consts/DEFAULT_THEME'; import ContainedButton from './ContainedButton'; import { Panel, PanelHeader } from './Panels'; import { BodyText, HeaderText } from './Text'; const ConfirmDialog = forwardRef< ConfirmDialogForwardedRefContent, ConfirmDialogProps >( ( { actionCancelText = 'Cancel', actionProceedText, content, dialogProps: { open: baseOpen = false, ...restDialogProps } = {}, onCancelAppend, onProceedAppend, openInitially = false, proceedButtonProps = {}, titleText, }, ref, ) => { const { sx: proceedButtonSx } = proceedButtonProps; const [isOpen, setIsOpen] = useState(openInitially); // TODO: using base open is depreciated; use internal state once all // dependent components finish the migrate. const open = useMemo( () => (ref ? isOpen : baseOpen), [baseOpen, isOpen, ref], ); useImperativeHandle( ref, () => ({ setOpen: (value) => setIsOpen(value), }), [], ); return ( {typeof content === 'string' ? : content} :not(:first-child)': { marginLeft: '.5em', }, }} > { setIsOpen(false); onCancelAppend?.call(null, ...args); }} > {actionCancelText} { setIsOpen(false); onProceedAppend?.call(null, ...args); }} > {actionProceedText} ); }, ); ConfirmDialog.displayName = 'ConfirmDialog'; export default ConfirmDialog;