import React, { useEffect } from 'react'; import ReactDOM from 'react-dom'; import cn from 'classnames'; import { useHistory } from 'react-router'; import ModalOverlay from './ModalOverlay'; 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(() => history.listen((location) => { if (history.action === 'POP') { document.querySelector('body').style.overflow = 'visible'; } }), ); return component ? ( ReactDOM.createPortal(
{component}
, document.querySelector('#modal-root'), ) ) : ( <> ); } Modal.Header = function ({ title, children, }: { title?: string; children?: any; }) { return children ? (
{children}
) : (
{title}
); }; Modal.Content = function ({ children, className = 'p-4', }: { children: any; className?: string; }) { return (
{children}
); }; Modal.Footer = function ({ children, className = '' }: any) { return (
{children}
); }; export default Modal;