/** ******************************************************************************************************************* 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, { FunctionComponent, ReactNode, useRef, useEffect, useState } from 'react'; import Grid from '../Grid'; import Typography from '@material-ui/core/Typography'; import { makeStyles, Theme } 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`, }), })); export interface GetStartedProps { /**The category of the application, displayed in the header */ category: string; /**The title of the application, displayed in the header */ title: string; /**The subtitle of the application, displayed in the header */ subTitle: string; /**The short description of the application, displayed in the header */ description: string; /**The action for getting started with the application */ action: ReactNode; /**The sidebar content for the application */ sidebar: ReactNode; /**Main content area */ children: ReactNode; } /** * Basic layout for Get Started page, with place holders for main content, sidebar and action. */ const GetStarted: FunctionComponent = ({ category, title, subTitle, description, action, sidebar, children, }) => { const headerRef = useRef(null); const actionRef = useRef(null); const [sidebarMarginTop, setSidebarMarginTop] = useState(-40); useEffect(() => { if (headerRef.current?.offsetHeight && actionRef.current?.offsetHeight) { const calc = (actionRef.current?.offsetTop || 0) + (actionRef.current?.offsetHeight || 0) - ((headerRef.current?.offsetTop || 0) + (headerRef.current?.offsetHeight || 0)) + 10; setSidebarMarginTop(calc); } }, [ setSidebarMarginTop, actionRef.current?.offsetTop, headerRef.current?.offsetTop, actionRef.current?.offsetHeight, headerRef.current?.offsetHeight, ]); const styles = useStyles({ sidebarMarginTop }); return (
{category} {title} {subTitle} {description}
{action}
{children} {sidebar}
); }; export default GetStarted;