'use client'; import * as React from 'react'; import { X } from 'lucide-react'; import { Button } from './Button'; import { cn } from '@/lib/utils/cn'; export interface ModalProps { open: boolean; onClose: () => void; title: string; description?: string; children: React.ReactNode; footer?: React.ReactNode; size?: 'sm' | 'md' | 'lg' | 'xl'; className?: string; } export function Modal({ open, onClose, title, description, children, footer, size = 'md', className, }: ModalProps) { // Close on Escape key React.useEffect(() => { const handleEscape = (e: KeyboardEvent) => { if (e.key === 'Escape' && open) { onClose(); } }; if (open) { document.addEventListener('keydown', handleEscape); // Prevent body scroll when modal is open document.body.style.overflow = 'hidden'; } return () => { document.removeEventListener('keydown', handleEscape); document.body.style.overflow = 'unset'; }; }, [open, onClose]); if (!open) return null; const sizeClasses = { sm: 'max-w-sm', md: 'max-w-md', lg: 'max-w-lg', xl: 'max-w-xl', }; return (
{description}
)}