Repository navigation
chore: Adds internal style api v2 to container #5192
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
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
There are no files selected for viewing
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,78 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import { Box, ColumnLayout, Container, ContainerProps, Header } from '~components'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
| import image169 from './images/16-9.png'; | ||
|
|
||
| import styles from './style-api-v2.scss'; | ||
|
|
||
| function StyledContainer(props: ContainerProps) { | ||
| return ( | ||
| <Container | ||
| {...props} | ||
| {...{ styleClassNames: { root: styles.container, header: styles.header, footer: styles.footer } }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function Permutation({ label, children }: { label: string; children: React.ReactNode }) { | ||
| return ( | ||
| <div> | ||
| <Box variant="awsui-key-label" margin={{ bottom: 'xs' }}> | ||
| {label} | ||
| </Box> | ||
| {children} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default function () { | ||
| return ( | ||
| <SimplePage title="Container - Style API v2" screenshotArea={{}} i18n={{}}> | ||
| <ColumnLayout columns={2}> | ||
| <Permutation label="Header, content and footer"> | ||
| <StyledContainer header={<Header variant="h2">Header</Header>} footer="Footer"> | ||
| Content | ||
| </StyledContainer> | ||
| </Permutation> | ||
| <Permutation label="Media on top"> | ||
| <StyledContainer | ||
| header={<Header variant="h2">Header</Header>} | ||
| media={{ content: <img src={image169} alt="" />, position: 'top', height: 120 }} | ||
| > | ||
| Content | ||
| </StyledContainer> | ||
| </Permutation> | ||
| <Permutation label="Stacked"> | ||
| <StyledContainer variant="stacked" header={<Header variant="h2">First</Header>} footer="First footer"> | ||
| Content | ||
| </StyledContainer> | ||
| <StyledContainer variant="stacked" header={<Header variant="h2">Second</Header>} footer="Second footer"> | ||
| Content | ||
| </StyledContainer> | ||
| </Permutation> | ||
| <Permutation label="Header only"> | ||
| <StyledContainer header={<Header variant="h2">Header</Header>}>Content</StyledContainer> | ||
| </Permutation> | ||
| <Permutation label="Footer only"> | ||
| <StyledContainer footer="Footer">Content</StyledContainer> | ||
| </Permutation> | ||
| <Permutation label="Header without paddings"> | ||
| <StyledContainer | ||
| disableHeaderPaddings={true} | ||
| header={ | ||
| <Box padding={{ vertical: 's', horizontal: 'l' }} fontWeight="bold"> | ||
| Header filled by its own element | ||
| </Box> | ||
| } | ||
| > | ||
| Content | ||
| </StyledContainer> | ||
| </Permutation> | ||
| </ColumnLayout> | ||
| </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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| @use '~components/styling/container'; | ||
| @use '../style-api/palette' as palette; | ||
|
|
||
| .container { | ||
| @include container.root( | ||
| $background: palette.$surface, | ||
| $border-color: palette.$border-accent, | ||
| $border-width: 2px, | ||
| $border-style: solid, | ||
| $box-shadow: 0 4px 12px palette.$subtle-active, | ||
| $border-radius: 24px | ||
| ); | ||
| } | ||
|
|
||
| // Only the block-end side of the header border is visible: it is the divider between the header and the content. | ||
| .header { | ||
| @include container.header( | ||
| $background: palette.$genai-surface, | ||
| $border-color: palette.$genai, | ||
| $border-block-width: 0 2px | ||
| ); | ||
| } | ||
|
|
||
| // Only the block-start side of the footer border is visible: it is the divider between the content and the footer. | ||
| .footer { | ||
| @include container.footer( | ||
| $background: palette.$info-surface, | ||
| $border-color: palette.$info, | ||
| $border-block-width: 3px 0 | ||
| ); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import Container, { ContainerProps } from '../../../lib/components/container'; | ||
| import createWrapper from '../../../lib/components/test-utils/dom'; | ||
|
|
||
| function renderContainer(props: ContainerProps & { styleClassNames?: Record<string, string> } = {}) { | ||
| const { container } = render(<Container {...props}>Content</Container>); | ||
| return { container, wrapper: createWrapper(container).findContainer()! }; | ||
| } | ||
|
|
||
| const styleClassNames = { root: 'a', header: 'b', footer: 'c', unknown: 'd' }; | ||
|
|
||
| describe('Container Style API v2', () => { | ||
| test('applies each slot class to its element and ignores unknown keys', () => { | ||
| const { container, wrapper } = renderContainer({ header: 'Header', footer: 'Footer', styleClassNames }); | ||
| expect(wrapper.getElement()).toHaveClass('a'); | ||
| expect(wrapper.findHeader()!.getElement()).toHaveClass('b'); | ||
| expect(wrapper.findFooter()!.getElement()).toHaveClass('c'); | ||
| expect(container.querySelectorAll('.a, .b, .c')).toHaveLength(3); | ||
| expect(container.querySelector('.d')).toBeNull(); | ||
| }); | ||
|
|
||
| test('applies the root class in the stacked variant and with media', () => { | ||
| const { container, wrapper } = renderContainer({ | ||
| variant: 'stacked', | ||
| media: { content: <img alt="" /> }, | ||
| styleClassNames, | ||
| }); | ||
| expect(wrapper.getElement()).toHaveClass('a'); | ||
| expect(container.querySelectorAll('.a')).toHaveLength(1); | ||
| }); | ||
|
|
||
| test('does not leak the styleClassNames prop to the DOM', () => { | ||
| const { container } = renderContainer({ header: 'Header', footer: 'Footer', styleClassNames }); | ||
| expect(container.querySelector('[styleClassNames]')).toBeNull(); | ||
| }); | ||
| }); |
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.