diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx new file mode 100644 index 0000000..5f3752d --- /dev/null +++ b/src/components/ui/Modal.tsx @@ -0,0 +1,73 @@ +'use client' + +import { cn } from "@/lib/utils" +import { X } from 'lucide-react' +import { useEffect, useCallback } from "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 handleKeyDown = useCallback( + (e: KeyboardEvent) => { + if (e.key === "Escape") onClose() + }, + [onClose] + ) + + useEffect(() => { + if (isOpen) { + document.addEventListener("keydown", handleKeyDown) + document.body.style.overflow = "hidden" + } else { + document.body.style.overflow = "unset" + } + return () => { + document.removeEventListener("keydown", handleKeyDown) + document.body.style.overflow = "unset" + } + }, [isOpen, handleKeyDown]) + + if (!isOpen) return null + + return ( +
+ + ) +} \ No newline at end of file