import React, { useEffect } from 'react'; interface ComponentNameProps { isOpen: boolean; onClose: () => void; title?: string; children: React.ReactNode; footer?: React.ReactNode; size?: 'sm' | 'md' | 'lg' | 'xl'; className?: string; } /** * ComponentName - A modal/dialog component with backdrop * * @param props - Component props * @returns JSX.Element */ export const ComponentName: React.FC = ({ isOpen, onClose, title, children, footer, size = 'md', className = '' }) => { // Handle ESC key press useEffect(() => { const handleEscape = (e: KeyboardEvent) => { if (e.key === 'Escape' && isOpen) { onClose(); } }; document.addEventListener('keydown', handleEscape); return () => document.removeEventListener('keydown', handleEscape); }, [isOpen, onClose]); // Prevent body scroll when modal is open 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; const sizeStyles = { sm: 'max-w-md', md: 'max-w-lg', lg: 'max-w-2xl', xl: 'max-w-4xl', }; return (
{/* Backdrop */} ); }; export default ComponentName;