UNPKG

aws-northstar

Version:
110 lines (106 loc) 5.22 kB
"use strict"; /** ******************************************************************************************************************* 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const styles_1 = require("@material-ui/core/styles"); const IconButton_1 = __importDefault(require("@material-ui/core/IconButton")); const Close_1 = __importDefault(require("@material-ui/icons/Close")); const clsx_1 = __importDefault(require("clsx")); const Container_1 = __importDefault(require("../../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] = (0, react_1.useState)(false); const useStyles = (0, styles_1.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({}); (0, react_1.useEffect)(() => { setVisible(visible); }, [visible]); const handleClose = () => { setVisible(false); onClose === null || onClose === void 0 ? void 0 : onClose(); }; const CloseButton = () => (react_1.default.createElement(IconButton_1.default, { className: styles.closeButton, onClick: handleClose, "aria-label": "close" }, react_1.default.createElement(Close_1.default, null))); const testId = props['data-testid'] || 'modal'; return (react_1.default.createElement("section", { "data-testid": testId, className: (0, clsx_1.default)(styles.cyclorama, { [styles.cycloramaActive]: isVisible }) }, react_1.default.createElement("div", { "data-testid": `${testId}-inner`, className: styles.modalPlaceholder }, react_1.default.createElement(Container_1.default, { title: title, subtitle: subtitle, actionGroup: react_1.default.createElement(CloseButton, null), footerContent: footer }, children)))); }; exports.default = Modal;