import classNames from 'classnames'; import * as React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import Button from '../button/button'; import IconButton from '../icon-button/icon-button'; const messages = defineMessages({ close: { id: 'lightbox.close', defaultMessage: 'Close' }, confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' }, }); interface IModal { /** Callback when the modal is cancelled. */ cancelAction?: () => void, /** Cancel button text. */ cancelText?: string, /** Callback when the modal is confirmed. */ confirmationAction?: () => void, /** Whether the confirmation button is disabled. */ confirmationDisabled?: boolean, /** Confirmation button text. */ confirmationText?: React.ReactNode, /** Confirmation button theme. */ confirmationTheme?: 'danger', /** Callback when the modal is closed. */ onClose?: () => void, /** Callback when the secondary action is chosen. */ secondaryAction?: () => void, /** Secondary button text. */ secondaryText?: React.ReactNode, /** Don't focus the "confirm" button on mount. */ skipFocus?: boolean, /** Title text for the modal. */ title: string | React.ReactNode, } /** Displays a modal dialog box. */ const Modal: React.FC = ({ cancelAction, cancelText, children, confirmationAction, confirmationDisabled, confirmationText, confirmationTheme, onClose, secondaryAction, secondaryText, skipFocus = false, title, }) => { const intl = useIntl(); const buttonRef = React.useRef(null); React.useEffect(() => { if (buttonRef?.current && !skipFocus) { buttonRef.current.focus(); } }, [skipFocus, buttonRef]); return (

{title}

{onClose && ( )}
{children}
{confirmationAction && (
{cancelAction && ( )}
{secondaryAction && ( )}
)}
); }; export default Modal;