// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { Button } from "@/app/element/button"; import clsx from "clsx"; import ReactDOM from "react-dom"; import "./modal.less"; interface ModalHeaderProps { description?: string; onClose?: () => void; } const ModalHeader = ({ onClose, description }: ModalHeaderProps) => (
{description &&

{description}

} {onClose && ( )}
); interface ModalContentProps { children: React.ReactNode; } function ModalContent({ children }: ModalContentProps) { return
{children}
; } interface ModalFooterProps { okLabel?: string; cancelLabel?: string; onOk?: () => void; onCancel?: () => void; } const ModalFooter = ({ onCancel, onOk, cancelLabel = "Cancel", okLabel = "Ok" }: ModalFooterProps) => { return ( ); }; interface ModalProps { title: string; children?: React.ReactNode; description?: string; okLabel?: string; cancelLabel?: string; className?: string; onClickBackdrop?: () => void; onOk?: () => void; onCancel?: () => void; onClose?: () => void; } const Modal = ({ children, className, title, description, cancelLabel, okLabel, onCancel, onOk, onClose, onClickBackdrop, }: ModalProps) => { const renderBackdrop = (onClick) =>
; const renderFooter = () => { return onOk || onCancel; }; const renderModal = () => (
{renderBackdrop(onClickBackdrop)}
{children}
{renderFooter() && ( )}
); return ReactDOM.createPortal(renderModal(), document.getElementById("main")); }; interface FlexiModalProps { children?: React.ReactNode; className?: string; onClickBackdrop?: () => void; } const FlexiModal = ({ children, className, onClickBackdrop }: FlexiModalProps) => { const renderBackdrop = (onClick) =>
; const renderModal = () => (
{renderBackdrop(onClickBackdrop)}
{children}
); return ReactDOM.createPortal(renderModal(), document.getElementById("main")); }; FlexiModal.Header = ModalHeader; FlexiModal.Content = ModalContent; FlexiModal.Footer = ModalFooter; export { FlexiModal, Modal };