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 (