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';
|
|
|
|
|
|
2020-07-10 12:48:51 -03:00
|
|
|
import { Typography, useModal, Icon } from '@ohif/ui';
|
2020-05-23 23:38:20 -04:00
|
|
|
|
|
|
|
|
ReactModal.setAppElement(document.getElementById('root'));
|
|
|
|
|
|
|
|
|
|
const Modal = ({
|
|
|
|
|
closeButton,
|
|
|
|
|
shouldCloseOnEsc,
|
|
|
|
|
isOpen,
|
|
|
|
|
title,
|
|
|
|
|
onClose,
|
|
|
|
|
children,
|
|
|
|
|
}) => {
|
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 && (
|
2020-07-10 12:48:51 -03:00
|
|
|
<header className="flex items-center p-4 border-b-2 border-black bg-secondary-dark rounded-tl rounded-tr">
|
|
|
|
|
<Typography
|
|
|
|
|
variant="h4"
|
|
|
|
|
className="flex flex-grow text-primary-light font-light"
|
|
|
|
|
>
|
|
|
|
|
{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
|
|
|
data-cy="close-button"
|
|
|
|
|
onClick={onClose}
|
2020-07-10 12:48:51 -03:00
|
|
|
name="close"
|
|
|
|
|
className="cursor-pointer text-primary-active w-6 h-6"
|
|
|
|
|
/>
|
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}
|
|
|
|
|
>
|
2020-07-10 12:48:51 -03:00
|
|
|
{renderHeader()}
|
|
|
|
|
<section className="ohif-scrollbar modal-content overflow-y-auto px-4 py-6 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,
|
|
|
|
|
};
|
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Modal;
|