Deploy
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { ReactNode, useEffect, useRef } from "react"
|
||||||
|
import { X } from 'lucide-react'
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
interface ModalProps {
|
||||||
|
open: boolean
|
||||||
|
onClose: () => void
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
children: ReactNode
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Modal({ open, onClose, title, description, children, className }: ModalProps) {
|
||||||
|
const contentRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return
|
||||||
|
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Escape") onClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("keydown", handleKeyDown)
|
||||||
|
document.body.style.overflow = "hidden"
|
||||||
|
contentRef.current?.focus()
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("keydown", handleKeyDown)
|
||||||
|
document.body.style.overflow = ""
|
||||||
|
}
|
||||||
|
}, [open, onClose])
|
||||||
|
|
||||||
|
if (!open) 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 || "Modal"}>
|
||||||
|
<div className="absolute inset-0 bg-black/50" onClick={onClose} aria-hidden="true" />
|
||||||
|
<div
|
||||||
|
ref={contentRef}
|
||||||
|
tabIndex={-1}
|
||||||
|
className={cn("relative w-full max-w-lg rounded-lg border border-border bg-background shadow-lg outline-none", className)}
|
||||||
|
>
|
||||||
|
<div className="flex items-start justify-between gap-4 p-6 pb-2">
|
||||||
|
<div>
|
||||||
|
{title && <h2 className="text-2xl font-semibold text-foreground">{title}</h2>}
|
||||||
|
{description && <p className="mt-1 text-sm text-muted-foreground">{description}</p>}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
className="rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus:outline-none focus:ring-2 focus:ring-[#ea580c]"
|
||||||
|
onClick={onClose}
|
||||||
|
aria-label="Close modal"
|
||||||
|
>
|
||||||
|
<X className="h-5 w-5" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="p-6 pt-2">{children}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user