Deploy
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useRef } 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 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
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={overlayRef}
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60"
|
||||
onClick={(e) => { if (e.target === overlayRef.current) onClose() }}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={title || "Dialog"}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"relative w-full max-w-lg rounded-lg bg-white p-6 shadow-xl",
|
||||
className
|
||||
)}
|
||||
>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="absolute right-4 top-4 rounded-sm text-[#21140d] hover:bg-[#f0ebdc] focus:outline-none focus:border-[#8b5a3c]"
|
||||
aria-label="Close"
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
{title && (
|
||||
<h2 className="text-xl font-semibold text-[#21140d] mb-4">{title}</h2>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user