UNPKG

aws-northstar

Version:
108 lines (104 loc) 5.37 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 AccordionDetails_1 = __importDefault(require("@material-ui/core/AccordionDetails")); const Accordion_1 = __importDefault(require("@material-ui/core/Accordion")); const Divider_1 = __importDefault(require("@material-ui/core/Divider")); const ExpansionPanelSummary_1 = __importDefault(require("./components/ExpansionPanelSummary")); const Text_1 = __importDefault(require("../Text")); const makeStyles_1 = __importDefault(require("@material-ui/styles/makeStyles")); const useStyles = (0, makeStyles_1.default)(() => { const borderless = { border: 'none', boxShadow: 'none', '&:not(:last-child)': { borderBottom: 0, }, '&::before': { display: 'none', }, backgroundColor: 'transparent', }; return { default: borderless, borderless, container: { '& .MuiAccordionDetails-root': { padding: '15px 20px', }, }, }; }); /** * An expandable section is a section that a user can expand or collapse. * Use expandable sections when you have multiple sections on a page, and you want to allow users to see one or more sections at a time. * Expandable sections are collapsed by default. */ const ExpandableSection = (_a) => { var { expanded = false, children, header = null, onChange, variant = 'default', description } = _a, props = __rest(_a, ["expanded", "children", "header", "onChange", "variant", "description"]); const [isExpanded, setExpanded] = (0, react_1.useState)(expanded); const styles = useStyles(); (0, react_1.useEffect)(() => { setExpanded(expanded); }, [expanded]); const handleChange = () => { const toBeState = !isExpanded; setExpanded(toBeState); onChange === null || onChange === void 0 ? void 0 : onChange(toBeState); }; const testId = props['data-testid'] || 'expandable-section'; return (react_1.default.createElement(Accordion_1.default, { className: styles[variant], square: true, expanded: isExpanded, onChange: handleChange, "data-testid": testId }, react_1.default.createElement(ExpansionPanelSummary_1.default, { variant: variant, header: header, description: description, expanded: isExpanded, "data-testid": `${testId}-header` }), variant !== 'borderless' && react_1.default.createElement(Divider_1.default, null), react_1.default.createElement(AccordionDetails_1.default, { "data-testid": `${testId}-content` }, typeof children === 'string' ? react_1.default.createElement(Text_1.default, null, children) : children))); }; exports.default = ExpandableSection;