aws-northstar
Version:
NorthStar Design System
82 lines (78 loc) • 3.74 kB
JavaScript
/** *******************************************************************************************************************
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. *
******************************************************************************************************************** */
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React, { useState, useEffect } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import Close from '@material-ui/icons/Close';
import clsx from 'clsx';
import Container from '../../layouts/Container';
/** A modal is a pop-up dialog that can be used to prompt a user for confirmation. */
const Modal = (_a) => {
var { visible = false, children, title, subtitle, footer, onClose, width } = _a, props = __rest(_a, ["visible", "children", "title", "subtitle", "footer", "onClose", "width"]);
const [isVisible, setVisible] = useState(false);
const useStyles = makeStyles({
cyclorama: {
position: 'fixed',
top: 0,
left: 0,
width: '100vw',
height: '100vh',
opacity: 0,
zIndex: -9999,
background: 'rgba(255, 255, 255, 0.7)',
display: 'flex',
transition: 'opacity 0.2s linear',
},
cycloramaActive: {
opacity: 1,
zIndex: 1299,
},
modalPlaceholder: {
width: width || '600px',
margin: 'auto',
position: 'relative',
},
closeButton: {
padding: 0,
'& > .MuiIconButton-label': {
padding: 0,
},
},
});
const styles = useStyles({});
useEffect(() => {
setVisible(visible);
}, [visible]);
const handleClose = () => {
setVisible(false);
onClose === null || onClose === void 0 ? void 0 : onClose();
};
const CloseButton = () => (React.createElement(IconButton, { className: styles.closeButton, onClick: handleClose, "aria-label": "close" },
React.createElement(Close, null)));
const testId = props['data-testid'] || 'modal';
return (React.createElement("section", { "data-testid": testId, className: clsx(styles.cyclorama, { [styles.cycloramaActive]: isVisible }) },
React.createElement("div", { "data-testid": `${testId}-inner`, className: styles.modalPlaceholder },
React.createElement(Container, { title: title, subtitle: subtitle, actionGroup: React.createElement(CloseButton, null), footerContent: footer }, children))));
};
export default Modal;