flwo / client /src /components /ui /Modal.jsx
moustafa7's picture
fix: Modal component accepts both 'open' and 'isOpen' props
35b2cf8
Raw History Blame Contribute Delete
1.24 kB
import { useEffect } from 'react'
import { X } from 'lucide-react'
import { cn } from '../../utils/cn'
export function Modal({ open, isOpen, onClose, children, title, size = 'md' }) {
const isVisible = open ?? isOpen ?? false
useEffect(() => {
if (isVisible) {
document.body.style.overflow = 'hidden'
} else {
document.body.style.overflow = ''
}
return () => { document.body.style.overflow = '' }
}, [isVisible])
if (!isVisible) return null
const sizes = { sm: 'max-w-sm', md: 'max-w-lg', lg: 'max-w-2xl', xl: 'max-w-4xl' }
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div className="fixed inset-0 bg-black/40" onClick={onClose} />
<div className={cn('relative bg-white rounded-2xl shadow-xl w-full max-h-[90vh] overflow-y-auto', sizes[size])}>
<div className="flex items-center justify-between p-4 border-b">
<h3 className="text-lg font-bold text-gray-900">{title}</h3>
<button onClick={onClose} className="p-1 hover:bg-gray-100 rounded-lg">
<X className="w-5 h-5" />
</button>
</div>
<div className="p-4">
{children}
</div>
</div>
</div>
)
}