Files
ohif-viewer/platform/ui/src/components/Modal/Modal.tsx
T

91 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-05-23 23:38:20 -04:00
import React from 'react';
import PropTypes from 'prop-types';
import ReactModal from 'react-modal';
import { useModal } from '../../contextProviders';
2020-05-23 23:38:20 -04:00
import Icon from '../Icon';
import Typography from '../Typography';
2020-06-26 12:34:43 -03:00
import './Modal.css';
2020-05-23 23:38:20 -04: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,
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 && (
<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
variant="h6"
color="primaryLight"
className="flex grow !leading-[1.2]"
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"
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}
shouldCloseOnOverlayClick={shouldCloseOnOverlayClick}
2020-05-23 23:38:20 -04:00
>
2020-07-10 12:48:51 -03:00
{renderHeader()}
<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,
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,
shouldCloseOnOverlayClick: PropTypes.bool,
2020-05-23 23:38:20 -04:00
};
export default Modal;