import React, {useState, useEffect} from 'react'; import StyledWrapper from './StyledWrapper'; const ModalHeader = ({title, handleCancel}) => (
{title ?
{title}
: null} {handleCancel ? (
handleCancel() : null}> ×
) : null}
); const ModalContent = ({children}) => (
{children}
); const ModalFooter = ({confirmText, cancelText, handleSubmit, handleCancel, confirmDisabled}) => { confirmText = confirmText || 'Save'; cancelText = cancelText || 'Cancel'; return (
); } const Modal = ({ size, title, confirmText, cancelText, handleCancel, handleConfirm, children, confirmDisabled }) => { const [isClosing, setIsClosing] = useState(false); const escFunction = (event) => { const escKeyCode = 27; if (event.keyCode === escKeyCode) { closeModal(); } }; const closeModal = () => { setIsClosing(true); setTimeout(() => handleCancel(), 500); } useEffect(() => { document.addEventListener('keydown', escFunction, false); return () => { document.removeEventListener('keydown', escFunction, false); } }, []); let classes = 'grafnode-modal'; if (isClosing) { classes += ' modal--animate-out'; } return (
closeModal()} /> {children} closeModal()} handleSubmit={handleConfirm} confirmDisabled={confirmDisabled} />
closeModal()} /> ); }; export default Modal;