Deploy
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
'use client'
|
||||
|
||||
import React, { 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 handleEsc = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose()
|
||||
}
|
||||
if (isOpen) {
|
||||
document.addEventListener('keydown', handleEsc)
|
||||
document.body.style.overflow = 'hidden'
|
||||
}
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleEsc)
|
||||
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/50'
|
||||
onClick={(e) => {
|
||||
if (e.target === overlayRef.current) onClose()
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'relative w-full max-w-lg rounded-lg bg-background p-6 shadow-lg',
|
||||
className
|
||||
)}
|
||||
role='dialog'
|
||||
aria-modal='true'
|
||||
aria-labelledby={title ? 'modal-title' : undefined}
|
||||
>
|
||||
<button
|
||||
className='absolute right-4 top-4 rounded-sm opacity-70 hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-primary'
|
||||
onClick={onClose}
|
||||
aria-label='Close'
|
||||
>
|
||||
<X className='h-4 w-4' />
|
||||
</button>
|
||||
{title && (
|
||||
<h2 id="modal-title" className="text-2xl font-semibold mb-4">
|
||||
{title}
|
||||
</h2>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user