import React from 'react'; import { FiX } from 'react-icons/fi'; function Modal({ isOpen, onClose, title, children, width = 'max-w-lg' }) { // Handle Escape key press - Hooks must be called unconditionally React.useEffect(() => { const handleEscape = (event) => { if (event.key === 'Escape') { onClose(); } }; // Only add listener if modal is open if (isOpen) { document.addEventListener('keydown', handleEscape); } // Cleanup function removes listener return () => { document.removeEventListener('keydown', handleEscape); }; }, [isOpen, onClose]); // Depend on isOpen and onClose // Early return if not open, *after* hooks if (!isOpen) return null; return (
e.stopPropagation()} // Prevent closing when clicking inside modal >

{title}

{children}
); } // Add simple fade-in animation (requires Tailwind config update) // In tailwind.config.js -> theme -> extend -> keyframes & animation: /* keyframes: { 'fade-scale-in': { '0%': { opacity: '0', transform: 'scale(0.95)' }, '100%': { opacity: '1', transform: 'scale(1)' }, } }, animation: { 'fade-scale-in': 'fade-scale-in 0.2s ease-out forwards', } */ export default Modal;