UNPKG

aws-northstar

Version:
98 lines (94 loc) 5.08 kB
/** ******************************************************************************************************************* 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, { useRef, useEffect, useState } from 'react'; import Grid from '../Grid'; import Typography from '@material-ui/core/Typography'; import { makeStyles } from '@material-ui/core/styles'; import Stack from '../Stack'; import Text from '../../components/Text'; const useStyles = makeStyles((theme) => ({ root: {}, headerRow: { backgroundColor: theme.palette.primary.main, paddingTop: theme.spacing(4), }, header: { padding: theme.spacing(1), color: theme.palette.primary.contrastText, }, title: { fontSize: '44px', lineHeight: '50px', }, subTitle: { fontSize: '44px', lineHeight: '50px', fontWeight: 300, }, action: { padding: theme.spacing(1), }, contentArea: { padding: theme.spacing(1), color: theme.palette.grey[900], marginBottom: theme.spacing(1), }, sidebarArea: ({ sidebarMarginTop }) => ({ padding: theme.spacing(1), marginTop: `${sidebarMarginTop}px`, }), })); /** * Basic layout for Get Started page, with place holders for main content, sidebar and action. */ const GetStarted = ({ category, title, subTitle, description, action, sidebar, children, }) => { var _a, _b, _c, _d; const headerRef = useRef(null); const actionRef = useRef(null); const [sidebarMarginTop, setSidebarMarginTop] = useState(-40); useEffect(() => { var _a, _b, _c, _d, _e, _f; if (((_a = headerRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) && ((_b = actionRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight)) { const calc = (((_c = actionRef.current) === null || _c === void 0 ? void 0 : _c.offsetTop) || 0) + (((_d = actionRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0) - ((((_e = headerRef.current) === null || _e === void 0 ? void 0 : _e.offsetTop) || 0) + (((_f = headerRef.current) === null || _f === void 0 ? void 0 : _f.offsetHeight) || 0)) + 10; setSidebarMarginTop(calc); } }, [ setSidebarMarginTop, (_a = actionRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop, (_b = headerRef.current) === null || _b === void 0 ? void 0 : _b.offsetTop, (_c = actionRef.current) === null || _c === void 0 ? void 0 : _c.offsetHeight, (_d = headerRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight, ]); const styles = useStyles({ sidebarMarginTop }); return (React.createElement(Grid, { container: true, className: styles.root }, React.createElement(Grid, { item: true, xs: 12, className: styles.headerRow }, React.createElement("div", { ref: headerRef }, React.createElement(Grid, { container: true, justify: "center" }, React.createElement(Grid, { item: true, xs: 10, lg: 8, className: styles.header }, React.createElement(Text, null, category)), React.createElement(Grid, { item: true, xs: 10, sm: 6, lg: 5, xl: 6, className: styles.header }, React.createElement(Stack, null, React.createElement(Typography, { variant: "h1", className: styles.title }, title), React.createElement(Typography, { className: styles.subTitle }, subTitle), React.createElement(Text, null, description))), React.createElement(Grid, { item: true, xs: 10, sm: 4, lg: 3, xl: 2, className: styles.action }, React.createElement("div", { ref: actionRef }, action))))), React.createElement(Grid, { item: true }, React.createElement(Grid, { container: true, justify: "center" }, React.createElement(Grid, { item: true, xs: 10, sm: 6, lg: 5, xl: 6, className: styles.contentArea }, children), React.createElement(Grid, { item: true, xs: 10, sm: 4, lg: 3, xl: 2, className: styles.sidebarArea }, sidebar))))); }; export default GetStarted;