Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Add indeterminate checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Nov 13, 2018
1 parent 0b3a832 commit ca3300a
Show file tree
Hide file tree
Showing 7 changed files with 652 additions and 178 deletions.
4 changes: 4 additions & 0 deletions src/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {
disabled?: boolean,
/** ID for the checkbox */
id?: string,
indeterminate?: boolean,
/** Makes the checkbox required and sets aria-invalid to true */
isRequired?: boolean,
/** Checkbox label */
Expand All @@ -39,6 +40,7 @@ const Checkbox = ({
defaultChecked,
disabled,
id,
indeterminate,
isRequired,
label,
onBlur,
Expand All @@ -62,6 +64,7 @@ const Checkbox = ({
defaultChecked={defaultChecked}
disabled={disabled}
id={id}
indeterminate={indeterminate}
onBlur={onBlur}
onChange={onChange}
onFocus={onFocus}
Expand All @@ -84,6 +87,7 @@ Checkbox.defaultProps = {
defaultChecked: undefined,
disabled: false,
id: undefined,
indeterminate: false,
isRequired: false,
onBlur: undefined,
onChange: undefined,
Expand Down
6 changes: 6 additions & 0 deletions src/Checkbox/Checkbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Make the checkbox disabled with the `disabled` prop.
<Checkbox checked disabled label="Click me" />
</Playground>

## Indeterminate

<Playground>
<Checkbox label="Click me" checked indeterminate />
</Playground>

## States

A checkbox can use different states (as per palette) such as `danger`, `success` and `warning`.
Expand Down
3 changes: 3 additions & 0 deletions src/Checkbox/CheckboxField.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Props = {
hint?: string | Element<any>,
/** ID for the checkbox */
id?: string,
indeterminate?: boolean,
isFullWidth?: boolean,
isOptional?: boolean,
/** Makes the checkbox required and sets aria-invalid to true */
Expand All @@ -45,6 +46,7 @@ const CheckboxField = ({
description,
hint,
label,
indeterminate,
isFullWidth,
isOptional,
isRequired,
Expand Down Expand Up @@ -77,6 +79,7 @@ CheckboxField.defaultProps = {
disabled: false,
hint: undefined,
id: undefined,
indeterminate: false,
isFullWidth: false,
isOptional: false,
isRequired: false,
Expand Down
5 changes: 5 additions & 0 deletions src/Checkbox/__tests__/Checkbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ it('renders correctly for a disabled checkbox', () => {
expect(container.firstChild).toMatchSnapshot();
});

it('renders correctly for an indeterminate checkbox', () => {
const { container } = render(<Checkbox defaultChecked indeterminate />);
expect(container.firstChild).toMatchSnapshot();
});

describe('states', () => {
['danger', 'success', 'warning', 'primary'].forEach(state => {
it(`renders correctly for an checkbox with state ${state}`, () => {
Expand Down
Loading

0 comments on commit ca3300a

Please sign in to comment.