This commit is contained in:
Vula Builder
2026-07-27 17:10:25 +00:00
parent 02a2416b8f
commit 19adf751b6
+71
View File
@@ -0,0 +1,71 @@
'use client'
import { cn } from "@/lib/utils"
import { X } from 'lucide-react'
import React, { useEffect, useRef } from "react"
interface ModalProps {
isOpen: boolean
onClose: () => void
title?: string
children: React.ReactNode
className?: string
}
export default function Modal({ isOpen, onClose, title, children, className }: ModalProps) {
const overlayRef = useRef<HTMLDivElement>(null)
useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {
if (e.key === "Escape") onClose()
}
if (isOpen) {
document.addEventListener("keydown", handleEscape)
document.body.style.overflow = "hidden"
}
return () => {
document.removeEventListener("keydown", handleEscape)
document.body.style.overflow = ""
}
}, [isOpen, onClose])
if (!isOpen) return null
const handleOverlayClick = (e: React.MouseEvent) => {
if (e.target === overlayRef.current) onClose()
}
return (
<div
ref={overlayRef}
className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4"
onClick={handleOverlayClick}
role="dialog"
aria-modal="true"
aria-label={title || "Dialog"}
>
<div
className={cn(
"relative w-full max-w-lg bg-white rounded-lg shadow-xl",
className
)}
>
<button
onClick={onClose}
className="absolute top-3 right-3 p-1 rounded-full hover:bg-[#18181b]/10 focus:outline-none focus:border-primary"
aria-label="Close dialog"
>
<X className="h-5 w-5 text-[#101418]" />
</button>
{title && (
<div className="px-6 pt-6 pb-4 border-b border-[#e7eaef]">
<h2 className="text-xl font-semibold text-[#101418]">{title}</h2>
</div>
)}
<div className="px-6 py-4">
{children}
</div>
</div>
</div>
)
}