import {useEffect, useCallback} from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import LoadingOverlay from '@givewp/components/LoadingOverlay'; import styles from './styles.module.scss'; import {__} from '@wordpress/i18n'; const Modal = ({visible = true, type = 'notice', children = {}, isLoading = false, handleClose = () => {}, ...rest}) => { const closeModal = useCallback((event) => { if (event.keyCode === 27 && typeof handleClose === 'function') { handleClose(); } }, []); useEffect(() => { document.addEventListener('keydown', closeModal, false); return () => { document.removeEventListener('keydown', closeModal, false); }; }, []); const handleOverlayClick = (e) => { if (e.target.classList.contains(styles.overlay) && typeof handleClose === 'function') { handleClose(); } }; const modalStyles = classNames({ [styles.modal]: true, [styles.error]: type === 'error' || type === 'failed', [styles.warning]: type === 'warning', [styles.success]: type === 'success', [styles.http]: type === 'http', }); return (
{context instanceof Object
? Object.entries(context).map(([key, value]) => {
return (
{key}:
{value}
);
})
: context}