|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +import React, { useContext, useState } from 'react'; |
| 4 | + |
| 5 | +import { |
| 6 | + AppLayout, |
| 7 | + Box, |
| 8 | + Button, |
| 9 | + CopyToClipboard, |
| 10 | + Header, |
| 11 | + HelpPanel, |
| 12 | + KeyValuePairs, |
| 13 | + Link, |
| 14 | + ProgressBar, |
| 15 | + SideNavigation, |
| 16 | + SpaceBetween, |
| 17 | + SplitPanel, |
| 18 | + StatusIndicator, |
| 19 | + Table, |
| 20 | +} from '~components'; |
| 21 | +import { AppLayoutProps } from '~components/app-layout'; |
| 22 | + |
| 23 | +import './utils/external-sidecar-widget-demo'; |
| 24 | +import AppContext, { AppContextType } from '../app/app-context'; |
| 25 | +import { generateItems, Instance } from '../table/generate-data'; |
| 26 | +import { columnsConfig } from '../table/shared-configs'; |
| 27 | +import { Breadcrumbs } from './utils/content-blocks'; |
| 28 | +import { drawerLabels } from './utils/drawers'; |
| 29 | +import appLayoutLabels from './utils/labels'; |
| 30 | +import { splitPaneli18nStrings } from './utils/strings'; |
| 31 | + |
| 32 | +type DemoContext = React.Context< |
| 33 | + AppContextType<{ |
| 34 | + hasTools: boolean | undefined; |
| 35 | + hasDrawers: boolean | undefined; |
| 36 | + splitPanelPosition: AppLayoutProps.SplitPanelPreferences['position']; |
| 37 | + }> |
| 38 | +>; |
| 39 | + |
| 40 | +export default function WithDrawers() { |
| 41 | + const { urlParams, setUrlParams } = useContext(AppContext as DemoContext); |
| 42 | + const hasTools = urlParams.hasTools ?? true; |
| 43 | + |
| 44 | + const [activeHref, setActiveHref] = useState('#/'); |
| 45 | + const [navigationOpen, setNavigationOpen] = useState(true); |
| 46 | + const [toolsOpen, setToolsOpen] = useState(false); |
| 47 | + |
| 48 | + const items = generateItems(20); |
| 49 | + |
| 50 | + function openHelp() { |
| 51 | + setToolsOpen(true); |
| 52 | + } |
| 53 | + |
| 54 | + return ( |
| 55 | + <AppLayout |
| 56 | + ariaLabels={{ ...appLayoutLabels, ...drawerLabels }} |
| 57 | + breadcrumbs={<Breadcrumbs />} |
| 58 | + navigation={ |
| 59 | + <SideNavigation |
| 60 | + activeHref={activeHref} |
| 61 | + header={{ text: 'Navigation', href: '#/' }} |
| 62 | + onFollow={e => { |
| 63 | + e.preventDefault(); |
| 64 | + setActiveHref(e.detail.href); |
| 65 | + }} |
| 66 | + items={[ |
| 67 | + { type: 'link', text: 'Side nav menu A', href: '#/menu-a' }, |
| 68 | + { type: 'link', text: 'Side nav menu B', href: '#/menu-b' }, |
| 69 | + { type: 'link', text: 'Side nav menu C', href: '#/menu-c' }, |
| 70 | + ]} |
| 71 | + /> |
| 72 | + } |
| 73 | + navigationOpen={navigationOpen} |
| 74 | + onNavigationChange={({ detail }) => setNavigationOpen(detail.open)} |
| 75 | + content={ |
| 76 | + <Table<Instance> |
| 77 | + header={ |
| 78 | + <Header |
| 79 | + variant="awsui-h1-sticky" |
| 80 | + description="Demo page with footer" |
| 81 | + info={ |
| 82 | + <Link variant="info" onFollow={() => openHelp()}> |
| 83 | + Info |
| 84 | + </Link> |
| 85 | + } |
| 86 | + actions={<Button variant="primary">Create</Button>} |
| 87 | + > |
| 88 | + Sticky Scrollbar Example |
| 89 | + </Header> |
| 90 | + } |
| 91 | + stickyHeader={true} |
| 92 | + variant="full-page" |
| 93 | + columnDefinitions={columnsConfig} |
| 94 | + items={items} |
| 95 | + selectionType="multi" |
| 96 | + ariaLabels={{ |
| 97 | + selectionGroupLabel: 'Item selection', |
| 98 | + allItemsSelectionLabel: () => 'Select all items', |
| 99 | + itemSelectionLabel: (_, item) => `Select ${item.id}`, |
| 100 | + }} |
| 101 | + /> |
| 102 | + } |
| 103 | + splitPanel={ |
| 104 | + <SplitPanel header="Overview" i18nStrings={splitPaneli18nStrings}> |
| 105 | + <SpaceBetween size="m"> |
| 106 | + <Box> |
| 107 | + Receive real-time data insights to build process improvements, track key performance indicators, and |
| 108 | + predict future business outcomes. Create a new Cloud Data Solution account to receive a 30 day free trial |
| 109 | + of all Cloud Data Solution services. |
| 110 | + </Box> |
| 111 | + <KeyValuePairs |
| 112 | + columns={2} |
| 113 | + items={[ |
| 114 | + { |
| 115 | + type: 'group', |
| 116 | + items: [ |
| 117 | + { |
| 118 | + label: 'Distribution ID', |
| 119 | + value: 'E1WG1ZNPRXT0D4', |
| 120 | + }, |
| 121 | + { |
| 122 | + label: 'ARN', |
| 123 | + value: ( |
| 124 | + <CopyToClipboard |
| 125 | + copyButtonAriaLabel="Copy ARN" |
| 126 | + copyErrorText="ARN failed to copy" |
| 127 | + copySuccessText="ARN copied" |
| 128 | + textToCopy="arn:service23G24::111122223333:distribution/23E1WG1ZNPRXT0D4" |
| 129 | + variant="inline" |
| 130 | + /> |
| 131 | + ), |
| 132 | + }, |
| 133 | + { |
| 134 | + label: 'Status', |
| 135 | + value: <StatusIndicator>Available</StatusIndicator>, |
| 136 | + }, |
| 137 | + ], |
| 138 | + }, |
| 139 | + |
| 140 | + { |
| 141 | + type: 'group', |
| 142 | + items: [ |
| 143 | + { |
| 144 | + label: 'SSL Certificate', |
| 145 | + id: 'ssl-certificate-id', |
| 146 | + value: ( |
| 147 | + <ProgressBar |
| 148 | + value={30} |
| 149 | + additionalInfo="Additional information" |
| 150 | + description="Progress bar description" |
| 151 | + ariaLabelledby="ssl-certificate-id" |
| 152 | + /> |
| 153 | + ), |
| 154 | + }, |
| 155 | + { |
| 156 | + label: 'Price class', |
| 157 | + value: 'Use only US, Canada, Europe', |
| 158 | + }, |
| 159 | + { |
| 160 | + label: 'CNAMEs', |
| 161 | + value: ( |
| 162 | + <Link external={true} href="#"> |
| 163 | + abc.service23G24.xyz |
| 164 | + </Link> |
| 165 | + ), |
| 166 | + }, |
| 167 | + ], |
| 168 | + }, |
| 169 | + ]} |
| 170 | + /> |
| 171 | + </SpaceBetween> |
| 172 | + </SplitPanel> |
| 173 | + } |
| 174 | + splitPanelPreferences={{ |
| 175 | + position: urlParams.splitPanelPosition, |
| 176 | + }} |
| 177 | + onSplitPanelPreferencesChange={event => { |
| 178 | + const { position } = event.detail; |
| 179 | + setUrlParams({ splitPanelPosition: position === 'side' ? position : undefined }); |
| 180 | + }} |
| 181 | + toolsOpen={toolsOpen} |
| 182 | + toolsHide={!hasTools} |
| 183 | + onToolsChange={({ detail }) => setToolsOpen(detail.open)} |
| 184 | + tools={ |
| 185 | + <HelpPanel header={<h2>Help</h2>}> |
| 186 | + <p>This is a demo page showcasing the AppLayout component with a sticky header and scrollable content.</p> |
| 187 | + <h3>Features:</h3> |
| 188 | + <ul> |
| 189 | + <li>Responsive navigation sidebar</li> |
| 190 | + <li>Sticky header with actions</li> |
| 191 | + <li>Full-page table with sticky header</li> |
| 192 | + <li>Split panel support</li> |
| 193 | + </ul> |
| 194 | + </HelpPanel> |
| 195 | + } |
| 196 | + /> |
| 197 | + ); |
| 198 | +} |
0 commit comments