diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx new file mode 100644 index 0000000..4cff882 --- /dev/null +++ b/src/components/ui/Modal.tsx @@ -0,0 +1,75 @@ +'use client' + +import { useEffect, useRef, useState } from "react" +import { X } from 'lucide-react' +import { cn } from "@/lib/utils" + +interface ModalProps { + isOpen: boolean + onClose: () => void + title?: string + children: React.ReactNode + className?: string +} + +export default function Modal({ isOpen, onClose, title, children, className }: ModalProps) { + const overlayRef = useRef(null) + const [mounted, setMounted] = useState(false) + + useEffect(() => { + if (isOpen) { + setMounted(true) + document.body.style.overflow = "hidden" + } else { + document.body.style.overflow = "" + } + return () => { + document.body.style.overflow = "" + } + }, [isOpen]) + + useEffect(() => { + const handleEscape = (e: KeyboardEvent) => { + if (e.key === "Escape") onClose() + } + window.addEventListener("keydown", handleEscape) + return () => window.removeEventListener("keydown", handleEscape) + }, [onClose]) + + if (!isOpen && !mounted) return null + + return ( +
{ + if (e.target === overlayRef.current) onClose() + }} + role="dialog" + aria-modal="true" + aria-label={title || "Modal"} + > +
+
+ {title &&

{title}

} + +
+ {children} +
+
+ ) +} \ No newline at end of file