text: import { useEffect } from 'react';
  import { createPortal } from 'react-dom';
  import PropTypes from 'prop-types';
  import s from './Modal.module.css';
  
  const modalRoot = document.querySelector('#modal-root');
  
  export default function Modal({ onClose, onOpenLargeImage }) {
    useEffect(() => {
      const handleKeyDown = event => {
        if (event.code === 'Escape') {
          onClose();
        }
      };
  
      window.addEventListener('keydown', handleKeyDown);
      return () => {
        window.removeEventListener('keydown', handleKeyDown);
      };
    }, [onClose]);
  
    const handleOverlayClick = event => {
      if (event.currentTarget === event.target) {
        onClose();
      }
    };
  
    return createPortal(
      <div className={s.overlay} onClick={handleOverlayClick}>
        <div className={s.modal}>
          <img src={onOpenLargeImage} alt="" />
        </div>
      </div>,
      modalRoot,
    );
  }
  
  Modal.propTypes = {
    onOpenLargeImage: PropTypes.string.isRequired,
    onClose: PropTypes.func,
  };
  