diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx new file mode 100644 index 0000000..5ed4053 --- /dev/null +++ b/src/components/ui/Modal.tsx @@ -0,0 +1,70 @@ +'use client' + +import { cn } from "@/lib/utils" +import { useEffect, useRef, useState } from "react" +import { X } from 'lucide-react' + +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) + + useEffect(() => { + if (isOpen) { + document.body.style.overflow = "hidden" + } else { + document.body.style.overflow = "" + } + return () => { + document.body.style.overflow = "" + } + }, [isOpen]) + + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") onClose() + } + window.addEventListener("keydown", handleKeyDown) + return () => window.removeEventListener("keydown", handleKeyDown) + }, [onClose]) + + if (!isOpen) return null + + return ( +
{ if (e.target === overlayRef.current) onClose() }} + role="dialog" + aria-modal="true" + aria-labelledby={title ? "modal-title" : undefined} + > +
+ + {title && ( + + )} + {children} +
+
+ ) +} \ No newline at end of file