"use client"; import { useEffect } from "react"; import { cn } from "@/shared/utils/cn"; import Button from "./Button"; export default function Modal({ isOpen, onClose, title, children, footer, size = "md", closeOnOverlay = true, showCloseButton = true, className, }) { const sizes = { sm: "max-w-sm", md: "max-w-md", lg: "max-w-lg", xl: "max-w-xl", full: "max-w-4xl", }; // Lock body scroll when modal is open useEffect(() => { if (isOpen) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, [isOpen]); // Handle escape key useEffect(() => { const handleEscape = (e) => { if (e.key === "Escape" && isOpen) { onClose(); } }; document.addEventListener("keydown", handleEscape); return () => document.removeEventListener("keydown", handleEscape); }, [isOpen, onClose]); if (!isOpen) return null; return (
{message}