2020-05-23 23:38:20 -04:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import ReactModal from 'react-modal';
|
2023-06-07 10:05:35 -03:00
|
|
|
import { useModal } from '../../contextProviders';
|
2020-05-23 23:38:20 -04:00
|
|
|
|
2023-06-07 10:05:35 -03:00
|
|
|
import Icon from '../Icon';
|
|
|
|
|
import Typography from '../Typography';
|
2020-06-26 12:34:43 -03:00
|
|
|
|
2023-06-07 10:05:35 -03:00
|
|
|
import './Modal.css';
|
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-09-01 16:19:39 -04:00
|
|
|
<header className="bg-primary-dark flex items-center rounded-tl rounded-tr px-[20px] py-[13px]">
|
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-09-01 16:19:39 -04:00
|
|
|
className="text-primary-active cursor-pointer"
|
2020-07-10 12:48:51 -03:00
|
|
|
/>
|
2020-05-23 23:38:20 -04:00
|
|
|
)}
|
|
|
|
|
</header>
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ReactModal
|
2024-02-14 08:51:17 -05:00
|
|
|
className="relative max-h-full w-11/12 text-white outline-none lg:w-10/12 xl:w-9/12"
|
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-09-01 16:19:39 -04:00
|
|
|
<section className="ohif-scrollbar modal-content bg-primary-dark overflow-y-auto rounded-bl rounded-br px-[20px] pt-2 pb-[20px]">
|
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 */
|
2023-09-01 16:19:39 -04:00
|
|
|
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;
|