import React, { FC, ReactNode, useEffect, useRef } from 'react'; import ReactModal from 'react-modal'; import css from './index.module.css'; import classnames from 'classnames'; import { MilaGridColumn, MilaGridVoid } from '../../index'; import CloseSVG from '../../assets/icons/icon_close.svg'; export interface ModalRedesignProps { isOpen?: boolean; error?: string; children?: ReactNode; actions?: ReactNode; title?: string; withAnimation: boolean; onRequestClose: () => void; } const ModalRedesign: FC = ({ isOpen, children, onRequestClose, withAnimation = false, ...rest }) => { const modalContent = useRef(); const handleClickOutside = (e): void => { // @ts-ignore if (modalContent.current && !modalContent.current.contains(e.target)) { onRequestClose(); } }; useEffect(() => { document.addEventListener('mousedown', handleClickOutside); return (): void => { document.removeEventListener('mousedown', handleClickOutside); }; }); return (
{ onRequestClose(); }} />
{children}
); }; export default ModalRedesign;