diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx new file mode 100644 index 0000000..5c7d53a --- /dev/null +++ b/src/components/ui/Modal.tsx @@ -0,0 +1,85 @@ +'use client' + +import { useEffect, useRef, useId } from 'react' +import * as React from 'react' +import { X } from 'lucide-react' +import { cn } from '@/lib/utils' + +interface ModalProps { + open: boolean + onClose: () => void + title?: string + description?: string + children: React.ReactNode + className?: string + showCloseButton?: boolean +} + +export default function Modal({ open, onClose, title, description, children, className, showCloseButton = true }: ModalProps) { + const titleId = React.useId() + const panelRef = React.useRef(null) + + React.useEffect(() => { + if (!open) return + + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Escape') onClose() + } + + const previousFocus = document.activeElement as HTMLElement | null + const originalOverflow = document.body.style.overflow + + panelRef.current?.focus() + document.addEventListener('keydown', handleKeyDown) + document.body.style.overflow = 'hidden' + + return () => { + document.removeEventListener('keydown', handleKeyDown) + document.body.style.overflow = originalOverflow + previousFocus?.focus() + } + }, [open, onClose]) + + if (!open) return null + + return ( +
+ + ) +} \ No newline at end of file