Loading component…
Loading component…
A real checkbox with a label and a second line, a some-of-them state for Select all, an error and a card row
To reuse this local React demo, copy all files from the Code tab into the same folder, then import Checkbox from ./checkbox.
import { useState } from "react";
import { Checkbox } from "@/components/ui/checkbox";
export function Topics() {
const all = ["mentions", "approvals", "summary"];
const [picked, setPicked] = useState<string[]>([]);
return (
<fieldset>
<legend>Email me about</legend>
<Checkbox
label="Everything"
checked={picked.length === all.length}
indeterminate={picked.length > 0 && picked.length < all.length}
onChange={() => setPicked(picked.length === all.length ? [] : all)}
/>
{all.map((id) => (
<Checkbox
key={id}
label={id}
checked={picked.includes(id)}
onChange={(e) => setPicked((p) => (e.target.checked ? [...p, id] : p.filter((x) => x !== id)))}
/>
))}
</fieldset>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| label | ReactNode | Shown next to the box; clicking it toggles | |
| description | ReactNode | A quiet second line under the label, linked with aria-describedby | |
| indeterminate | boolean | false | Some of them – a dash instead of the check; set it on a Select all whose list is partly picked |
| error | ReactNode | Marks it invalid (red edge, aria-invalid) and shows the message under it | |
| variant | "plain" \| "card" | "plain" | card: a bordered row that is clickable as a whole; checked, its edge turns dark |
| ...input props | ComponentProps<"input"> | checked, defaultChecked, onChange, name, value, required, disabled, ref – everything goes to the real checkbox |
Long labels wrap; the box stays on the first line
Touch screens get a 20px box, 15px text and a hit area larger than the box
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.