import React, { useEffect } from 'react'; import '../styles/Modal.css'; interface ModalProps { isOpen: boolean; onClose: () => void; title: string; children: React.ReactNode; actions?: React.ReactNode; } const Modal: React.FC = ({ isOpen, onClose, title, children, actions }) => { // Close modal when Escape key is pressed useEffect(() => { const handleEscapeKey = (event: KeyboardEvent) => { if (event.key === 'Escape' && isOpen) { onClose(); } }; document.addEventListener('keydown', handleEscapeKey); // Disable body scrolling when modal is open if (isOpen) { document.body.style.overflow = 'hidden'; } return () => { document.removeEventListener('keydown', handleEscapeKey); document.body.style.overflow = ''; }; }, [isOpen, onClose]); if (!isOpen) return null; // Handle click outside the modal content to close it const handleClickOutside = (event: React.MouseEvent) => { if (event.target === event.currentTarget) { onClose(); } }; return (
e.stopPropagation()}>

{title}

{children}
{actions && (
{actions}
)}
); }; export default Modal;