diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx new file mode 100644 index 0000000..6037c5c --- /dev/null +++ b/src/components/ui/Modal.tsx @@ -0,0 +1,63 @@ +'use client' + +import { ReactNode, useEffect, useRef } from "react" +import { X } from 'lucide-react' +import { cn } from "@/lib/utils" + +interface ModalProps { + open: boolean + onClose: () => void + title?: string + description?: string + children: ReactNode + className?: string +} + +export default function Modal({ open, onClose, title, description, children, className }: ModalProps) { + const contentRef = useRef(null) + + useEffect(() => { + if (!open) return + + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") onClose() + } + + document.addEventListener("keydown", handleKeyDown) + document.body.style.overflow = "hidden" + contentRef.current?.focus() + + return () => { + document.removeEventListener("keydown", handleKeyDown) + document.body.style.overflow = "" + } + }, [open, onClose]) + + if (!open) return null + + return ( +
+ + ) +} \ No newline at end of file