48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
'use client'
|
|
|
|
import { X } from 'lucide-react'
|
|
import { useEffect } from 'react'
|
|
|
|
interface ModalProps {
|
|
isOpen: boolean
|
|
onClose: () => void
|
|
title?: string
|
|
children: React.ReactNode
|
|
}
|
|
|
|
export default function Modal({ isOpen, onClose, title, children }: ModalProps) {
|
|
useEffect(() => {
|
|
if (isOpen) {
|
|
document.body.style.overflow = 'hidden'
|
|
} else {
|
|
document.body.style.overflow = 'unset'
|
|
}
|
|
return () => {
|
|
document.body.style.overflow = 'unset'
|
|
}
|
|
}, [isOpen])
|
|
|
|
if (!isOpen) 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-celo-dark rounded-xl max-w-lg w-full max-h-[90vh] overflow-y-auto border border-white/20">
|
|
{title && (
|
|
<div className="flex items-center justify-between p-4 border-b border-white/10">
|
|
<h2 className="text-xl font-bold text-white">{title}</h2>
|
|
<button
|
|
onClick={onClose}
|
|
className="p-1 hover:bg-white/10 rounded-lg transition"
|
|
aria-label="Close modal"
|
|
>
|
|
<X size={20} className="text-white" />
|
|
</button>
|
|
</div>
|
|
)}
|
|
<div className="p-4 text-white">{children}</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|