2020-05-23 23:38:20 -04:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import ReactModal from 'react-modal';
|
|
|
|
|
|
2020-06-26 12:34:43 -03:00
|
|
|
import './Modal.css';
|
|
|
|
|
|
2021-07-13 23:48:16 +02:00
|
|
|
import { Typography, Icon } from '../';
|
2022-09-19 20:02:53 -04:00
|
|
|
import { useModal } from '../../contextProviders';
|
2020-05-23 23:38:20 -04:00
|
|
|
|
2021-03-01 16:52:54 +01:00
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
|
ReactModal.setAppElement(document.getElementById('root'));
|
|
|
|
|
}
|
2020-05-23 23:38:20 -04:00
|
|
|
|
|
|
|
|
const Modal = ({
|
|
|
|
|
closeButton,
|
|
|
|
|
shouldCloseOnEsc,
|
|
|
|
|
isOpen,
|
|
|
|
|
title,
|
|
|
|
|
onClose,
|
|
|
|
|
children,
|
2023-04-28 16:13:47 -04:00
|
|
|
shouldCloseOnOverlayClick,
|
2020-05-23 23:38:20 -04:00
|
|
|
}) => {
|
2020-06-26 12:34:43 -03:00
|
|
|
const { hide } = useModal();
|
|
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
hide();
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-23 23:38:20 -04:00
|
|
|
const renderHeader = () => {
|
|
|
|
|
return (
|
|
|
|
|
title && (
|
2023-06-07 08:31:09 -04:00
|
|
|
<header className="flex items-center px-[20px] py-[13px] bg-primary-dark rounded-tl rounded-tr">
|
2020-07-10 12:48:51 -03:00
|
|
|
<Typography
|
2023-06-07 08:31:09 -04:00
|
|
|
variant="h6"
|
|
|
|
|
color="primaryLight"
|
|
|
|
|
className="flex grow !leading-[1.2]"
|
2023-02-17 15:04:07 -05:00
|
|
|
data-cy="modal-header"
|
2020-07-10 12:48:51 -03:00
|
|
|
>
|
|
|
|
|
{title}
|
|
|
|
|
</Typography>
|
2020-05-23 23:38:20 -04:00
|
|
|
{closeButton && (
|
2020-07-10 12:48:51 -03:00
|
|
|
<Icon
|
2020-06-26 12:34:43 -03:00
|
|
|
onClick={onClose}
|
2020-07-10 12:48:51 -03:00
|
|
|
name="close"
|
2023-06-07 08:31:09 -04:00
|
|
|
className="cursor-pointer text-primary-active"
|
2020-07-10 12:48:51 -03:00
|
|
|
/>
|
2020-05-23 23:38:20 -04:00
|
|
|
)}
|
|
|
|
|
</header>
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ReactModal
|
2020-07-10 12:48:51 -03:00
|
|
|
className="relative w-11/12 lg:w-10/12 xl:w-1/2 max-h-full outline-none text-white"
|
2020-06-26 12:34:43 -03:00
|
|
|
overlayClassName="fixed top-0 left-0 right-0 bottom-0 z-50 bg-overlay flex items-start justify-center py-16"
|
2020-05-23 23:38:20 -04:00
|
|
|
shouldCloseOnEsc={shouldCloseOnEsc}
|
2020-06-26 12:34:43 -03:00
|
|
|
onRequestClose={handleClose}
|
2020-05-23 23:38:20 -04:00
|
|
|
isOpen={isOpen}
|
|
|
|
|
title={title}
|
2023-04-28 16:13:47 -04:00
|
|
|
shouldCloseOnOverlayClick={shouldCloseOnOverlayClick}
|
2020-05-23 23:38:20 -04:00
|
|
|
>
|
2020-07-10 12:48:51 -03:00
|
|
|
{renderHeader()}
|
2023-06-07 08:31:09 -04:00
|
|
|
<section className="ohif-scrollbar modal-content overflow-y-auto px-[20px] pt-2 pb-[20px] rounded-bl rounded-br bg-primary-dark">
|
2020-06-26 12:34:43 -03:00
|
|
|
{children}
|
|
|
|
|
</section>
|
2020-05-23 23:38:20 -04:00
|
|
|
</ReactModal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-26 12:34:43 -03:00
|
|
|
Modal.defaultProps = {
|
|
|
|
|
shouldCloseOnEsc: true,
|
2023-04-28 16:13:47 -04:00
|
|
|
shouldCloseOnOverlayClick: true,
|
2020-06-26 12:34:43 -03:00
|
|
|
};
|
|
|
|
|
|
2020-05-23 23:38:20 -04:00
|
|
|
Modal.propTypes = {
|
|
|
|
|
closeButton: PropTypes.bool,
|
|
|
|
|
shouldCloseOnEsc: PropTypes.bool,
|
|
|
|
|
isOpen: PropTypes.bool,
|
|
|
|
|
title: PropTypes.string,
|
|
|
|
|
onClose: PropTypes.func,
|
|
|
|
|
/** The modal's content */
|
|
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
|
|
|
|
PropTypes.node,
|
|
|
|
|
]).isRequired,
|
2023-04-28 16:13:47 -04:00
|
|
|
shouldCloseOnOverlayClick: PropTypes.bool,
|
2020-05-23 23:38:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Modal;
|