import { useEffect, useRef } from "react"; import "./Modal.css"; interface ModalProps { isOpen: boolean; onClose?: () => void; title?: string; children: React.ReactNode; footer?: React.ReactNode; } const Modal = ({ isOpen, onClose, title, children, footer }: ModalProps) => { const dialogRef = useRef(null); useEffect(() => { const dialog = dialogRef.current; if (!dialog) return; if (isOpen) { if (!dialog.open) dialog.showModal(); } else { if (dialog.open) dialog.close(); } }, [isOpen]); useEffect(() => { const dialog = dialogRef.current; if (!dialog) return; const handleCancel = () => onClose?.(); dialog.addEventListener("cancel", handleCancel); return () => dialog.removeEventListener("cancel", handleCancel); }, [onClose]); const handleBackdropClick = (e: React.MouseEvent) => { if (e.target === dialogRef.current) onClose?.(); }; return ( // biome-ignore lint/a11y/useKeyWithClickEvents: handles keyboard interaction natively via the cancel event (Escape key)

{title}

{children}
{footer &&
{footer}
}
); }; export default Modal;