-
Notifications
You must be signed in to change notification settings - Fork 31
CardCheckbox and CardRadioGroup Components #2692
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 140 commits
Commits
Show all changes
157 commits
Select commit
Hold shift + click to select a range
b686844
Setup card2
coderitual b60d904
Mark legacy card as a deprecated
coderitual e85cafb
Extract clickable component
coderitual cd4c8fd
Add basic behaviour
coderitual 06f4a46
Change size
coderitual eea5129
Change naming convention for card
coderitual a06eac5
Add radio variant for API evalation
coderitual daa77a5
Add card checkbox template
coderitual d9f853d
Add checkbox for testing
coderitual 5fc75a7
Add checkbox indicator
coderitual c807fc4
Use default checkbox indicator if not provided
coderitual 7744571
Add checkbox indicator
coderitual 5ad87d6
Add prop types
coderitual 4ea9c32
Remove unnecessaary comment
coderitual b80229b
Remove unnecesasry type import
coderitual f76072e
Remove indicator input from dom tree
coderitual 32c4a27
Temp change class name for card
coderitual 3d24783
Add slots positions
coderitual 9b781cf
Change story
coderitual 78e083f
Add outline and solid variants
coderitual c37e32e
Add css colors
coderitual 723b341
Add comment
coderitual d6934b1
Override checkbox color
coderitual cc30356
Add bg color to card
coderitual 97bbdfc
Add dev stories to card checkbox
coderitual 8f3c583
Remove user select
coderitual b139e10
Add all variants to states table
coderitual 120d5b2
Add story with indicator position
coderitual 01003b7
Add states
coderitual 8bae397
add disabled data state
coderitual d4e5fdf
Override checkbox check color
coderitual 49504ed
Change story table
coderitual a1b8d59
Handle indicator color for disabled and invalid
coderitual 738122c
Change indicator position
coderitual 357c132
Add focus style
coderitual c886fa4
Add js docs
coderitual 00fcf03
Add basic tests
coderitual 4560604
Fix type
coderitual 198b16b
Change doc
coderitual 0f34a7e
Add focus state
coderitual 7fe266d
Add focus state
coderitual b4485d2
Use box shadow instead of outline
coderitual 628d98f
Remove unnecessary focus part
coderitual 81ff648
Focus
coderitual a4843f9
Add animated icons
coderitual f86e013
Add animated examples
coderitual 0645d99
Add more cards
coderitual b391b52
Update story
coderitual 88dac64
Change default story
coderitual 3b27fde
Remove unnecessary packages
coderitual 5224faa
Fix yarn.lock
coderitual 1efc2e4
Add ios event to press state
coderitual 3d400f1
Add gap to stories
coderitual 47a6d94
Change label structure
coderitual f29ff53
Update physics animation
coderitual 6153b7b
Add focus
coderitual deb68b3
Add focus on keyboard only
coderitual 18615af
Remove unecessary css variables
coderitual 4d89b27
Add more state to atributes
coderitual da8cafe
Remove redundant style
coderitual 5d4f93e
Fix hovering over invalid checkbox
coderitual d804a53
Sync hover animations
coderitual 9d77583
Add card radio
coderitual 5e5b12d
Add stories for radio
coderitual 95596bb
Change indicator default position
coderitual 66b69a2
Change checkbox bg color
coderitual a95c52e
Add shade hex color function
coderitual ede2872
Change section name
coderitual 39bc24d
Customise colors
coderitual 762dfd4
Rename components
coderitual 45241be
Refactor components naming
coderitual 2181f3c
Fix colors in radio indicator
coderitual d34d8d6
Adjust docs
coderitual 463e883
Fix radio isPristine check
coderitual 7361c74
Revert "Fix radio isPristine check"
coderitual bcb4f96
Use fake borders on solid variant
coderitual 41157ac
Add check on hover style
coderitual 807a4d4
Add border colors
coderitual cfa368c
Adjust ligtht and dark colors
coderitual e302ac9
Remove unused var
coderitual 7e7909c
Remove tap highlight from ios
coderitual 8ef6736
Fix stories
coderitual efafa56
Add card radio story
coderitual 18a86a1
Add card radio group
coderitual ce3294c
Change default story to CardRadiogroup
coderitual a58e81e
Refactor Card Radio to rely on Card Radio Group
coderitual c5dd2ee
Add jsdocs
coderitual 786a684
Import required type
coderitual 950a03c
Add direction
coderitual 5006a59
Pass required props to indicators
coderitual f3d2c63
Fix type err
coderitual ea96f6b
Clean up code
coderitual 6bc1190
Fix types and tests
coderitual 812ef61
Change error message
coderitual acc82b1
Handle indeterminate state
coderitual 6af3093
Fix card radio styles and adjust properties mapping
coderitual 48e4fd6
Add state dark to radio
coderitual ebe4d74
Fix radio circle inside color
coderitual c042c5d
Add radio group tests
coderitual 6295cff
Fix test
coderitual 73f0e91
Fix tests
coderitual 0f82149
Fix tests
coderitual 1c77747
Add card radio tests
coderitual 5c829ec
Improve Card radio test
coderitual 27ee45f
Fix card radio tests
coderitual 899a5c4
Add more tests to card radio
coderitual 012d051
Remove Card export only component
coderitual 6613236
Add chromatic
coderitual c6dddc7
Change folders
coderitual 8649f4b
Add export
coderitual cdaa678
Revert "Change folders"
coderitual 04933be
Change name
coderitual e9ece51
Add states light to checkbox
coderitual 8ea14fc
Use compound components naming
coderitual 95c5bc0
Add subcomponents
coderitual 6fce7a8
Fix ts
coderitual 9fbf427
Add custom images
coderitual ca90fc8
Add hacky fix to border radius artifact
coderitual fc9aaae
Remove clip-path
coderitual 2afb61f
Change border
coderitual b4728b2
Add accessibility docs do card checkbox
coderitual 8ef2ad5
Add a11y rules to card radio
coderitual 24afc32
Add tests to card checkbox
coderitual b126479
Add a11y docs to cardradiogroup
coderitual c888b61
Add tests to radio, fix checkbox and radio
coderitual 874f56b
Remove utils
coderitual a0ebdf1
Add focus state configuration
coderitual 8958751
Add prop documentation
coderitual 678d937
Fix direction in passing to flex
coderitual f14a51c
Add customisation section in mdx
coderitual c5325c5
Adjust focus color
coderitual 8e13100
Fox controlled state in card checkbox
coderitual 1c18d00
Adjust card checkbox stories
coderitual fcc4058
Add hover stories
coderitual 9d14310
Check chromatic story
coderitual f1ac389
Add chromatic stories
coderitual b606172
Improve stories in card radio
coderitual 6379260
Add def state
coderitual 0ccc539
Merge remote-tracking branch 'origin/master' into card-component
coderitual b950d14
Merge remote-tracking branch 'origin/master' into card-component
coderitual 63566fa
Review
coderitual 643036a
Fix comment
coderitual cef1c49
Improve animated story for radio
coderitual d86eefe
Use padding box for bg clip
coderitual b727efe
Fix story wrap in radio group
coderitual 6a5c44b
Fix card radio story
coderitual 84777ae
Use outer background instead of border
coderitual 6d62720
Add bg and border positon
coderitual 913fd72
Revert "Add bg and border positon"
coderitual e0033de
Revert "Use outer background instead of border"
coderitual 6b8052f
Use outer background instead of border
coderitual 8d6d836
Code review
coderitual 4314773
Fix story
coderitual a0b12a0
Code review
coderitual 9ccb9be
Code review
coderitual fa9cd0e
Code review
coderitual 3a7cb4f
Fix clicking on border
coderitual 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
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
9 changes: 9 additions & 0 deletions
9
src/components/card-interactive/CardCheckbox.chromatic.stories.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,9 @@ | ||
| import * as CardCheckbox from './CardCheckbox.stories.mdx'; | ||
| import {generateChromaticStory} from '../../chromatic/utils'; | ||
|
|
||
| export const Default = generateChromaticStory(CardCheckbox, { | ||
| storiesToHover: ['statesDark', 'statesLight'], | ||
| }); | ||
| const {includeStories, ...meta} = CardCheckbox.default; | ||
|
|
||
| export default meta; |
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,153 @@ | ||
| import * as React from 'react'; | ||
| import CardCheckbox from './CardCheckbox'; | ||
| import {render, screen} from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import {testA11y} from '../../axe'; | ||
|
|
||
| describe('<CardCheckbox />', () => { | ||
| it('renders unchecked checkbox input, without label', () => { | ||
| const checkbox = render(<CardCheckbox />); | ||
| const checkboxInput = checkbox.getByRole('checkbox') as HTMLInputElement; | ||
|
|
||
| expect(checkboxInput.checked).toBe(false); | ||
| expect(checkbox.queryByLabelText('my label')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders CardRadio with accessible name and checkbox role', () => { | ||
| const label = 'Option A'; | ||
|
|
||
| render(<CardCheckbox>{label}</CardCheckbox>); | ||
| const checkboxInput = screen.getByRole('checkbox', { | ||
| name: label, | ||
| }) as HTMLInputElement; | ||
|
|
||
| expect(checkboxInput).toBeInTheDocument(); | ||
| expect(checkboxInput.checked).toBe(false); | ||
| }); | ||
|
|
||
| it('does not allow checking disabled item', () => { | ||
| render(<CardCheckbox disabled>Option A</CardCheckbox>); | ||
| userEvent.click(screen.getByLabelText('Option A')); | ||
| expect(screen.getByLabelText('Option A')).not.toBeChecked(); | ||
| }); | ||
|
|
||
| it('checks/unchecks when either checkbox, input or label is clicked or space is pressed', () => { | ||
| const checkbox = render(<CardCheckbox>my label</CardCheckbox>); | ||
| const checkboxInput = checkbox.getByRole('checkbox') as HTMLInputElement; | ||
|
|
||
| expect(checkboxInput.checked).toBe(false); | ||
| userEvent.click(checkboxInput); | ||
| expect(checkboxInput).toEqual(document.activeElement); | ||
|
|
||
| expect(checkboxInput.checked).toBe(true); | ||
| userEvent.keyboard('{space}'); | ||
| expect(checkboxInput.checked).toBe(false); | ||
| userEvent.click(checkbox.getByText('my label')); | ||
| expect(checkboxInput.checked).toBe(true); | ||
| }); | ||
|
|
||
| it('allows aria-labbelledby to override accessible name', () => { | ||
| render( | ||
| <CardCheckbox aria-labelledby="labelid"> | ||
| Option A<span id="labelid">Custom Label Option A</span> | ||
| </CardCheckbox> | ||
| ); | ||
|
|
||
| const checkboxInput = screen.getByRole('checkbox', { | ||
| name: 'Custom Label Option A', | ||
| }) as HTMLInputElement; | ||
|
|
||
| expect(checkboxInput).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('allows descriibedby to define accessible description', () => { | ||
| render( | ||
| <CardCheckbox aria-describedby="descriptionid"> | ||
| Option A<span id="descriptionid">Custom Description Option A</span> | ||
| </CardCheckbox> | ||
| ); | ||
|
|
||
| const checkboxInput = screen.getByRole('checkbox', { | ||
| description: 'Custom Description Option A', | ||
| }) as HTMLInputElement; | ||
|
|
||
| expect(checkboxInput).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('it renders as checked by default', () => { | ||
| const checkbox = render( | ||
| <CardCheckbox defaultChecked>my label</CardCheckbox> | ||
| ); | ||
| const checkboxInput = checkbox.getByRole('checkbox') as HTMLInputElement; | ||
|
|
||
| expect(checkboxInput.checked).toBe(true); | ||
| }); | ||
|
|
||
| it('renders as unchecked by default', () => { | ||
| const checkbox = render( | ||
| <CardCheckbox defaultChecked={false}>my label</CardCheckbox> | ||
| ); | ||
| const checkboxInput = checkbox.getByRole('checkbox') as HTMLInputElement; | ||
|
|
||
| expect(checkboxInput.checked).toBe(false); | ||
| }); | ||
|
|
||
| it('works in controlled mode', () => { | ||
coderitual marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const ControlledCheckbox = () => { | ||
| const [checked, setChecked] = React.useState(false); | ||
|
|
||
| return ( | ||
| <CardCheckbox | ||
| checked={checked} | ||
| onChange={() => setChecked(val => !val)} | ||
| aria-labelledby="label" | ||
| > | ||
| <label id="label">placeholder</label> | ||
| </CardCheckbox> | ||
| ); | ||
| }; | ||
|
|
||
| const checkbox = render(<ControlledCheckbox />); | ||
| const checkboxInput = checkbox.getByRole('checkbox') as HTMLInputElement; | ||
|
|
||
| expect(checkboxInput.checked).toBe(false); | ||
| userEvent.click(checkboxInput); | ||
| expect(checkboxInput.checked).toBe(true); | ||
| userEvent.click(checkboxInput); | ||
| expect(checkboxInput.checked).toBe(false); | ||
| }); | ||
|
|
||
| describe('a11y', () => { | ||
| it('should have no a11y violations when children is provided', async () => { | ||
| await testA11y( | ||
| <CardCheckbox aria-labelledby="label"> | ||
| <label id="label">placeholder</label> | ||
| </CardCheckbox> | ||
| ); | ||
| }); | ||
|
|
||
| it('should have no a11y violations when checked', async () => { | ||
| await testA11y( | ||
| <CardCheckbox aria-labelledby="label" checked> | ||
| <label id="label">placeholder</label> | ||
| </CardCheckbox> | ||
| ); | ||
| }); | ||
|
|
||
| it('should have no a11y violations when disabled', async () => { | ||
| await testA11y( | ||
| <CardCheckbox aria-labelledby="label" disabled> | ||
| <label id="label">placeholder</label> | ||
| </CardCheckbox> | ||
| ); | ||
| }); | ||
|
|
||
| it('should have no a11y violations when required', async () => { | ||
| await testA11y( | ||
| <CardCheckbox aria-labelledby="label" required> | ||
| <label id="label">placeholder</label> | ||
| </CardCheckbox> | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
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.