Repository navigation
feat: add headerSecondaryContent and hideHeaderText to ExpandableSection #5088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+765
−51
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
234 changes: 234 additions & 0 deletions
234
pages/expandable-section/header-secondary-content.page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import Badge from '~components/badge'; | ||
| import Box from '~components/box'; | ||
| import Button from '~components/button'; | ||
| import ButtonGroup from '~components/button-group'; | ||
| import ExpandableSection from '~components/expandable-section'; | ||
| import Input from '~components/input'; | ||
| import Link from '~components/link'; | ||
| import Popover from '~components/popover'; | ||
| import Select, { SelectProps } from '~components/select'; | ||
| import SpaceBetween from '~components/space-between'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
|
|
||
| const languageOptions: SelectProps.Options = [ | ||
| { label: 'SQL', value: 'sql' }, | ||
| { label: 'PPL', value: 'ppl' }, | ||
| { label: 'Logstash', value: 'logstash' }, | ||
| ]; | ||
|
|
||
| function StandardExample() { | ||
| return ( | ||
| <ExpandableSection variant="container" defaultExpanded={true} headerText="Standard expandable section"> | ||
| Content | ||
| </ExpandableSection> | ||
| ); | ||
| } | ||
|
|
||
| function CreateQueryExample() { | ||
| const [expanded, setExpanded] = useState(true); | ||
| const [language, setLanguage] = useState<SelectProps.Option>(languageOptions[0]); | ||
| return ( | ||
| <ExpandableSection | ||
| variant="container" | ||
| headerText="Create query" | ||
| expanded={expanded} | ||
| onChange={({ detail }) => setExpanded(detail.expanded)} | ||
| headerSecondaryContent={ | ||
| <Select | ||
| selectedOption={language} | ||
| onChange={({ detail }) => setLanguage(detail.selectedOption)} | ||
| options={languageOptions} | ||
| ariaLabel="Query language" | ||
| /> | ||
| } | ||
| headerActions={ | ||
| expanded ? ( | ||
| <SpaceBetween direction="horizontal" size="xs"> | ||
| <ButtonGroup | ||
| ariaLabel="Query actions" | ||
| variant="icon" | ||
| items={[ | ||
| { type: 'icon-button', id: 'copy', iconName: 'copy', text: 'Copy' }, | ||
| { type: 'icon-button', id: 'remove', iconName: 'remove', text: 'Clear' }, | ||
| ]} | ||
| /> | ||
| <Button>Save</Button> | ||
| <Button variant="primary">Run</Button> | ||
| </SpaceBetween> | ||
| ) : ( | ||
| <Button variant="primary">Run</Button> | ||
| ) | ||
| } | ||
| > | ||
| <Box color="text-body-secondary">SELECT * FROM logs WHERE status = 500 ORDER BY timestamp DESC LIMIT 100</Box> | ||
| </ExpandableSection> | ||
| ); | ||
| } | ||
|
|
||
| function DescriptionAsSecondaryContentExample() { | ||
| return ( | ||
| <ExpandableSection | ||
| variant="container" | ||
| defaultExpanded={true} | ||
| headerText="Production database" | ||
| headerSecondaryContent={<Box variant="small">Last synced 3 minutes ago</Box>} | ||
| headerActions={<Button>Refresh</Button>} | ||
| > | ||
| <Box color="text-body-secondary"> | ||
| Supporting text can live in the secondary content slot next to the header text, instead of the description slot | ||
| below it. | ||
| </Box> | ||
| </ExpandableSection> | ||
| ); | ||
| } | ||
|
|
||
| function HiddenHeaderTextExample() { | ||
| const sectionName = 'Data source A'; | ||
| const [language, setLanguage] = useState<SelectProps.Option>(languageOptions[0]); | ||
| return ( | ||
| <ExpandableSection | ||
| variant="container" | ||
| defaultExpanded={true} | ||
| headerText={sectionName} | ||
| hideHeaderText={true} | ||
| headerSecondaryContent={ | ||
| <SpaceBetween direction="horizontal" size="xs" alignItems="center"> | ||
| <Badge color="severity-low"> | ||
| <Box padding={{ vertical: 'xxs' }} color="inherit"> | ||
| <Popover content="Edit name..."> | ||
| <Box fontSize="heading-m" color="inherit"> | ||
| A | ||
| </Box> | ||
| </Popover> | ||
| </Box> | ||
| </Badge> | ||
| <Select | ||
| selectedOption={language} | ||
| onChange={({ detail }) => setLanguage(detail.selectedOption)} | ||
| options={languageOptions} | ||
| ariaLabel="Query language" | ||
| /> | ||
| </SpaceBetween> | ||
| } | ||
| > | ||
| <Box color="text-body-secondary">Configuration for {sectionName}.</Box> | ||
| </ExpandableSection> | ||
| ); | ||
| } | ||
|
|
||
| function HiddenHeaderTextSearchExample() { | ||
| const [value, setValue] = useState(''); | ||
| return ( | ||
| <ExpandableSection | ||
| variant="container" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add one more example with variant equals to container, and it has |
||
| defaultExpanded={true} | ||
| headerText="Search results" | ||
| hideHeaderText={true} | ||
| headerSecondaryContent={ | ||
| <Input | ||
| type="search" | ||
| value={value} | ||
| onChange={({ detail }) => setValue(detail.value)} | ||
| placeholder="Search results" | ||
| ariaLabel="Search results" | ||
| /> | ||
| } | ||
| > | ||
| <Box color="text-body-secondary">Results matching “{value || 'your query'}”.</Box> | ||
| </ExpandableSection> | ||
| ); | ||
| } | ||
|
|
||
| function AllHeaderSlotsExample() { | ||
| const [language, setLanguage] = useState<SelectProps.Option>(languageOptions[0]); | ||
| return ( | ||
| <ExpandableSection | ||
| variant="container" | ||
| defaultExpanded={true} | ||
| headerText="Queries" | ||
| headerCounter="(3)" | ||
| headerInfo={<Link variant="info">Info</Link>} | ||
| headerDescription="Saved queries for the production log group." | ||
| headerSecondaryContent={ | ||
| <Select | ||
| selectedOption={language} | ||
| onChange={({ detail }) => setLanguage(detail.selectedOption)} | ||
| options={languageOptions} | ||
| ariaLabel="Query language" | ||
| /> | ||
| } | ||
| headerActions={<Button variant="primary">Run</Button>} | ||
| > | ||
| <Box color="text-body-secondary">Counter, info link, description, secondary content and actions together.</Box> | ||
| </ExpandableSection> | ||
| ); | ||
| } | ||
|
|
||
| function LongContentExample() { | ||
| const [language, setLanguage] = useState<SelectProps.Option>(languageOptions[0]); | ||
| return ( | ||
| <ExpandableSection | ||
| variant="container" | ||
| defaultExpanded={true} | ||
| headerText="Create query for the aggregated multi-region production log analytics dataset" | ||
| headerSecondaryContent={ | ||
| <Select | ||
| selectedOption={language} | ||
| onChange={({ detail }) => setLanguage(detail.selectedOption)} | ||
| options={languageOptions} | ||
| ariaLabel="Query language" | ||
| /> | ||
| } | ||
| headerActions={ | ||
| <SpaceBetween direction="horizontal" size="xs"> | ||
| <Button>Save</Button> | ||
| <Button variant="primary">Run</Button> | ||
| </SpaceBetween> | ||
| } | ||
| > | ||
| <Box color="text-body-secondary">Stress case: long header text next to an interactive control and actions.</Box> | ||
| </ExpandableSection> | ||
| ); | ||
| } | ||
|
|
||
| export default function ExpandableSectionHeaderSecondaryContentPage() { | ||
| return ( | ||
| <SimplePage title="Expandable section — header secondary content" screenshotArea={{}}> | ||
| <SpaceBetween size="l"> | ||
| <div> | ||
| <h2>Standard</h2> | ||
| <StandardExample /> | ||
| </div> | ||
| <div> | ||
| <h2>Interactive control alongside visible header text</h2> | ||
| <CreateQueryExample /> | ||
| </div> | ||
| <div> | ||
| <h2>Description-style text as secondary content</h2> | ||
| <DescriptionAsSecondaryContentExample /> | ||
| </div> | ||
| <div> | ||
| <h2>Interactive control with hidden header text</h2> | ||
| <HiddenHeaderTextExample /> | ||
| </div> | ||
| <div> | ||
| <h2>Search input with hidden header text</h2> | ||
| <HiddenHeaderTextSearchExample /> | ||
| </div> | ||
| <div> | ||
| <h2>Counter, info link and description with secondary content</h2> | ||
| <AllHeaderSlotsExample /> | ||
| </div> | ||
| <div> | ||
| <h2>Long header text with control and actions</h2> | ||
| <LongContentExample /> | ||
| </div> | ||
| </SpaceBetween> | ||
| </SimplePage> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.