-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add selection state to Detail View (#5868)
--------- Co-authored-by: Caleb Pollman <[email protected]>
- Loading branch information
Showing
11 changed files
with
551 additions
and
128 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/react-storage/src/components/StorageBrowser/components/Checkbox.tsx
This file contains 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,50 @@ | ||
import React from 'react'; | ||
|
||
import { CLASS_BASE } from '../views/constants'; | ||
import { | ||
ViewElement, | ||
LabelElement, | ||
InputElement, | ||
} from '../context/elements/definitions'; | ||
|
||
const BLOCK_NAME = `${CLASS_BASE}__checkbox`; | ||
export const INPUT_CLASSNAME = `${BLOCK_NAME}-input`; | ||
export const LABEL_CLASSNAME = `${BLOCK_NAME}-label`; | ||
|
||
interface CheckboxControlProps { | ||
checked?: boolean; | ||
disabled?: boolean; | ||
id?: string; | ||
labelHidden?: boolean; | ||
labelText?: string; | ||
onSelect?: () => void; | ||
} | ||
|
||
export const CheckboxControl = ({ | ||
disabled, | ||
checked, | ||
onSelect, | ||
labelText, | ||
labelHidden = false, | ||
id, | ||
}: CheckboxControlProps): React.JSX.Element => ( | ||
<ViewElement className={BLOCK_NAME}> | ||
<InputElement | ||
checked={checked} | ||
className={INPUT_CLASSNAME} | ||
disabled={disabled} | ||
id={id} | ||
onChange={onSelect} | ||
type="checkbox" | ||
/> | ||
<LabelElement | ||
className={[ | ||
LABEL_CLASSNAME, | ||
labelHidden ? `${CLASS_BASE}-visually-hidden` : undefined, | ||
].join(' ')} | ||
htmlFor={id} | ||
> | ||
{labelText} | ||
</LabelElement> | ||
</ViewElement> | ||
); |
53 changes: 53 additions & 0 deletions
53
packages/react-storage/src/components/StorageBrowser/components/__tests__/Checkbox.spec.tsx
This file contains 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,53 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { CheckboxControl, INPUT_CLASSNAME, LABEL_CLASSNAME } from '../Checkbox'; | ||
|
||
const myLabelText = 'My Checkbox'; | ||
const handleSelect = jest.fn(); | ||
|
||
describe('CheckboxControl', () => { | ||
it('renders the CheckboxControl', () => { | ||
render( | ||
<CheckboxControl | ||
id="checkbox-id" | ||
checked={false} | ||
labelText={myLabelText} | ||
onSelect={handleSelect} | ||
/> | ||
); | ||
const input = screen.getByRole('checkbox'); | ||
const label = screen.getByText(myLabelText); | ||
expect(input).toBeInTheDocument(); | ||
expect(input).not.toHaveAttribute('checked'); | ||
expect(input).toHaveClass(INPUT_CLASSNAME); | ||
expect(label).toHaveClass(LABEL_CLASSNAME); | ||
expect(label).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the CheckboxControl checked', () => { | ||
render( | ||
<CheckboxControl | ||
id="checkbox-id" | ||
checked | ||
labelText={myLabelText} | ||
onSelect={handleSelect} | ||
/> | ||
); | ||
const input = screen.getByRole('checkbox'); | ||
expect(input).toHaveAttribute('checked'); | ||
}); | ||
|
||
it('accepts onSelect prop', () => { | ||
render( | ||
<CheckboxControl | ||
id="checkbox-id" | ||
checked | ||
labelText={myLabelText} | ||
onSelect={handleSelect} | ||
/> | ||
); | ||
const input = screen.getByRole('checkbox'); | ||
fireEvent.click(input); | ||
expect(handleSelect).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains 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 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 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 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 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.