Repository navigation
chore: Styling v2 for slider and progress bar #5188
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
Open
pan-kot
wants to merge
3
commits into
main
Choose a base branch
from
chore-style-api-slider-progress-bar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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,21 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import { ProgressBar } from '~components'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
|
|
||
| import styles from './style-api-v2.scss'; | ||
|
|
||
| const brand = { styleClassNames: { root: styles['bar-brand'], percentage: styles['percentage-brand'] } }; | ||
| const genai = { styleClassNames: { root: styles['bar-genai'], percentage: styles['percentage-genai'] } }; | ||
|
|
||
| export default function () { | ||
| return ( | ||
| <SimplePage title="Progress bar - Style API v2" screenshotArea={{}}> | ||
| <ProgressBar value={45} label="Attachments" description="Files are uploading" {...brand} /> | ||
| <ProgressBar value={72} label="Attachments" additionalInfo="You can add more files at any time" {...genai} /> | ||
| </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,33 @@ | ||
| /* | ||
| Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| @use '~components/styling/progress-bar'; | ||
| @use '../style-api/palette' as palette; | ||
|
|
||
| .bar-brand { | ||
| @include progress-bar.root( | ||
| $track-color: palette.$subtle, | ||
| $value-color: palette.$accent, | ||
| $bar-border-radius: 2px, | ||
| $bar-block-size: 8px | ||
| ); | ||
| } | ||
|
|
||
| .bar-genai { | ||
| @include progress-bar.root( | ||
| $track-color: palette.$genai-surface, | ||
| $value-color: palette.$genai, | ||
| $bar-border-radius: 0, | ||
| $bar-block-size: 12px | ||
| ); | ||
| } | ||
|
|
||
| .percentage-brand { | ||
| @include progress-bar.percentage($color: palette.$accent, $font-size: 14px, $font-weight: 700); | ||
| } | ||
|
|
||
| .percentage-genai { | ||
| @include progress-bar.percentage($color: palette.$genai-text, $font-size: 16px, $font-weight: 600); | ||
| } | ||
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,69 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import { KeyValuePairs, Slider } from '~components'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
|
|
||
| import styles from './style-api-v2.scss'; | ||
|
|
||
| const styleClassNames = { root: styles.slider, handle: styles.handle }; | ||
|
|
||
| export default function () { | ||
| const [value, setValue] = useState(40); | ||
| return ( | ||
| <SimplePage title="Slider - Style API v2" screenshotArea={{}}> | ||
| <KeyValuePairs | ||
| items={[ | ||
| { | ||
| type: 'pair', | ||
| label: 'With tick marks', | ||
| value: ( | ||
| <Slider | ||
| value={value} | ||
| onChange={({ detail }) => setValue(detail.value)} | ||
| min={0} | ||
| max={100} | ||
| step={20} | ||
| tickMarks={true} | ||
| ariaLabel="With tick marks" | ||
| {...{ styleClassNames }} | ||
| /> | ||
| ), | ||
| }, | ||
| { | ||
| type: 'pair', | ||
| label: 'Disabled', | ||
| value: ( | ||
| <Slider | ||
| value={value} | ||
| onChange={({ detail }) => setValue(detail.value)} | ||
| min={0} | ||
| max={100} | ||
| disabled={true} | ||
| ariaLabel="Disabled" | ||
| {...{ styleClassNames }} | ||
| /> | ||
| ), | ||
| }, | ||
| { | ||
| type: 'pair', | ||
| label: 'Read-only', | ||
| value: ( | ||
| <Slider | ||
| value={value} | ||
| onChange={({ detail }) => setValue(detail.value)} | ||
| min={0} | ||
| max={100} | ||
| readOnly={true} | ||
| ariaLabel="Read-only" | ||
| {...{ styleClassNames }} | ||
| /> | ||
| ), | ||
| }, | ||
| ]} | ||
| /> | ||
| </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,39 @@ | ||
| /* | ||
| Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| @use '~components/styling/slider'; | ||
| @use '../style-api/palette' as palette; | ||
|
|
||
| .slider { | ||
| @include slider.root($track-color: palette.$surface-alt, $value-color: palette.$accent); | ||
| } | ||
|
|
||
| // The handle is the native <input type="range">, so its states are regular selectors. | ||
| .handle { | ||
| @include slider.handle($fill-color: palette.$accent, $halo-color: palette.$genai, $border-radius: 4px); | ||
|
|
||
| &:hover { | ||
| @include slider.handle($fill-color: palette.$accent-hover); | ||
| } | ||
|
|
||
| &:is(:focus, :active) { | ||
| @include slider.handle($fill-color: palette.$accent-active); | ||
| } | ||
|
|
||
| &:disabled, | ||
| &[aria-disabled='true'] { | ||
| @include slider.handle($fill-color: palette.$control-bg-disabled, $halo-color: palette.$control-bg-disabled); | ||
| } | ||
| } | ||
|
|
||
| // The value fill follows the handle state through :has() on the root slot. | ||
| .slider:has(.handle:is(:focus, :active)) { | ||
| @include slider.root($value-color: palette.$accent-active); | ||
| } | ||
|
|
||
| // After the focus rule: a read-only slider stays focusable, and both rules have the same specificity. | ||
| .slider:has(.handle:disabled, .handle[aria-disabled='true']) { | ||
| @include slider.root($value-color: palette.$control-bg-disabled); | ||
| } |
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 | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import ProgressBar, { ProgressBarProps } from '../../../lib/components/progress-bar'; | ||
| import createWrapper from '../../../lib/components/test-utils/dom'; | ||
|
|
||
| function renderProgressBar(props: Partial<ProgressBarProps> & Record<string, unknown> = {}) { | ||
| const { container } = render(<ProgressBar value={40} label="Label" {...props} />); | ||
| return { container, wrapper: createWrapper(container).findProgressBar()! }; | ||
| } | ||
|
|
||
| describe('ProgressBar Style API v2', () => { | ||
| test.each<ProgressBarProps.Variant>(['standalone', 'flash', 'key-value'])( | ||
| 'applies styleClassNames (variant=%s)', | ||
| variant => { | ||
| const { wrapper } = renderProgressBar({ | ||
| variant, | ||
| styleClassNames: { root: 'a', percentage: 'b', unknown: 'c' }, | ||
| }); | ||
| expect(wrapper.getElement()).toHaveClass('a'); | ||
| expect(wrapper.getElement()).not.toHaveClass('c'); | ||
|
|
||
| const percentage = wrapper.findPercentageText()!.getElement(); | ||
| expect(percentage).not.toHaveClass('a'); | ||
| expect(percentage).toHaveClass('b'); | ||
| expect(percentage).not.toHaveClass('c'); | ||
| } | ||
| ); | ||
|
|
||
| test('does not leak the styleClassNames prop to the DOM', () => { | ||
| const { container } = renderProgressBar({ styleClassNames: { root: 'a', percentage: 'b' } }); | ||
| 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we prefix this with
awsui-like$awsui-bar-border-radius, so it's clear it only accepts a single value? For example,4px 8pxwouldn't work here. According to the doc: UM9CHZ8CCdFlThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will add this change to the component toolkit part that generates css vars, docs, and mixins: every token that we pass to the style-api.docs() util will be automatically prefixed with
awsui-.