UNPKG

aws-northstar

Version:
75 lines (71 loc) 3.61 kB
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; }; /** ******************************************************************************************************************* 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. * ******************************************************************************************************************** */ import React, { Children, Fragment } from 'react'; import Divider from '@material-ui/core/Divider'; import { makeStyles, useTheme } from '@material-ui/core/styles'; import useMediaQuery from '@material-ui/core/useMediaQuery'; import Grid from '../../layouts/Grid'; import Column from './components/Column'; const useStyles = makeStyles((theme) => ({ root: { width: '100%', '& hr': { margin: theme.spacing(0, 2), }, marginTop: -theme.spacing(1), '&>*': { marginTop: theme.spacing(1), }, }, column: { overflow: 'hidden', }, })); const covertBreakpoint = (breakpoint) => { const breakpoints = { lg: 3, md: 2, sm: 1, }; return breakpoints[breakpoint] || 0; }; const getBreakpointValue = (collapseBelow, breakpoint) => { return covertBreakpoint(collapseBelow) - covertBreakpoint(breakpoint) >= 0 ? 12 : true; }; /** * The column layout is a helper component to ease the layout process. * Within containers, users can position their content in typical layouts, for example: two columns in a row. */ const ColumnLayout = (_a) => { var { children, renderDivider = true, collapseBelow = 'xs' } = _a, props = __rest(_a, ["children", "renderDivider", "collapseBelow"]); const classes = useStyles(); const theme = useTheme(); const matched = useMediaQuery(theme.breakpoints.up(collapseBelow)); const columns = Children.toArray(children); return (React.createElement(Grid, { container: true, justify: "flex-start", alignItems: "flex-start", className: classes.root, "data-testid": props['data-testid'] }, columns.map((column, index) => (React.createElement(Fragment, { key: `column${index}` }, React.createElement(Grid, { item: true, xs: 12, sm: getBreakpointValue(collapseBelow, 'sm'), md: getBreakpointValue(collapseBelow, 'md'), lg: getBreakpointValue(collapseBelow, 'lg'), xl: true, className: classes.column }, column), index !== columns.length - 1 && renderDivider && matched && (React.createElement(Divider, { orientation: "vertical", flexItem: true }))))))); }; export default ColumnLayout; export { Column };