generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 204
feat: Add radio button component to Core #3860
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
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8b98791
Move style utils to internal radio button component
jperals 712018e
feat: Add Radio Button component to Core
jperals 8f18a77
Fix a11y in dev pages
jperals eea515e
Add system tag
jperals 12e6bff
Duplicate interface to workarond TS compile issue
jperals d61fe0b
Update API docs
jperals fa7bf45
Revert "Move style utils to internal radio button component"
jperals c7c6d07
Fix documenter snapshot
jperals 5cb252f
Add coverage
jperals 2af378e
Add coverage and support for native attributes
jperals 2dbb861
Replace onChange with onClick
jperals 239c404
Do not pass checked state to onClick
jperals 13d9e96
Revert "Do not pass checked state to onClick"
jperals dd89299
Toggle checked value in internal component for backwards compatibility
jperals 30d4c5a
Rename onClick to onSelect
jperals da9a233
Remove dev pages which are not used for tests
jperals 80883b0
Restore system tag for style prop
jperals 86bedb7
Update Documenter snapshot
jperals 9cc1109
Refactor dev pages
jperals 677d60e
Only call onSelect when not checked
jperals b9f40e5
Refactor tests
jperals c8199e2
Add missing screenshot areas
jperals 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
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,52 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import RadioButton, { RadioButtonProps } from '~components/radio-button'; | ||
|
|
||
| import createPermutations from '../utils/permutations'; | ||
|
|
||
| const shortText = 'Short text'; | ||
|
|
||
| export const longText = | ||
| 'Long text, long enough to wrap. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Whatever.'; | ||
|
|
||
| type Permutation = Omit<RadioButtonProps, 'name'>; | ||
|
|
||
| export const permutations = createPermutations<Permutation>([ | ||
| { | ||
| description: [undefined, shortText, longText], | ||
| children: [undefined, shortText, longText], | ||
| readOnly: [false, true], | ||
| disabled: [false, true], | ||
| checked: [true, false], | ||
| }, | ||
| ]); | ||
|
|
||
| export const RadioButtonPermutation = ({ | ||
| children, | ||
| description, | ||
| readOnly, | ||
| disabled, | ||
| checked, | ||
| index, | ||
| }: Permutation & { index?: number }) => { | ||
| const commonProps = { | ||
| children, | ||
| description, | ||
| readOnly, | ||
| disabled, | ||
| checked, | ||
| name: `radio-group-${index}`, | ||
| }; | ||
| if (children) { | ||
| return <RadioButton {...commonProps} />; | ||
| } else { | ||
| // If no visual label provided, add a label for screen readers | ||
| return ( | ||
| <label aria-label={`Select ${index}`}> | ||
| <RadioButton {...commonProps} /> | ||
| </label> | ||
| ); | ||
| } | ||
| }; |
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,47 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import { palette } from '../app/themes/style-api'; | ||
|
|
||
| export default { | ||
| input: { | ||
| stroke: { | ||
| default: palette.neutral80, | ||
| disabled: palette.neutral100, | ||
| readOnly: palette.neutral90, | ||
| }, | ||
| fill: { | ||
| checked: palette.teal80, | ||
| default: palette.neutral10, | ||
| disabled: palette.neutral60, | ||
| readOnly: palette.neutral40, | ||
| }, | ||
| circle: { | ||
| fill: { | ||
| checked: palette.neutral10, | ||
| disabled: palette.neutral10, | ||
| readOnly: palette.neutral80, | ||
| }, | ||
| }, | ||
| focusRing: { | ||
| borderColor: palette.teal80, | ||
| borderRadius: '2px', | ||
| borderWidth: '1px', | ||
| }, | ||
| }, | ||
| label: { | ||
| color: { | ||
| checked: `light-dark(${palette.neutral100}, ${palette.neutral10})`, | ||
| default: `light-dark(${palette.neutral100}, ${palette.neutral10})`, | ||
| disabled: `light-dark(${palette.neutral80}, ${palette.neutral40})`, | ||
| readOnly: `light-dark(${palette.neutral80}, ${palette.neutral40})`, | ||
| }, | ||
| }, | ||
| description: { | ||
| color: { | ||
| checked: `light-dark(${palette.neutral100}, ${palette.neutral10})`, | ||
| default: `light-dark(${palette.neutral100}, ${palette.neutral10})`, | ||
| disabled: `light-dark(${palette.neutral80}, ${palette.neutral40})`, | ||
| readOnly: `light-dark(${palette.neutral80}, ${palette.neutral40})`, | ||
| }, | ||
| }, | ||
| }; |
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,23 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import RadioButton from '~components/radio-button'; | ||
|
|
||
| import FocusTarget from '../common/focus-target'; | ||
| import ScreenshotArea from '../utils/screenshot-area'; | ||
|
|
||
| export default function RadioButtonScenario() { | ||
| const [checked, setChecked] = useState(false); | ||
| return ( | ||
| <article> | ||
| <h1>Radio buttons should be focused using the correct highlight</h1> | ||
| <FocusTarget /> | ||
| <ScreenshotArea> | ||
| <RadioButton name="radio-button-group" checked={checked} onSelect={() => setChecked(true)}> | ||
| Radio button label | ||
| </RadioButton> | ||
| </ScreenshotArea> | ||
| </article> | ||
| ); | ||
| } | ||
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,18 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
| import PermutationsView from '../utils/permutations-view'; | ||
| import { permutations, RadioButtonPermutation } from './common'; | ||
|
|
||
| export default function RadioButtonPermutations() { | ||
| return ( | ||
| <SimplePage title="RadioButton permutations" screenshotArea={{}}> | ||
| <PermutationsView | ||
| permutations={permutations} | ||
| render={(permutation, index) => <RadioButtonPermutation {...permutation} index={index} />} | ||
| /> | ||
| </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,19 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
| import PermutationsView from '../utils/permutations-view'; | ||
| import { permutations, RadioButtonPermutation } from './common'; | ||
| import customStyle from './custom-style'; | ||
|
|
||
| export default function RadioButtonPermutations() { | ||
| return ( | ||
| <SimplePage title="RadioButton permutations with custom styles" screenshotArea={{}}> | ||
| <PermutationsView | ||
| permutations={permutations} | ||
| render={(permutation, index) => <RadioButtonPermutation {...permutation} index={index} style={customStyle} />} | ||
| /> | ||
| </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,19 @@ | ||
| /* | ||
| Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| @use '~design-tokens' as awsui; | ||
|
|
||
| .radio-group { | ||
| display: flex; | ||
| column-gap: awsui.$space-scaled-m; | ||
| row-gap: awsui.$space-scaled-xs; | ||
| &--horizontal { | ||
| flex-direction: row; | ||
| flex-wrap: wrap; | ||
| } | ||
| &--vertical { | ||
| flex-direction: column; | ||
| } | ||
| } |
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.