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

88 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="bg-primary-dark flex items-center rounded-tl rounded-tr px-[20px] py-[13px]">
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="text-primary-active cursor-pointer"
2020-07-10 12:48:51 -03:00
/>
2020-05-23 23:38:20 -04:00
)}
</header>
)
);
};
return (
<ReactModal
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}
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 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,
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;