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

80 lines
2.0 KiB
React
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';
2020-06-26 12:34:43 -03:00
import './Modal.css';
import { Typography, useModal, IconButton, 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-06-26 12:34:43 -03:00
<header className="mb-6 pb-4 border-b border-secondary-main">
<Typography variant="h4">{title}</Typography>
2020-05-23 23:38:20 -04:00
{closeButton && (
2020-06-26 12:34:43 -03:00
<IconButton
className="absolute top-0 right-0 focus:outline-none flex -mr-3 -mt-3"
data-cy="close-button"
color="primary"
onClick={onClose}
rounded="full"
>
<Icon name="close" className="text-white w-8 h-8" />
</IconButton>
2020-05-23 23:38:20 -04:00
)}
</header>
)
);
};
return (
<ReactModal
2020-06-26 12:34:43 -03:00
className="relative py-6 w-11/12 lg:w-10/12 xl:w-1/2 max-h-full outline-none bg-primary-dark border border-secondary-main text-white rounded"
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-06-26 12:34:43 -03:00
<div className="px-6">{renderHeader()}</div>
<section className="ohif-scrollbar modal-content overflow-y-auto px-6">
{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;