import React from 'react' import clsx from 'clsx' import EventListener from 'react-event-listener' import Portal from '../Portal' import IconButton from '../IconButton' import Close from '../vectors/Close' import Backdrop from './Backdrop' import './Modal.scss' interface ModalProps { open: boolean classes?: { root?: string backdrop?: string container?: string header?: string contentPanel?: string content?: string footer?: string } title?: string footerContent?: React.ReactElement onClose?: () => void } const Modal: React.FC = ({ open, classes, title, footerContent, children, onClose, }) => { const rootRef = React.useRef(null) const containerRef = React.useRef(null) const handleReCalculation = React.useCallback(() => { const { current: rootEl } = rootRef const { current: containerEl } = containerRef if (!containerEl || !rootEl) return const { clientHeight, clientWidth } = containerEl rootEl.setAttribute( 'style', `top: calc(50vh - ${Math.round( clientHeight / 2, )}px);left: calc(50vw - ${Math.round( clientWidth / 2, )}px); width: ${clientWidth}px;height: ${clientHeight}px;`, ) }, []) React.useEffect(handleReCalculation, [handleReCalculation, open]) return open ? ( <>
{title ?

{title}

: } } onClick={onClose} /> {children}
{footerContent && ( {footerContent} )}
) : null } export default Modal