|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +import React, { useState } from 'react'; |
| 4 | + |
| 5 | +import Badge from '~components/badge'; |
| 6 | +import Box from '~components/box'; |
| 7 | +import Button from '~components/button'; |
| 8 | +import ButtonGroup from '~components/button-group'; |
| 9 | +import ExpandableSection from '~components/expandable-section'; |
| 10 | +import Input from '~components/input'; |
| 11 | +import Link from '~components/link'; |
| 12 | +import Popover from '~components/popover'; |
| 13 | +import Select, { SelectProps } from '~components/select'; |
| 14 | +import SpaceBetween from '~components/space-between'; |
| 15 | + |
| 16 | +import { SimplePage } from '../app/templates'; |
| 17 | + |
| 18 | +const languageOptions: SelectProps.Options = [ |
| 19 | + { label: 'SQL', value: 'sql' }, |
| 20 | + { label: 'PPL', value: 'ppl' }, |
| 21 | + { label: 'Logstash', value: 'logstash' }, |
| 22 | +]; |
| 23 | + |
| 24 | +function StandardExample() { |
| 25 | + return ( |
| 26 | + <ExpandableSection variant="container" defaultExpanded={true} headerText="Standard expandable section"> |
| 27 | + Content |
| 28 | + </ExpandableSection> |
| 29 | + ); |
| 30 | +} |
| 31 | + |
| 32 | +function CreateQueryExample() { |
| 33 | + const [expanded, setExpanded] = useState(true); |
| 34 | + const [language, setLanguage] = useState<SelectProps.Option>(languageOptions[0]); |
| 35 | + return ( |
| 36 | + <ExpandableSection |
| 37 | + variant="container" |
| 38 | + headerText="Create query" |
| 39 | + expanded={expanded} |
| 40 | + onChange={({ detail }) => setExpanded(detail.expanded)} |
| 41 | + headerSecondaryContent={ |
| 42 | + <Select |
| 43 | + selectedOption={language} |
| 44 | + onChange={({ detail }) => setLanguage(detail.selectedOption)} |
| 45 | + options={languageOptions} |
| 46 | + ariaLabel="Query language" |
| 47 | + /> |
| 48 | + } |
| 49 | + headerActions={ |
| 50 | + expanded ? ( |
| 51 | + <SpaceBetween direction="horizontal" size="xs"> |
| 52 | + <ButtonGroup |
| 53 | + ariaLabel="Query actions" |
| 54 | + variant="icon" |
| 55 | + items={[ |
| 56 | + { type: 'icon-button', id: 'copy', iconName: 'copy', text: 'Copy' }, |
| 57 | + { type: 'icon-button', id: 'remove', iconName: 'remove', text: 'Clear' }, |
| 58 | + ]} |
| 59 | + /> |
| 60 | + <Button>Save</Button> |
| 61 | + <Button variant="primary">Run</Button> |
| 62 | + </SpaceBetween> |
| 63 | + ) : ( |
| 64 | + <Button variant="primary">Run</Button> |
| 65 | + ) |
| 66 | + } |
| 67 | + > |
| 68 | + <Box color="text-body-secondary">SELECT * FROM logs WHERE status = 500 ORDER BY timestamp DESC LIMIT 100</Box> |
| 69 | + </ExpandableSection> |
| 70 | + ); |
| 71 | +} |
| 72 | + |
| 73 | +function DescriptionAsSecondaryContentExample() { |
| 74 | + return ( |
| 75 | + <ExpandableSection |
| 76 | + variant="container" |
| 77 | + defaultExpanded={true} |
| 78 | + headerText="Production database" |
| 79 | + headerSecondaryContent={<Box variant="small">Last synced 3 minutes ago</Box>} |
| 80 | + headerActions={<Button>Refresh</Button>} |
| 81 | + > |
| 82 | + <Box color="text-body-secondary"> |
| 83 | + Supporting text can live in the secondary content slot next to the header text, instead of the description slot |
| 84 | + below it. |
| 85 | + </Box> |
| 86 | + </ExpandableSection> |
| 87 | + ); |
| 88 | +} |
| 89 | + |
| 90 | +function HiddenHeaderTextExample() { |
| 91 | + const sectionName = 'Data source A'; |
| 92 | + const [language, setLanguage] = useState<SelectProps.Option>(languageOptions[0]); |
| 93 | + return ( |
| 94 | + <ExpandableSection |
| 95 | + variant="container" |
| 96 | + defaultExpanded={true} |
| 97 | + headerText={sectionName} |
| 98 | + hideHeaderText={true} |
| 99 | + headerSecondaryContent={ |
| 100 | + <SpaceBetween direction="horizontal" size="xs" alignItems="center"> |
| 101 | + <Badge color="severity-low"> |
| 102 | + <Box padding={{ vertical: 'xxs' }} color="inherit"> |
| 103 | + <Popover content="Edit name..."> |
| 104 | + <Box fontSize="heading-m" color="inherit"> |
| 105 | + A |
| 106 | + </Box> |
| 107 | + </Popover> |
| 108 | + </Box> |
| 109 | + </Badge> |
| 110 | + <Select |
| 111 | + selectedOption={language} |
| 112 | + onChange={({ detail }) => setLanguage(detail.selectedOption)} |
| 113 | + options={languageOptions} |
| 114 | + ariaLabel="Query language" |
| 115 | + /> |
| 116 | + </SpaceBetween> |
| 117 | + } |
| 118 | + > |
| 119 | + <Box color="text-body-secondary">Configuration for {sectionName}.</Box> |
| 120 | + </ExpandableSection> |
| 121 | + ); |
| 122 | +} |
| 123 | + |
| 124 | +function HiddenHeaderTextSearchExample() { |
| 125 | + const [value, setValue] = useState(''); |
| 126 | + return ( |
| 127 | + <ExpandableSection |
| 128 | + variant="container" |
| 129 | + defaultExpanded={true} |
| 130 | + headerText="Search results" |
| 131 | + hideHeaderText={true} |
| 132 | + headerSecondaryContent={ |
| 133 | + <Input |
| 134 | + type="search" |
| 135 | + value={value} |
| 136 | + onChange={({ detail }) => setValue(detail.value)} |
| 137 | + placeholder="Search results" |
| 138 | + ariaLabel="Search results" |
| 139 | + /> |
| 140 | + } |
| 141 | + > |
| 142 | + <Box color="text-body-secondary">Results matching “{value || 'your query'}”.</Box> |
| 143 | + </ExpandableSection> |
| 144 | + ); |
| 145 | +} |
| 146 | + |
| 147 | +function AllHeaderSlotsExample() { |
| 148 | + const [language, setLanguage] = useState<SelectProps.Option>(languageOptions[0]); |
| 149 | + return ( |
| 150 | + <ExpandableSection |
| 151 | + variant="container" |
| 152 | + defaultExpanded={true} |
| 153 | + headerText="Queries" |
| 154 | + headerCounter="(3)" |
| 155 | + headerInfo={<Link variant="info">Info</Link>} |
| 156 | + headerDescription="Saved queries for the production log group." |
| 157 | + headerSecondaryContent={ |
| 158 | + <Select |
| 159 | + selectedOption={language} |
| 160 | + onChange={({ detail }) => setLanguage(detail.selectedOption)} |
| 161 | + options={languageOptions} |
| 162 | + ariaLabel="Query language" |
| 163 | + /> |
| 164 | + } |
| 165 | + headerActions={<Button variant="primary">Run</Button>} |
| 166 | + > |
| 167 | + <Box color="text-body-secondary">Counter, info link, description, secondary content and actions together.</Box> |
| 168 | + </ExpandableSection> |
| 169 | + ); |
| 170 | +} |
| 171 | + |
| 172 | +function LongContentExample() { |
| 173 | + const [language, setLanguage] = useState<SelectProps.Option>(languageOptions[0]); |
| 174 | + return ( |
| 175 | + <ExpandableSection |
| 176 | + variant="container" |
| 177 | + defaultExpanded={true} |
| 178 | + headerText="Create query for the aggregated multi-region production log analytics dataset" |
| 179 | + headerSecondaryContent={ |
| 180 | + <Select |
| 181 | + selectedOption={language} |
| 182 | + onChange={({ detail }) => setLanguage(detail.selectedOption)} |
| 183 | + options={languageOptions} |
| 184 | + ariaLabel="Query language" |
| 185 | + /> |
| 186 | + } |
| 187 | + headerActions={ |
| 188 | + <SpaceBetween direction="horizontal" size="xs"> |
| 189 | + <Button>Save</Button> |
| 190 | + <Button variant="primary">Run</Button> |
| 191 | + </SpaceBetween> |
| 192 | + } |
| 193 | + > |
| 194 | + <Box color="text-body-secondary">Stress case: long header text next to an interactive control and actions.</Box> |
| 195 | + </ExpandableSection> |
| 196 | + ); |
| 197 | +} |
| 198 | + |
| 199 | +export default function ExpandableSectionHeaderSecondaryContentPage() { |
| 200 | + return ( |
| 201 | + <SimplePage title="Expandable section — header secondary content" screenshotArea={{}}> |
| 202 | + <SpaceBetween size="l"> |
| 203 | + <div> |
| 204 | + <h2>Standard</h2> |
| 205 | + <StandardExample /> |
| 206 | + </div> |
| 207 | + <div> |
| 208 | + <h2>Interactive control alongside visible header text</h2> |
| 209 | + <CreateQueryExample /> |
| 210 | + </div> |
| 211 | + <div> |
| 212 | + <h2>Description-style text as secondary content</h2> |
| 213 | + <DescriptionAsSecondaryContentExample /> |
| 214 | + </div> |
| 215 | + <div> |
| 216 | + <h2>Interactive control with hidden header text</h2> |
| 217 | + <HiddenHeaderTextExample /> |
| 218 | + </div> |
| 219 | + <div> |
| 220 | + <h2>Search input with hidden header text</h2> |
| 221 | + <HiddenHeaderTextSearchExample /> |
| 222 | + </div> |
| 223 | + <div> |
| 224 | + <h2>Counter, info link and description with secondary content</h2> |
| 225 | + <AllHeaderSlotsExample /> |
| 226 | + </div> |
| 227 | + <div> |
| 228 | + <h2>Long header text with control and actions</h2> |
| 229 | + <LongContentExample /> |
| 230 | + </div> |
| 231 | + </SpaceBetween> |
| 232 | + </SimplePage> |
| 233 | + ); |
| 234 | +} |
0 commit comments