Checkbox
A checkbox that represents a selected state. Supports both single checkboxes and checkbox groups.
View in Storybook (opens in a new tab)
Installation
import { Checkbox } from "@ginga-ui/core";Basic usage
An example of a single checkbox.
checkbox.tsx
import { Checkbox } from "@ginga-ui/core";
export function BasicExample() {
return <Checkbox label="I agree to the terms of service" />;
}Selected
A checkbox that is selected initially.
checkbox.tsx
import { Checkbox } from "@ginga-ui/core";
export function SelectedExample() {
return <Checkbox label="Selected by default" defaultSelected />;
}Disabled
An example of a disabled checkbox.
checkbox.tsx
checkbox.module.css
import { Checkbox } from "@ginga-ui/core";
import styles from "./checkbox.module.css";
export function DisabledExample() {
return (
<div className={styles.disabledStack}>
<Checkbox label="Disabled checkbox" disabled />
<Checkbox label="Disabled and selected" disabled selected />
</div>
);
}Checkbox group
An example of grouping multiple checkboxes.
checkbox.tsx
import { Checkbox, CheckboxGroup } from "@ginga-ui/core";
export function CheckboxGroupExample() {
return (
<CheckboxGroup>
<Checkbox value="option1" label="Option 1" />
<Checkbox value="option2" label="Option 2" />
<Checkbox value="option3" label="Option 3" />
</CheckboxGroup>
);
}Props
Checkbox
| Name | Type | Default | Description |
|---|---|---|---|
label | ReactNode | - | Label of the checkbox. children takes precedence when given. |
selected | boolean | - | Whether the checkbox is checked (controlled). Use it with onChange. |
indeterminate | boolean | false | Shows the indeterminate state, used when only some of the children are checked. |
disabled | boolean | false | Disables the checkbox. |
required | boolean | false | Requires the checkbox to be checked. |
readOnly | boolean | false | Prevents the user from changing the value. |
invalid | boolean | false | Shows the checkbox as invalid. |
icon | ReactNode | - | Icon shown when checked. |
indeterminateIcon | ReactNode | - | Icon shown in the indeterminate state. |
Also accepts the props of React Aria's Checkbox (opens in a new tab).
CheckboxGroup
| Name | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Disables every checkbox in the group. |
required | boolean | false | Requires at least one checkbox to be checked. |
readOnly | boolean | false | Prevents the user from changing the selection. |
invalid | boolean | false | Shows the group as invalid. |
Also accepts the props of React Aria's CheckboxGroup (opens in a new tab).