import React, { useEffect, useRef } from 'react'; import { WrapperModalProps } from './types'; import Exit from '../assets/exit.svg'; const WrapperModal: React.FC = ({ children, close, isPerformingTask, }) => { const modalRef = useRef(null); useEffect(() => { if (isPerformingTask) return; const handleClickOutside = (event: MouseEvent) => { if ( modalRef.current && !modalRef.current.contains(event.target as Node) ) { close(); } }; const handleEscapePress = (event: KeyboardEvent) => { if (event.key === 'Escape') { close(); } }; document.addEventListener('mousedown', handleClickOutside); document.addEventListener('keydown', handleEscapePress); return () => { document.removeEventListener('mousedown', handleClickOutside); document.removeEventListener('keydown', handleEscapePress); }; }, [close]); return (
{!isPerformingTask && ( )} {children}
); }; export default WrapperModal;