This commit is contained in:
Vula Builder
2026-09-15 18:02:59 +00:00
parent cf93c45d68
commit b14c925b9b
+65
View File
@@ -0,0 +1,65 @@
'use client'
import React, { useEffect } from "react"
import { X } from 'lucide-react'
import { cn } from "@/lib/utils"
interface ModalProps {
isOpen: boolean
onClose: () => void
title?: string
description?: string
children: React.ReactNode
className?: string
}
export default function Modal({ isOpen, onClose, title, description, children, className }: ModalProps) {
useEffect(() => {
if (!isOpen) return
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") onClose()
}
document.addEventListener("keydown", handleKeyDown)
const previousOverflow = document.body.style.overflow
document.body.style.overflow = "hidden"
return () => {
document.removeEventListener("keydown", handleKeyDown)
document.body.style.overflow = previousOverflow
}
}, [isOpen, onClose])
if (!isOpen) return null
return (
<div
className="fixed inset-0 z-50 flex items-center justify-center p-4"
role="dialog"
aria-modal="true"
aria-label={title}
>
<div
className="absolute inset-0 bg-foreground/50 backdrop-blur-sm"
onClick={onClose}
aria-hidden="true"
/>
<div
className={cn(
"relative z-10 max-h-[90vh] w-full max-w-lg overflow-y-auto rounded-lg border border-border bg-background p-6 text-foreground shadow-xl",
className
)}
>
<button
type="button"
onClick={onClose}
aria-label="Close dialog"
className="absolute right-4 top-4 rounded-md p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
<X className="h-5 w-5" />
</button>
{title ? <h2 className="pr-8 text-xl font-semibold tracking-tight text-foreground">{title}</h2> : null}
{description ? <p className="mt-1 text-sm text-muted-foreground">{description}</p> : null}
<div className={cn(title || description ? "mt-4" : "")}>{children}</div>
</div>
</div>
)
}