import { useRef, useEffect } from "react"; interface ModalProps { isOpen: boolean; onClose: () => void; className?: string; children: React.ReactNode; showCloseButton?: boolean; // New prop to control close button visibility isFullscreen?: boolean; // Default to false for backwards compatibility } export const Modal: React.FC = ({ isOpen, onClose, children, className, showCloseButton = true, // Default to true for backwards compatibility isFullscreen = false, }) => { const modalRef = useRef(null); useEffect(() => { const handleEscape = (event: KeyboardEvent) => { if (event.key === "Escape") { onClose(); } }; if (isOpen) { document.addEventListener("keydown", handleEscape); } return () => { document.removeEventListener("keydown", handleEscape); }; }, [isOpen, onClose]); useEffect(() => { if (isOpen) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = "unset"; } return () => { document.body.style.overflow = "unset"; }; }, [isOpen]); if (!isOpen) return null; const contentClasses = isFullscreen ? "w-full h-full" : "relative w-full rounded-3xl bg-white dark:bg-gray-900"; return (
{!isFullscreen && (
)}
e.stopPropagation()} > {showCloseButton && ( )}
{children}
); }; export default Modal;