Checkbox
Installation
yarn add @spark-web/checkbox
Checkboxes are used to toggle between checked and unchecked states — usually in
a form. If only one option from a list is allowed to be enable, consider using a
RadioButton
instead.
Examples
Controlled
Checkboxes can be both controlled and uncontrolled. To control a checkbox
provide the checked
state with a value you control, as well as an onChange
function to set the new value when the checkbox is toggled.
Size
Checkboxes are available in two sizes: small
and medium
.
Message and tone
The message
is used to communicate the status of a field, such as an error
message. This will be announced on focus and can be combined with a tone
to
illustrate intent. The supported tones are: critical
, positive
and
neutral
.
Props
Checkbox
Prop | Type | Description |
---|---|---|
checked? | boolean | When true, the checkbox will be checked. |
children? | ReactNode: string | number | false | true | {} | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | The checkbox label content. |
data? | DataAttributeMap | Sets data attributes on the component. |
disabled? | boolean | When true, the checkbox will be disabled. Default: |
message? | string | Provide a message, informing the user about changes in state. |
size? | CheckboxSize: "small" | "medium" | The size of the checkbox. Default: |
tone? | "critical" | "positive" | "neutral" | Provide a tone to influence elements of the field, and its input. Default: |
value? | string | The value of the checkbox. |
The Checkbox
component also extends InputHTMLAttributes
props and are not
listed here.
CheckboxPrimitive
Prop | Type | Description |
---|---|---|
checked? | boolean | When true, the checkbox will be checked. |
data? | DataAttributeMap | Sets data attributes on the component. |
disabled? | boolean | When true, the checkbox will be disabled. |
size? | CheckboxSize: "small" | "medium" | The size of the checkbox. Default: |
value? | string | The value of the checkbox. |
The CheckboxPrimitive
component also extends InputHTMLAttributes
props and
are not listed here.