'use client'; import clsx from 'clsx'; import { motion } from 'framer-motion'; import useEscapeKey from '@/hooks/useEscapeKey'; import { HelpTopic } from '@/models/miscellaneous'; import { animateModal } from '@/styling/animations'; import { PARAMETER } from '@/utils/constants'; import { prepareTooltip } from '@/utils/labels'; import { IconClose } from '../Icons'; import BadgeHelp from '../info/BadgeHelp'; import { CProps } from '../props'; import Button from './Button'; import MiniButton from './MiniButton'; import Overlay from './Overlay'; export interface ModalProps extends CProps.Styling { /** Title of the modal window. */ header?: string; /** Text of the submit button. */ submitText?: string; /** Tooltip for the submit button when the form is invalid. */ submitInvalidTooltip?: string; /** Indicates that form is readonly. */ readonly?: boolean; /** Indicates that submit button is enabled. */ canSubmit?: boolean; /** Indicates that the modal window should be scrollable. */ overflowVisible?: boolean; /** Callback to be called when the modal window is closed. */ hideWindow: () => void; /** Callback to be called before submit. */ beforeSubmit?: () => boolean; /** Callback to be called after submit. */ onSubmit?: () => void; /** Callback to be called after cancel. */ onCancel?: () => void; /** Help topic to be displayed in the modal window. */ helpTopic?: HelpTopic; /** Callback to determine if help should be displayed. */ hideHelpWhen?: () => boolean; } /** * Displays a customizable modal window. */ function Modal({ children, header, submitText = 'Продолжить', submitInvalidTooltip, readonly, canSubmit, overflowVisible, hideWindow, beforeSubmit, onSubmit, onCancel, className, helpTopic, hideHelpWhen, ...restProps }: React.PropsWithChildren) { useEscapeKey(hideWindow); const handleCancel = () => { hideWindow(); onCancel?.(); }; const handleSubmit = () => { if (beforeSubmit && !beforeSubmit()) { return; } onSubmit?.(); hideWindow(); }; return (
} onClick={handleCancel} /> {helpTopic && !hideHelpWhen?.() ? ( ) : null} {header ?

{header}

: null}
{children}
{!readonly ? (
); } export default Modal;