import React, { useEffect } from 'react'; import ReactDOM from 'react-dom'; import ModalOverlay from './ModalOverlay'; import cn from 'classnames'; import { useHistory } from 'react-router'; const DEFAULT_WIDTH = 350; interface Props { component: any; className?: string; props: any; hideModal?: boolean; width?: number; } function Modal({ component, className = 'bg-white', props, hideModal }: Props) { const history = useHistory(); useEffect(() => { return history.listen((location) => { if (history.action === 'POP') { document.querySelector('body').style.overflow = 'visible'; } }); }); return component ? ( ReactDOM.createPortal(
{component}
, document.querySelector('#modal-root') ) ) : ( <> ); } Modal.Header = ({ title, children }: { title?: string, children?: any }) => { return !!children ? (
{children}
): (
{title}
); }; Modal.Content = ({ children, className = 'p-4' }: { children: any; className?: string }) => { return (
{children}
); }; Modal.Footer = ({ children, className = '' }: any) => { return (
{children}
); }; export default Modal;