/** *******************************************************************************************************************
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, useCallback, useEffect, useState } from 'react';
import { action } from '@storybook/addon-actions';
import { v4 as uuidv4 } from 'uuid';
import AppLayout, { Notification, useAppLayoutContext } from '.';
import ColumnLayout, { Column } from '../ColumnLayout';
import KeyValuePair from '../../components/KeyValuePair';
import Badge from '../../components/Badge';
import Box from '../Box';
import BreadcrumbGroup from '../../components/BreadcrumbGroup';
import Button from '../../components/Button';
import Header from '../../components/Header';
import Heading from '../../components/Heading';
import HelpPanel from '../../components/HelpPanel';
import Link from '../../components/Link';
import SideNavigation, { SideNavigationItemType } from '../../components/SideNavigation';
import Stack from '../Stack';
import Text from '../../components/Text';
import { Simple as SimpleTable } from '../../components/Table/index.stories';
import { Default as GeneralInfo } from '../../components/KeyValuePair/index.stories';
export default {
component: AppLayout,
title: 'Layouts/AppLayout',
parameters: {
layout: 'fullscreen',
},
};
const header = ;
const navigationItems = [
{ type: SideNavigationItemType.LINK, text: 'Page 1', href: '/page1' },
{ type: SideNavigationItemType.LINK, text: 'Page 2', href: '/page2' },
{ type: SideNavigationItemType.LINK, text: 'Page 3', href: '/page3' },
{ type: SideNavigationItemType.LINK, text: 'Page 4', href: '/page4' },
{ type: SideNavigationItemType.DIVIDER },
{
type: SideNavigationItemType.LINK,
text: 'Notifications',
href: '/notifications',
info: ,
},
{
type: SideNavigationItemType.LINK,
text: 'Documentation',
href: 'https://docs.yoursite.com',
},
];
const navigation = (
);
const helpPanel = (
Link to internal documentation,
Link to external documentation,
]}
>
This is a paragraph with some bold text and also some italic text.
h4 section header
h5 section header
);
const breadcrumbGroup = (
);
const splitPanel = (
);
const defaultNotifications: Notification[] = [
{
id: '1',
header: 'Successfully update 4 orders',
type: 'success',
content: 'This is a success flash message.',
dismissible: true,
},
{
id: '2',
header: 'Failed to update 1 order',
type: 'error',
content: 'This is a dismissible error message with a button.',
buttonText: 'Retry',
onButtonClick: action('onButtonClick'),
dismissible: true,
},
{
id: '3',
header: 'Warning',
type: 'warning',
content: 'This is warning content',
dismissible: true,
},
];
export const Default = () => {
const [notifications, setNotifications] = useState(defaultNotifications);
const handleDismiss = (id: string) => {
setNotifications(notifications.filter((n) => n.id !== id));
};
return (
({ ...n, onDismiss: () => handleDismiss(n.id) }))}
>
);
};
const DynamicSplitPanelSubComponent: React.FunctionComponent = () => {
const { setSplitPanelContent, openSplitPanel } = useAppLayoutContext();
const handleButtonClick = useCallback(() => {
setSplitPanelContent(splitPanel);
openSplitPanel(true);
}, [openSplitPanel, setSplitPanelContent]);
return ;
};
export const DynamicSplitPanel = () => {
return (
);
};
const DynamicHelpPanelSubComponent: React.FunctionComponent = ({ children }) => {
const { setHelpPanelContent } = useAppLayoutContext();
useEffect(() => {
setHelpPanelContent(helpPanel);
}, [setHelpPanelContent]);
return children;
};
export const DynamicHelpPanel = () => {
return (
);
};
export const WithoutNotifications = () => {
return (
);
};
const DynamicNotificationAddMainComponent: FunctionComponent = () => {
const { addNotification, dismissNotifications } = useAppLayoutContext();
const [notificationId, setNotificationId] = useState();
const handleAddClick = useCallback(() => {
const id = uuidv4();
addNotification({
id,
type: 'success',
header: `Your request ${id} is being processed`,
dismissible: true,
});
setNotificationId(id);
}, [addNotification]);
const handleRemoveLastClick = useCallback(() => {
notificationId && dismissNotifications(notificationId);
}, [dismissNotifications, notificationId]);
const handleRemoveAll = useCallback(() => {
dismissNotifications();
}, [dismissNotifications]);
return (
);
};
export const DynamicNotificationAdd = () => (
);
export const WithoutSidebars = () => {
return (
);
};
export const WithOnlyHelpPanel = () => {
return (
);
};
export const WithoutContentPadding = () => {
return (
);
};
const ContentUsingContext = () => {
const { openHelpPanel } = useAppLayoutContext();
return (
Main Content
);
};
export const OpenHelpPanel = () => {
return (
);
};
export const CustomHeader = () => {
const customHeader = (
Header
);
return (
);
};
export const WithInprogressOverlay = () => {
const [inProgress, setInProgress] = useState(false);
useEffect(() => {
setTimeout(() => {
setInProgress(true);
setTimeout(() => {
setInProgress(false);
}, 3000);
}, 3000);
}, []);
return (
);
};