|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import React, { useContext, useState } from 'react'; |
| 5 | + |
| 6 | +import { |
| 7 | + AppLayout, |
| 8 | + Box, |
| 9 | + Button, |
| 10 | + Checkbox, |
| 11 | + Container, |
| 12 | + Drawer, |
| 13 | + ExpandableSection, |
| 14 | + Header, |
| 15 | + Modal, |
| 16 | + Popover, |
| 17 | + SpaceBetween, |
| 18 | + SplitPanel, |
| 19 | + Table, |
| 20 | +} from '~components'; |
| 21 | +import { ErrorBoundariesProvider } from '~components/error-boundary/context'; |
| 22 | +import I18nProvider from '~components/i18n'; |
| 23 | +import messages from '~components/i18n/messages/all.en'; |
| 24 | +import { |
| 25 | + colorBackgroundStatusError, |
| 26 | + colorBorderStatusError, |
| 27 | + colorTextInteractiveInvertedHover, |
| 28 | + colorTextStatusError, |
| 29 | +} from '~design-tokens'; |
| 30 | + |
| 31 | +import AppContext, { AppContextType } from '../app/app-context'; |
| 32 | +import ScreenshotArea from '../utils/screenshot-area'; |
| 33 | + |
| 34 | +type PageContext = React.Context<AppContextType<{ errorBoundariesActive: boolean }>>; |
| 35 | + |
| 36 | +export default function () { |
| 37 | + const { |
| 38 | + urlParams: { errorBoundariesActive = true }, |
| 39 | + setUrlParams, |
| 40 | + } = useContext(AppContext as PageContext); |
| 41 | + const [splitPanelOpen, setSplitPanelOpen] = useState(true); |
| 42 | + const [activeDrawerId, setActiveDrawerId] = useState<null | string>('d1'); |
| 43 | + const [modalOpen, setModalOpen] = useState(false); |
| 44 | + return ( |
| 45 | + <ScreenshotArea gutters={false}> |
| 46 | + <I18nProvider messages={[messages]} locale="en"> |
| 47 | + <ErrorBoundariesProvider active={errorBoundariesActive} value={{ feedbackLink: '/#' }}> |
| 48 | + <AppLayout |
| 49 | + navigationHide={true} |
| 50 | + activeDrawerId={activeDrawerId} |
| 51 | + onDrawerChange={({ detail }) => setActiveDrawerId(detail.activeDrawerId)} |
| 52 | + splitPanel={ |
| 53 | + <SplitPanel header="Split panel"> |
| 54 | + <BrokenButton /> |
| 55 | + </SplitPanel> |
| 56 | + } |
| 57 | + splitPanelOpen={splitPanelOpen} |
| 58 | + onSplitPanelToggle={({ detail }) => setSplitPanelOpen(detail.open)} |
| 59 | + drawers={[ |
| 60 | + { |
| 61 | + id: 'd1', |
| 62 | + content: ( |
| 63 | + <Drawer header={<Header variant="h2">Drawer 1</Header>}> |
| 64 | + <BrokenButton /> |
| 65 | + </Drawer> |
| 66 | + ), |
| 67 | + trigger: { iconName: 'bug' }, |
| 68 | + ariaLabels: { drawerName: 'Drawer 1', triggerButton: 'Open drawer 1', closeButton: 'Close drawer 1' }, |
| 69 | + }, |
| 70 | + { |
| 71 | + id: 'd2', |
| 72 | + content: ( |
| 73 | + <Drawer header={<Header variant="h2">Drawer 2</Header>}> |
| 74 | + <BrokenButton /> |
| 75 | + </Drawer> |
| 76 | + ), |
| 77 | + trigger: { iconName: 'call' }, |
| 78 | + ariaLabels: { drawerName: 'Drawer 2', triggerButton: 'Open drawer 2', closeButton: 'Close drawer 2' }, |
| 79 | + }, |
| 80 | + ]} |
| 81 | + content={ |
| 82 | + <Box> |
| 83 | + <h1>Error boundary demo</h1> |
| 84 | + <Box margin={{ bottom: 'm' }}> |
| 85 | + <Checkbox |
| 86 | + checked={errorBoundariesActive} |
| 87 | + onChange={({ detail }) => setUrlParams({ errorBoundariesActive: detail.checked })} |
| 88 | + > |
| 89 | + Error boundaries on |
| 90 | + </Checkbox> |
| 91 | + </Box> |
| 92 | + |
| 93 | + <SpaceBetween size="m"> |
| 94 | + <SpaceBetween size="m" direction="horizontal"> |
| 95 | + <BrokenButton /> |
| 96 | + |
| 97 | + <Box> |
| 98 | + <Button onClick={() => setModalOpen(true)}>Show modal</Button> |
| 99 | + <Modal visible={modalOpen} header="Modal" onDismiss={() => setModalOpen(false)}> |
| 100 | + <BrokenButton /> |
| 101 | + </Modal> |
| 102 | + </Box> |
| 103 | + |
| 104 | + <Popover header="Header" content={<BrokenButton />} triggerType="custom"> |
| 105 | + <Button>Show popover</Button> |
| 106 | + </Popover> |
| 107 | + </SpaceBetween> |
| 108 | + |
| 109 | + <Container header={<Header>Container 1</Header>}> |
| 110 | + <BrokenButton /> |
| 111 | + </Container> |
| 112 | + |
| 113 | + <Container header={<Header>Container 2</Header>}> |
| 114 | + <BrokenButton /> |
| 115 | + </Container> |
| 116 | + |
| 117 | + <ExpandableSection |
| 118 | + variant="container" |
| 119 | + headerText="Expandable section" |
| 120 | + headerActions={<BrokenButton />} |
| 121 | + defaultExpanded={true} |
| 122 | + > |
| 123 | + <BrokenButton /> |
| 124 | + </ExpandableSection> |
| 125 | + |
| 126 | + <Table |
| 127 | + header={<Header>Table</Header>} |
| 128 | + columnDefinitions={[ |
| 129 | + { header: 'Column 1', cell: item => `Content 1:${item}` }, |
| 130 | + { header: 'Column 2', cell: item => `Content 2:${item}` }, |
| 131 | + { header: 'Column 3', cell: item => `Content 3:${item}` }, |
| 132 | + { header: 'Actions', cell: () => <BrokenButton /> }, |
| 133 | + ]} |
| 134 | + items={[1, 2, 3]} |
| 135 | + ></Table> |
| 136 | + </SpaceBetween> |
| 137 | + </Box> |
| 138 | + } |
| 139 | + /> |
| 140 | + </ErrorBoundariesProvider> |
| 141 | + </I18nProvider> |
| 142 | + </ScreenshotArea> |
| 143 | + ); |
| 144 | +} |
| 145 | + |
| 146 | +function BrokenButton() { |
| 147 | + const [errorState, setErrorState] = useState(false); |
| 148 | + const colorsDefault = [colorTextStatusError, colorBorderStatusError, undefined]; |
| 149 | + const colorsHover = [colorTextStatusError, colorBorderStatusError, colorBackgroundStatusError]; |
| 150 | + const colorsActive = [colorTextInteractiveInvertedHover, colorBorderStatusError, colorTextStatusError]; |
| 151 | + return ( |
| 152 | + <Button |
| 153 | + style={{ |
| 154 | + root: { |
| 155 | + color: { default: colorsDefault[0], hover: colorsHover[0], active: colorsActive[0] }, |
| 156 | + borderColor: { default: colorsDefault[1], hover: colorsHover[1], active: colorsActive[1] }, |
| 157 | + background: { default: colorsDefault[2], hover: colorsHover[2], active: colorsActive[2] }, |
| 158 | + }, |
| 159 | + }} |
| 160 | + onClick={() => setErrorState(true)} |
| 161 | + > |
| 162 | + Broken button {errorState ? {} : ''} |
| 163 | + </Button> |
| 164 | + ); |
| 165 | +} |
0 commit comments