@workday/canvas-kit-docs
Version:
Documentation components of Canvas Kit components
115 lines (73 loc) • 3.36 kB
text/mdx
import {
ExampleCodeBlock,
SymbolDoc,
Specifications,
InformationHighlight,
} from '@workday/canvas-kit-docs';
import Caution from './examples/Caution';
import Basic from './examples/Basic';
import Inverse from './examples/Inverse';
import Disabled from './examples/Disabled';
import Error from './examples/Error';
import Indeterminate from './examples/Indeterminate';
import LabelPosition from './examples/LabelPosition';
import RefForwarding from './examples/RefForwarding';
import Required from './examples/Required';
Checkboxes allow a user to select zero, one, or multiple values from a predefined list of 7 or less
options.
[> Workday Design Reference](https://design.workday.com/components/inputs/checkboxes)
```sh
yarn add @workday/canvas-kit-react
```
Checkbox may be used on its own without [Form Field](/components/inputs/form-field/) since it
includes a `<label>` with a `for` attribute referencing the underlying `<input type="checkbox">`
element.
<ExampleCodeBlock code={Basic} />
Checkbox with inverse variation
<ExampleCodeBlock code={Inverse} />
Set the `disabled` prop of the Checkbox to prevent users from interacting with it.
<ExampleCodeBlock code={Disabled} />
Set the `indeterminate` prop of the Checkbox to `true` to indicate the Checkbox is neither checked
nor unchecked.
A common use case for an indeterminate Checkbox is when the value of a parent Checkbox is dependent
on a number of child Checkboxes. The parent Checkbox is set to the indeterminate state if some (but
not all) of its children are checked.
<ExampleCodeBlock code={Indeterminate} />
Checkbox supports [ref forwarding](https://reactjs.org/docs/forwarding-refs.html). It will forward
`ref` to its underlying `<input type="checkbox">` element.
<ExampleCodeBlock code={RefForwarding} />
Set the `orientation` prop of the Form Field to designate the position of the label relative to the
input component. By default, the orientation will be set to `vertical`.
<ExampleCodeBlock code={LabelPosition} />
Set the `required` prop of a wrapping Form Field to `true` to indicate that the field is required.
Labels for required fields are suffixed by a red asterisk.
<ExampleCodeBlock code={Required} />
Set the `error` prop of the wrapping Form Field to `"caution"` or
`"error"` to set the Checkbox to the Alert or Error state, respectively. You will
also need to set the `hintId` and `hintText` props on the Form Field to meet accessibility
standards. You may wish to omit the `label` prop on the Form Field given that Checkbox already
includes a label.
The `error` prop may be applied directly to the Checkbox with a value of `"caution"`
or `"error"` if Form Field is not being used.
<ExampleCodeBlock code={Caution} />
<ExampleCodeBlock code={Error} />
Checkbox supports custom styling via the `cs` prop. For more information, check our
["How To Customize Styles"](https://workday.github.io/canvas-kit/?path=/docs/styling-guides-customizing-styles--docs).
<SymbolDoc name="Checkbox" fileName="/react/" />
<Specifications file="Checkbox.spec.ts" name="Checkbox" />