import React from "react"; import { ComponentProps } from "../../types"; import { Button } from "../buttons/button"; import { ModalDialog } from "./dialog"; export interface ModalProps extends ComponentProps { /** * The child component/content for open button */ openChild?: React.ReactNode; /** * The child component/content for close button */ closeChild?: React.ReactNode; /** * The child component/content for modal header */ modalHeader?: React.ReactNode; /** * The child component/content for modal footer */ modalFooter?: React.ReactNode; /** * The child component/content for modal body */ children: React.ReactNode; /** * Open modal on mount when set to true */ showOpen?: boolean; } export const Modal = ({ openChild, closeChild, modalHeader, modalFooter, children, showOpen = false, ...props }: ModalProps) => { const dialogRef = React.useRef(null); const openModal = (): void => { if (dialogRef.current) { if (showOpen) dialogRef.current.show(); else dialogRef.current.showModal(); } }; const closeModal = () => { if (dialogRef.current) { dialogRef.current.close(); } }; return ( <>
{modalHeader} {children} {modalFooter ?? (
{" "}
)}
{!showOpen && ( )} ); }; Modal.displayName = "Modal";