59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect, type ReactNode } from "react"
|
|
import { X } from "lucide-react"
|
|
|
|
interface GlassModalProps {
|
|
title: string
|
|
onClose: () => void
|
|
children: ReactNode
|
|
maxWidth?: string
|
|
}
|
|
|
|
export function GlassModal({ title, onClose, children, maxWidth = "max-w-md" }: GlassModalProps) {
|
|
useEffect(() => {
|
|
const onKey = (e: KeyboardEvent) => {
|
|
if (e.key === "Escape") onClose()
|
|
}
|
|
window.addEventListener("keydown", onKey)
|
|
document.body.style.overflow = "hidden"
|
|
return () => {
|
|
window.removeEventListener("keydown", onKey)
|
|
document.body.style.overflow = ""
|
|
}
|
|
}, [onClose])
|
|
|
|
return (
|
|
<div
|
|
className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4"
|
|
onClick={onClose}
|
|
>
|
|
<div
|
|
className={`relative w-full ${maxWidth} max-h-[85vh] overflow-y-auto rounded-2xl border border-white/20 bg-white/15 p-6 text-white shadow-2xl backdrop-blur-2xl`}
|
|
onClick={(e) => e.stopPropagation()}
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-label={title}
|
|
>
|
|
<div className="mb-5 flex items-center justify-between">
|
|
<h2 className="text-xl font-semibold text-white">{title}</h2>
|
|
<button
|
|
onClick={onClose}
|
|
className="rounded-full p-1 text-white/70 transition-colors hover:bg-white/20 hover:text-white"
|
|
aria-label="Close"
|
|
>
|
|
<X className="h-5 w-5" />
|
|
</button>
|
|
</div>
|
|
{children}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// Shared input styling used across dialogs.
|
|
export const fieldClass =
|
|
"w-full rounded-xl border border-white/20 bg-white/10 px-4 py-2.5 text-white placeholder:text-white/50 focus:outline-none focus:ring-2 focus:ring-white/40"
|
|
|
|
export const labelClass = "mb-1.5 block text-sm font-medium text-white/90"
|