Checkbox
Picked or not: an item in a list, or an option that waits for Save. For a setting that applies at once, use a Switch.
tsx
import { Checkbox } from '@adecore/ui';tsx
import { Checkbox } from '@adecore/ui';
import { useState } from 'react';
const SCRIPTS = ['dev', 'build', 'check', 'preview'];
export default function CheckboxDemo() {
const [picked, setPicked] = useState<string[]>(['dev', 'build']);
const all = picked.length === SCRIPTS.length;
const toggle = (script: string, checked: boolean) => {
setPicked((current) => (checked ? [...current, script] : current.filter((candidate) => candidate !== script)));
};
return (
<div className="flex w-72 flex-col gap-2 text-sm text-text">
<label className="flex items-center gap-2 font-medium">
<Checkbox
label="Every script"
checked={all}
indeterminate={!all && picked.length > 0}
onCheckedChange={(checked) => setPicked(checked ? SCRIPTS : [])}
/>
Every script
</label>
{SCRIPTS.map((script) => (
<label key={script} className="flex items-center gap-2 pl-6">
<Checkbox label={script} checked={picked.includes(script)} onCheckedChange={(checked) => toggle(script, checked)} />
{script}
</label>
))}
<label className="flex items-center gap-2 pl-6 text-text-muted">
<Checkbox label="test" checked={false} onCheckedChange={() => {}} disabled />
test
</label>
</div>
);
}label is the accessible name. Wrap the box and its visible text in one <label> so the text toggles it too. Space toggles it.
indeterminate draws a dash, for a select-all box while some rows are picked. A press still reports the opposite of checked, so with checked={false} it picks every row.
Props
| Prop | Type | Default | |
|---|---|---|---|
checked | boolean | Required. | |
onCheckedChange | (checked: boolean) => void | Required. | |
label | string | Required. | |
indeterminate | boolean | false | Draws a dash. |
disabled | boolean | ||
className | string | ||
ref | Ref<HTMLButtonElement> |
CheckboxProps is an exported type.