diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx new file mode 100644 index 0000000..d40e925 --- /dev/null +++ b/src/components/ui/Modal.tsx @@ -0,0 +1,57 @@ +'use client' + +import React, { useEffect, useCallback } from 'react' +import { X } from 'lucide-react' +import { cn } from "@/lib/utils" + +interface ModalProps { + isOpen: boolean + onClose: () => void + children: React.ReactNode + className?: string +} + +export default function Modal({ isOpen, onClose, children, className }: ModalProps) { + const handleEscape = useCallback((e: KeyboardEvent) => { + if (e.key === 'Escape') onClose() + }, [onClose]) + + useEffect(() => { + if (isOpen) { + document.addEventListener('keydown', handleEscape) + document.body.style.overflow = 'hidden' + } + return () => { + document.removeEventListener('keydown', handleEscape) + document.body.style.overflow = 'unset' + } + }, [isOpen, handleEscape]) + + if (!isOpen) return null + + return ( +
+
e.stopPropagation()} + role="dialog" + aria-modal="true" + > + + {children} +
+
+ ) +} \ No newline at end of file