diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx new file mode 100644 index 0000000..576934c --- /dev/null +++ b/src/components/ui/Modal.tsx @@ -0,0 +1,67 @@ +'use client' + +import { cn } from "@/lib/utils" +import React, { useEffect, useRef } 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(() => { + const handleEscape = (e: KeyboardEvent) => { + if (e.key === 'Escape') onClose() + } + if (isOpen) { + document.addEventListener('keydown', handleEscape) + document.body.style.overflow = 'hidden' + } + return () => { + document.removeEventListener('keydown', handleEscape) + document.body.style.overflow = 'unset' + } + }, [isOpen, onClose]) + + if (!isOpen) return null + + return ( +
{ + if (e.target === overlayRef.current) onClose() + }} + > +
+
+ {title &&

{title}

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