shared/ui/Modal.tsx

17 lines
901 B
TypeScript

'use client'
import { ReactNode, useEffect } from 'react'
interface ModalProps { open: boolean; onClose: () => void; title?: string; children: ReactNode; maxWidth?: string }
export default function Modal({ open, onClose, title, children, maxWidth = 'max-w-lg' }: ModalProps) {
useEffect(() => { if (open) document.body.style.overflow = 'hidden'; return () => { document.body.style.overflow = '' } }, [open])
if (!open) return null
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div className="fixed inset-0 bg-black/50" onClick={onClose} />
<div className={`relative bg-white dark:bg-slate-900 rounded-xl shadow-xl border border-slate-200 dark:border-slate-800 w-full ${maxWidth} p-6`}>
{title && <h2 className="text-lg font-semibold text-slate-900 dark:text-white mb-4">{title}</h2>}
{children}
</div>
</div>
)
}