This commit is contained in:
Vula Builder
2026-07-25 19:05:22 +00:00
parent 47613f92cb
commit 647c0aa25b
+68
View File
@@ -0,0 +1,68 @@
'use client'
import React, { useEffect, useRef } from 'react'
import { X } from 'lucide-react'
import { cn } from "@/lib/utils"
interface ModalProps {
open: boolean
onClose: () => void
title?: string
children: React.ReactNode
className?: string
}
export default function Modal({ open, onClose, title, children, className }: ModalProps) {
const overlayRef = useRef<HTMLDivElement>(null)
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose()
}
if (open) {
document.addEventListener('keydown', handleKeyDown)
document.body.style.overflow = 'hidden'
}
return () => {
document.removeEventListener('keydown', handleKeyDown)
document.body.style.overflow = 'auto'
}
}, [open, onClose])
if (!open) return null
const handleOverlayClick = (e: React.MouseEvent) => {
if (e.target === overlayRef.current) onClose()
}
return (
<div
ref={overlayRef}
role="dialog"
aria-modal="true"
onClick={handleOverlayClick}
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm transition-opacity"
>
<div
className={cn(
"relative w-full max-w-lg rounded-xl border border-[#403630] bg-[#1a1512] p-6 shadow-xl",
className
)}
>
<button
onClick={onClose}
aria-label="Close modal"
className="absolute right-4 top-4 rounded-full p-1 text-[#aaa096] hover:text-[#eeeae7] hover:bg-[#8b5a3c]/10 transition-colors"
>
<X size={20} />
</button>
{title && (
<h2 className="mb-4 text-2xl font-semibold text-[#eeeae7]">
{title}
</h2>
)}
{children}
</div>
</div>
)
}