From b20fc1d14982f9e698c334cda4f0c36d313fb4eb Mon Sep 17 00:00:00 2001 From: Vula Builder Date: Sat, 1 Aug 2026 16:13:33 +0000 Subject: [PATCH] Deploy --- src/components/ui/Modal.tsx | 103 ++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/components/ui/Modal.tsx diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx new file mode 100644 index 0000000..5e2cc2f --- /dev/null +++ b/src/components/ui/Modal.tsx @@ -0,0 +1,103 @@ +'use client' + +import { cn } from "@/lib/utils" +import { X } from 'lucide-react' +import { useCallback, useEffect, useRef } from "react" + +interface ModalProps { + isOpen: boolean + onClose: () => void + title?: string + description?: string + children: React.ReactNode + className?: string + showCloseButton?: boolean +} + +export default function Modal({ + isOpen, + onClose, + title, + description, + children, + className, + showCloseButton = true +}: ModalProps) { + const panelRef = useRef(null) + + useEffect(() => { + if (isOpen) { + const originalOverflow = document.body.style.overflow + document.body.style.overflow = "hidden" + return () => { + document.body.style.overflow = originalOverflow + } + } + }, [isOpen]) + + useEffect(() => { + if (isOpen) { + panelRef.current?.focus() + } + }, [isOpen]) + + const handleKeyDown = useCallback( + (event: KeyboardEvent) => { + if (event.key === "Escape") { + onClose() + } + }, + [onClose] + ) + + useEffect(() => { + if (!isOpen) return + document.addEventListener("keydown", handleKeyDown) + return () => document.removeEventListener("keydown", handleKeyDown) + }, [isOpen, handleKeyDown]) + + if (!isOpen) return null + + return ( +
+ + ) +} \ No newline at end of file