This commit is contained in:
Vula Builder
2026-07-14 17:42:10 +00:00
parent 5b7f9c9af6
commit f863e1ac62
+72
View File
@@ -0,0 +1,72 @@
'use client'
import { useEffect, useCallback } from "react"
import { X } from 'lucide-react'
import { cn } from "@/lib/utils"
interface ModalProps {
isOpen: boolean
onClose: () => void
title?: string
children: React.ReactNode
className?: string
}
export default function Modal({ isOpen, onClose, title, children, className }: ModalProps) {
const handleEscape = useCallback((e: KeyboardEvent) => {
if (e.key === "Escape") onClose()
}, [onClose])
useEffect(() => {
if (isOpen) {
document.body.style.overflow = "hidden"
document.addEventListener("keydown", handleEscape)
}
return () => {
document.body.style.overflow = ""
document.removeEventListener("keydown", handleEscape)
}
}, [isOpen, handleEscape])
if (!isOpen) return null
return (
<div
className="fixed inset-0 z-50 flex items-center justify-center"
role="dialog"
aria-modal="true"
aria-label={title || "Dialog"}
>
{/* Overlay */}
<div
className="fixed inset-0 bg-black/60 backdrop-blur-sm transition-opacity"
onClick={onClose}
aria-hidden="true"
/>
{/* Modal content */}
<div
className={cn(
"relative z-10 w-full max-w-md p-6 bg-white border border-[#daddd4] rounded-lg shadow-xl",
className
)}
>
{/* Close button */}
<button
onClick={onClose}
className="absolute top-3 right-3 p-1 rounded-md text-[#36454F] hover:bg-[#daddd4]/50 focus:outline-none focus:border-[#6b8e23] transition-colors"
aria-label="Close modal"
>
<X size={20} />
</button>
{/* Title */}
{title && (
<h2 className="text-xl font-semibold text-[#2c331f] mb-4 pr-8">
{title}
</h2>
)}
{/* Children */}
<div>{children}</div>
</div>
</div>
)
}