|
| 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 | +import range from 'lodash/range'; |
| 5 | + |
| 6 | +import AppLayout from '~components/app-layout'; |
| 7 | +import Header from '~components/header'; |
| 8 | +import RadioGroup from '~components/radio-group'; |
| 9 | +import SideNavigation from '~components/side-navigation'; |
| 10 | +import SplitPanel from '~components/split-panel'; |
| 11 | + |
| 12 | +import AppContext, { AppContextType } from '../app/app-context'; |
| 13 | +import { Footer, Tools } from './utils/content-blocks'; |
| 14 | +import labels from './utils/labels'; |
| 15 | +import * as toolsContent from './utils/tools-content'; |
| 16 | + |
| 17 | +const overflowWhenSplitPanelIsAtBottom = ( |
| 18 | + <div |
| 19 | + style={{ |
| 20 | + height: 400, |
| 21 | + }} |
| 22 | + ></div> |
| 23 | +); |
| 24 | + |
| 25 | +const overflowWhenSplitPanelIsOnSide = ( |
| 26 | + <div style={{ display: 'flex', gap: '2000px 350px', flexWrap: 'wrap' }}> |
| 27 | + <div>Item 1</div> |
| 28 | + <div>Item 2</div> |
| 29 | + </div> |
| 30 | +); |
| 31 | + |
| 32 | +const overflowNever = 'Short content'; |
| 33 | + |
| 34 | +const overflowAlways = <div style={{ height: 1200 }}></div>; |
| 35 | + |
| 36 | +const contentByOverflowCondition = { |
| 37 | + side: overflowWhenSplitPanelIsOnSide, |
| 38 | + bottom: overflowWhenSplitPanelIsAtBottom, |
| 39 | + never: overflowNever, |
| 40 | + always: overflowAlways, |
| 41 | +}; |
| 42 | + |
| 43 | +type ScrollbarCondition = 'side' | 'bottom' | 'never' | 'always'; |
| 44 | + |
| 45 | +type SplitPanelDemoContext = React.Context< |
| 46 | + AppContextType<{ |
| 47 | + scrollbarDisplayCondition: ScrollbarCondition; |
| 48 | + toolsEnabled: boolean; |
| 49 | + }> |
| 50 | +>; |
| 51 | + |
| 52 | +export default function () { |
| 53 | + const { |
| 54 | + urlParams: { scrollbarDisplayCondition = 'always' }, |
| 55 | + setUrlParams, |
| 56 | + } = useContext(AppContext as SplitPanelDemoContext); |
| 57 | + |
| 58 | + const [splitPanelOpen, setSplitPanelOpen] = useState(true); |
| 59 | + |
| 60 | + return ( |
| 61 | + <> |
| 62 | + <AppLayout |
| 63 | + ariaLabels={labels} |
| 64 | + navigation={ |
| 65 | + <SideNavigation |
| 66 | + header={{ |
| 67 | + href: '#', |
| 68 | + text: 'Service name', |
| 69 | + }} |
| 70 | + items={range(3).map(i => ({ type: 'link', text: `Navigation #${i + 1}`, href: `#item-${i}` }))} |
| 71 | + /> |
| 72 | + } |
| 73 | + navigationOpen={true} |
| 74 | + disableContentPaddings={true} |
| 75 | + minContentWidth={300} |
| 76 | + splitPanelOpen={splitPanelOpen} |
| 77 | + onSplitPanelToggle={e => setSplitPanelOpen(e.detail.open)} |
| 78 | + splitPanelPreferences={{ |
| 79 | + position: 'side', |
| 80 | + }} |
| 81 | + tools={<Tools>{toolsContent.long}</Tools>} |
| 82 | + content={ |
| 83 | + <div |
| 84 | + style={{ |
| 85 | + backgroundColor: 'rgba(255, 255, 0, 0.1)', |
| 86 | + borderBottom: '1px dashed gray', |
| 87 | + }} |
| 88 | + > |
| 89 | + <Header variant="h1">Split panel with body scroll</Header> |
| 90 | + {contentByOverflowCondition[scrollbarDisplayCondition]} |
| 91 | + </div> |
| 92 | + } |
| 93 | + splitPanel={ |
| 94 | + <SplitPanel |
| 95 | + header="Split panel header" |
| 96 | + i18nStrings={{ |
| 97 | + preferencesTitle: 'Preferences', |
| 98 | + preferencesPositionLabel: 'Split panel position', |
| 99 | + preferencesPositionDescription: 'Choose the default split panel position for the service.', |
| 100 | + preferencesPositionSide: 'Side', |
| 101 | + preferencesPositionBottom: 'Bottom', |
| 102 | + preferencesConfirm: 'Confirm', |
| 103 | + preferencesCancel: 'Cancel', |
| 104 | + closeButtonAriaLabel: 'Close panel', |
| 105 | + openButtonAriaLabel: 'Open panel', |
| 106 | + resizeHandleAriaLabel: 'Slider', |
| 107 | + }} |
| 108 | + > |
| 109 | + <div id="radio-group-label">Let content overflow vertically when split panel is:</div> |
| 110 | + <RadioGroup |
| 111 | + ariaLabelledby="radio-group-label" |
| 112 | + value={scrollbarDisplayCondition} |
| 113 | + onChange={({ detail }) => setUrlParams({ scrollbarDisplayCondition: detail.value as ScrollbarCondition })} |
| 114 | + items={[ |
| 115 | + { |
| 116 | + value: 'side', |
| 117 | + label: 'On the side', |
| 118 | + }, |
| 119 | + { |
| 120 | + value: 'bottom', |
| 121 | + label: 'At the bottom', |
| 122 | + }, |
| 123 | + { |
| 124 | + value: 'always', |
| 125 | + label: 'Always', |
| 126 | + }, |
| 127 | + { |
| 128 | + value: 'never', |
| 129 | + label: 'Never', |
| 130 | + }, |
| 131 | + ]} |
| 132 | + /> |
| 133 | + </SplitPanel> |
| 134 | + } |
| 135 | + /> |
| 136 | + <Footer legacyConsoleNav={false} /> |
| 137 | + </> |
| 138 | + ); |
| 139 | +} |
0 commit comments