|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +import React, { useContext } from 'react'; |
| 4 | + |
| 5 | +import { Button, Checkbox, SegmentedControl, SpaceBetween } from '~components'; |
| 6 | +import PanelLayout, { PanelLayoutProps } from '~components/panel-layout'; |
| 7 | +import { colorBackgroundCellShaded } from '~design-tokens'; |
| 8 | + |
| 9 | +import AppContext, { AppContextType } from '../app/app-context'; |
| 10 | +import { SimplePage } from '../app/templates'; |
| 11 | + |
| 12 | +type PageContext = React.Context< |
| 13 | + AppContextType<{ |
| 14 | + display: PanelLayoutProps.Display; |
| 15 | + panelPosition: PanelLayoutProps.PanelPosition; |
| 16 | + disablePanelScrolling: boolean; |
| 17 | + disableMainScrolling: boolean; |
| 18 | + tallContent: boolean; |
| 19 | + }> |
| 20 | +>; |
| 21 | + |
| 22 | +// Buttons flush with both inline edges, to check whether their focus rings are clipped. |
| 23 | +function EdgeContent({ label, tall }: { label: string; tall: boolean }) { |
| 24 | + return ( |
| 25 | + <div style={{ background: colorBackgroundCellShaded, blockSize: tall ? 600 : '100%' }}> |
| 26 | + <div style={{ display: 'flex', justifyContent: 'space-between' }}> |
| 27 | + <Button>{label} start</Button> |
| 28 | + <Button>{label} end</Button> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + ); |
| 32 | +} |
| 33 | + |
| 34 | +export default function PanelLayoutDisableScrollingPage() { |
| 35 | + const { |
| 36 | + urlParams: { |
| 37 | + display = 'all', |
| 38 | + panelPosition = 'side-start', |
| 39 | + disablePanelScrolling = false, |
| 40 | + disableMainScrolling = false, |
| 41 | + tallContent = false, |
| 42 | + }, |
| 43 | + setUrlParams, |
| 44 | + } = useContext(AppContext as PageContext); |
| 45 | + |
| 46 | + return ( |
| 47 | + <SimplePage |
| 48 | + title="Panel layout with disabled scrolling" |
| 49 | + screenshotArea={{}} |
| 50 | + settings={ |
| 51 | + <SpaceBetween size="s"> |
| 52 | + <SegmentedControl |
| 53 | + label="Display" |
| 54 | + options={[ |
| 55 | + { id: 'all', text: 'all' }, |
| 56 | + { id: 'panel-only', text: 'panel-only' }, |
| 57 | + { id: 'main-only', text: 'main-only' }, |
| 58 | + ]} |
| 59 | + selectedId={display} |
| 60 | + onChange={({ detail }) => setUrlParams({ display: detail.selectedId as PanelLayoutProps.Display })} |
| 61 | + /> |
| 62 | + <SegmentedControl |
| 63 | + label="Panel position" |
| 64 | + options={[ |
| 65 | + { id: 'side-start', text: 'side-start' }, |
| 66 | + { id: 'side-end', text: 'side-end' }, |
| 67 | + ]} |
| 68 | + selectedId={panelPosition} |
| 69 | + onChange={({ detail }) => |
| 70 | + setUrlParams({ panelPosition: detail.selectedId as PanelLayoutProps.PanelPosition }) |
| 71 | + } |
| 72 | + /> |
| 73 | + <Checkbox |
| 74 | + checked={disablePanelScrolling} |
| 75 | + onChange={({ detail }) => setUrlParams({ disablePanelScrolling: detail.checked })} |
| 76 | + > |
| 77 | + disablePanelScrolling |
| 78 | + </Checkbox> |
| 79 | + <Checkbox |
| 80 | + checked={disableMainScrolling} |
| 81 | + onChange={({ detail }) => setUrlParams({ disableMainScrolling: detail.checked })} |
| 82 | + > |
| 83 | + disableMainScrolling |
| 84 | + </Checkbox> |
| 85 | + <Checkbox checked={tallContent} onChange={({ detail }) => setUrlParams({ tallContent: detail.checked })}> |
| 86 | + Tall content |
| 87 | + </Checkbox> |
| 88 | + </SpaceBetween> |
| 89 | + } |
| 90 | + > |
| 91 | + <div style={{ blockSize: 300 }}> |
| 92 | + <PanelLayout |
| 93 | + resizable={true} |
| 94 | + defaultPanelSize={300} |
| 95 | + minPanelSize={200} |
| 96 | + display={display} |
| 97 | + panelPosition={panelPosition} |
| 98 | + disablePanelScrolling={disablePanelScrolling} |
| 99 | + disableMainScrolling={disableMainScrolling} |
| 100 | + panelContent={<EdgeContent label="Panel" tall={tallContent} />} |
| 101 | + mainContent={<EdgeContent label="Main" tall={tallContent} />} |
| 102 | + /> |
| 103 | + </div> |
| 104 | + </SimplePage> |
| 105 | + ); |
| 106 | +} |
0 commit comments