/*! Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ import { Box, Button, Container, Inline, Paper, Stack } from 'aws-northstar'; import { ContainerProps } from 'aws-northstar/layouts/Container'; import { Divider } from '@material-ui/core'; import { HeadingStripe, HeadingStripeProps } from '..'; import { TableBaseOptions } from 'aws-northstar/components/Table'; import React from 'react'; import Skeleton, { SkeletonProps as BaseSkeletonProps } from '@material-ui/lab/Skeleton'; type SkeletonProps = Pick; type SkeletonFlags = { [Property in keyof Type]?: Required[Property] extends string ? (string | boolean) : Required[Property] extends React.ReactNode ? (string | boolean) : boolean; }; function renderSkelotonStringFlag( value: string | boolean | undefined, skeleton: React.ReactElement ): string | React.ReactElement | undefined { if (value == null) return undefined; if (typeof value === 'string') return value; if (typeof value === 'boolean') return skeleton; return undefined; } type ActionGroupSkeletonProps = SkeletonProps & { /** @default 2 */ actions?: number; }; export const ActionGroupSkeleton: React.FC = ({ actions = 2, animation }) => { return ( {Array.from(Array(actions)).map((_v, i) => ( ))} ); }; type HeadingStripeSkeletonProps = SkeletonProps & SkeletonFlags & { actions?: number }; export const HeadingStripeSkeleton: React.FC = ({ title = true, subtitle = true, actionButtons = false, actions, animation, }) => { return ( ) as any} subtitle={renderSkelotonStringFlag(subtitle, )} actionButtons={actionButtons && } /> ); }; type ContainerSkeletonProps = SkeletonProps & SkeletonFlags; export const ContainerSkeleton: React.FC = ({ title = true, subtitle = true, actionGroup = true, children, animation, }) => { return ( ) as any} subtitle={renderSkelotonStringFlag(subtitle, ) as any} actionGroup={actionGroup && (() as any)} > {children || } ); }; type TableSkeletonProps = SkeletonProps & SkeletonFlags> & { /** @default 4 */ columns?: number; /** @default 7 */ rows?: number; /** @default 20 */ rowHeight?: number; }; export const TableSkeleton: React.FC = ({ tableTitle = true, tableDescription = true, actionGroup = false, columns = 4, rows = 7, rowHeight = 20, animation, }) => { return ( {Array.from(Array(rows)).map((_v, i) => (
{Array.from(Array(columns)).map((_, _i) => ( ))}
))}
); }; type FormSkeletonProps = SkeletonProps & { /** @default 5 */ fields?: number; }; export const FormSkeleton: React.FC = ({ fields = 5, animation }) => { return ( {Array.from(Array(fields)).map((_v, _i) => ( ))} ); }; type WizardSkeletonProps = SkeletonProps & { /** @default 3 */ steps?: number; /** @default 5 */ fields?: number; }; export const WizardSkeleton: React.FC = ({ steps = 3, fields = 5, animation }) => { return ( {Array.from(Array(steps)).map((_v, _i) => ( ))} ); }; type SummarySkeletonProps = SkeletonProps & { /** @default 2 */ sections?: number; }; export const SummarySkeleton: React.FC = ({ sections = 2, animation }) => { return ( {Array.from(Array(sections)).map((_v, _i) => ( ))} ); }; type PageSkeletonProps = HeadingStripeSkeletonProps & SummarySkeletonProps; export const PageSkeleton: React.FC = ({ title, subtitle, actionButtons, actions, sections = 2, animation, }) => { return ( ); }; export const DetailsPageSkeleton: React.FC = ({ actionButtons = true, ...props }) => { return ; }; export const Skeletons = { Container: ContainerSkeleton, Table: TableSkeleton, Form: FormSkeleton, Wizard: WizardSkeleton, Summary: SummarySkeleton, ActionGroup: ActionGroupSkeleton, HeadingStripe: HeadingStripeSkeleton, Page: PageSkeleton, DetailsPage: DetailsPageSkeleton, };