import React, { useRef } from "react"; import { CloseFunction, OverlayChildrenProps } from "../overlay"; import IconButton from "../icon-button"; import CloseIcon from "../../icons/close-icon"; import Window from "../window"; import classnames from "classnames"; import { ConfirmPopupProps, useConfirmPopup } from "../popup/confirm"; type ModalScrollType = "paper" | "body"; export interface ModalProps { children: | string | React.ReactElement | ((props: OverlayChildrenProps) => React.ReactElement); title?: string | React.ReactElement; show: boolean; onClose: () => void; scrollType?: ModalScrollType; closeConfirmPopup?: ConfirmPopupProps; } const Modal = ({ children, title, show, scrollType = "paper", closeConfirmPopup, onClose, }: ModalProps) => { const el = (props: OverlayChildrenProps) => { if (typeof children === "function") { return children(props); } return children as React.ReactElement; }; const ref = useRef(null); const showConfirmPopup = useConfirmPopup(); const handleBackdropClick = async () => { if (closeConfirmPopup) { const result = await showConfirmPopup(closeConfirmPopup); if (!result) { return; } } onClose(); }; return ( {({ close }) => { return (
{title && (
{title}
} onClick={close} >
)}
{el({ close })}
); }}
); }; export default Modal;