import type { ButtonType } from '@app/components/Common/Button'; import Button from '@app/components/Common/Button'; import CachedImage from '@app/components/Common/CachedImage'; import LoadingSpinner from '@app/components/Common/LoadingSpinner'; import useClickOutside from '@app/hooks/useClickOutside'; import { useLockBodyScroll } from '@app/hooks/useLockBodyScroll'; import globalMessages from '@app/i18n/globalMessages'; import { Transition } from '@headlessui/react'; import type { MouseEvent } from 'react'; import React, { Fragment, useRef } from 'react'; import ReactDOM from 'react-dom'; import { useIntl } from 'react-intl'; interface ModalProps { title?: string; onCancel?: (e?: MouseEvent) => void; onOk?: (e?: MouseEvent) => void; onSecondary?: (e?: MouseEvent) => void; onTertiary?: (e?: MouseEvent) => void; cancelText?: string; okText?: string; secondaryText?: string; tertiaryText?: string; okDisabled?: boolean; cancelButtonType?: ButtonType; okButtonType?: ButtonType; secondaryButtonType?: ButtonType; secondaryDisabled?: boolean; tertiaryDisabled?: boolean; tertiaryButtonType?: ButtonType; disableScrollLock?: boolean; backgroundClickable?: boolean; iconSvg?: React.ReactNode; loading?: boolean; backdrop?: string; children?: React.ReactNode; } const Modal = React.forwardRef( ( { title, onCancel, onOk, cancelText, okText, okDisabled = false, cancelButtonType = 'default', okButtonType = 'primary', children, disableScrollLock, backgroundClickable = true, iconSvg, secondaryButtonType = 'default', secondaryDisabled = false, onSecondary, secondaryText, tertiaryButtonType = 'default', tertiaryDisabled = false, tertiaryText, loading = false, onTertiary, backdrop, }, parentRef ) => { const intl = useIntl(); const modalRef = useRef(null); useClickOutside(modalRef, () => { typeof onCancel === 'function' && backgroundClickable ? onCancel() : undefined; }); useLockBodyScroll(true, disableScrollLock); return ReactDOM.createPortal(
{backdrop && (
)}
{iconSvg &&
{iconSvg}
}
{title && ( {title} )}
{children && (
{children}
)} {(onCancel || onOk || onSecondary || onTertiary) && (
{typeof onOk === 'function' && ( )} {typeof onSecondary === 'function' && secondaryText && ( )} {typeof onTertiary === 'function' && tertiaryText && ( )} {typeof onCancel === 'function' && ( )}
)} , document.body ); } ); Modal.displayName = 'Modal'; export default Modal;