Documentation / Forms
Checkbox
The checkbox: a native <input type="checkbox">, visually replaced by a styled box, with a label, a description and an error message linked through aria-describedby. Three sizes, three variants, three shapes, and an indeterminate state for the “select all” box.
Controlled (checked + onChange) or not (defaultChecked). Note: onChange receives the boolean first, then the native event.
For a multiple-choice list, CheckboxGroup holds the array of checked values and shares it with its CheckboxGroupItems through context; it also passes down size and disabled. Client components ("use client").
Examples
Basic usage
Uncontrolled: defaultChecked sets the initial state, description adds detail to the label.
import { Checkbox } from "@synertech/ui";
export function Basic() {
return (
<Checkbox
label="Recevoir la newsletter"
description="Un e-mail par mois, désinscription en un clic."
defaultChecked
/>
);
}Controlled state and error
onChange hands back the boolean; a string passed to error is shown under the box.
import { useState } from "react";
import { Checkbox } from "@synertech/ui";
export function Controlled() {
const [accepted, setAccepted] = useState(false);
return (
<Checkbox
label="J’accepte les conditions générales de vente"
required
checked={accepted}
onChange={(checked) => setAccepted(checked)}
error={accepted ? false : "Vous devez accepter les CGV pour continuer."}
/>
);
}Sizes, variants and shapes
size, variant and shape combine; checkedColor takes a Tailwind background class.
import { Checkbox } from "@synertech/ui";
export function Appearance() {
return (
<div className="flex flex-col gap-3">
<Checkbox size="sm" label="Petite, par défaut" defaultChecked />
<Checkbox
size="md"
variant="filled"
shape="rounded"
label="Moyenne, remplie, arrondie"
defaultChecked
/>
<Checkbox
size="lg"
variant="outlined"
shape="circle"
label="Grande, contour, ronde"
defaultChecked
/>
<Checkbox checkedColor="bg-emerald-600" label="Couleur personnalisée" defaultChecked />
<Checkbox label="Désactivée" disabled defaultChecked />
</div>
);
}Select all
indeterminate shows a dash when only some of the boxes are checked.
import { useState } from "react";
import { Checkbox, CheckboxGroup, CheckboxGroupItem } from "@synertech/ui";
const permissions = [
{ value: "read", label: "Lecture" },
{ value: "write", label: "Écriture" },
{ value: "delete", label: "Suppression" },
];
export function SelectAll() {
const [selected, setSelected] = useState<string[]>(["read"]);
const all = selected.length === permissions.length;
return (
<div className="flex flex-col gap-2">
<Checkbox
label="Toutes les permissions"
checked={all}
indeterminate={selected.length > 0 && !all}
onChange={(checked) => setSelected(checked ? permissions.map((p) => p.value) : [])}
/>
<CheckboxGroup value={selected} onChange={setSelected} className="ml-6">
{permissions.map((p) => (
<CheckboxGroupItem key={p.value} value={p.value} label={p.label} />
))}
</CheckboxGroup>
</div>
);
}Checkbox group
CheckboxGroup manages the array of values; orientation and spacing set the layout.
import { useState } from "react";
import { CheckboxGroup, CheckboxGroupItem } from "@synertech/ui";
export function Group() {
const [days, setDays] = useState<string[]>(["lun", "mer"]);
return (
<CheckboxGroup
label="Jours de livraison"
description="Choisissez au moins un jour."
orientation="horizontal"
value={days}
onChange={setDays}
error={days.length === 0 ? "Sélectionnez au moins un jour." : false}
>
<CheckboxGroupItem value="lun" label="Lundi" />
<CheckboxGroupItem value="mar" label="Mardi" />
<CheckboxGroupItem value="mer" label="Mercredi" />
<CheckboxGroupItem value="jeu" label="Jeudi" />
<CheckboxGroupItem value="ven" label="Vendredi" disabled />
</CheckboxGroup>
);
}Uncontrolled group
defaultValue is enough when only the result matters: onChange passes it on at every click.
import { CheckboxGroup, CheckboxGroupItem } from "@synertech/ui";
export function UncontrolledGroup() {
return (
<CheckboxGroup
label="Notifications"
size="sm"
defaultValue={["email"]}
onChange={(values) => console.log("Canaux :", values)}
>
<CheckboxGroupItem value="email" label="E-mail" />
<CheckboxGroupItem value="sms" label="SMS" />
<CheckboxGroupItem
value="push"
label="Notification push"
description="Sur l’application mobile"
/>
</CheckboxGroup>
);
}API reference
Components
import { Checkbox } from "@synertech/ui";Props — CheckboxProps
| Prop | Type | Default | Description |
|---|---|---|---|
animation |
boolean |
true |
|
borderColor |
string |
"border-gray-300 dark:border-gray-600" |
|
checked |
boolean |
— | |
checkedColor |
string |
"bg-synertech-primary-600" |
|
checkmarkColor |
string |
— | Classes of the check mark. Left out, it is the colour the brand is written in ( |
className |
string |
— | Classes of the box. The root takes |
containerClassName |
string |
— | |
defaultChecked |
boolean |
false |
|
description |
string |
— | Written under the label, and describes the box. |
disabled |
boolean |
false |
|
error |
boolean | string |
— |
|
errorColor |
string |
"text-red-600 dark:text-red-400" |
|
focusRingColor |
string |
— | Classes of the focus ring, written with their variant: |
hoverColor |
string |
— | Classes of the box under the pointer, written with their variant: |
icon |
ReactNode |
— | |
indeterminate |
boolean |
false |
Draws a dash, the box neither checked nor not. Kept on the input as long as the prop says so: a click, which clears it in the browser, does not clear it while the dash is still drawn. |
label |
ReactNode |
— | |
labelColor |
string |
— | |
labelPosition |
"left" | "right" |
"right" |
|
onChange |
(checked: boolean, event: ChangeEvent<HTMLInputElement>) => void |
— | |
readOnly |
boolean |
false |
|
required |
boolean |
false |
|
shape |
"square" | "rounded" | "circle" |
"square" |
|
showFocusRing |
boolean |
true |
|
size |
"sm" | "md" | "lg" |
"md" |
|
uncheckedColor |
string |
"bg-white dark:bg-gray-800" |
|
variant |
"default" | "filled" | "outlined" |
"default" |
+ 301 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).
import { CheckboxGroup } from "@synertech/ui";Props — CheckboxGroupProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
className |
string |
— | |
defaultValue |
string[] |
[] |
|
description |
string |
— | Written under the label, and describes the group. |
disabled |
boolean |
false |
|
error |
boolean | string |
— |
|
label |
ReactNode |
— | Names the group of boxes ( |
labelClassName |
string |
— | |
name |
string |
— | The name the checked items are submitted under, each with its own |
onChange |
(values: string[]) => void |
— | |
orientation |
"horizontal" | "vertical" |
"vertical" |
|
required |
boolean |
false |
|
size |
"sm" | "md" | "lg" |
"md" |
|
spacing |
"sm" | "md" | "lg" |
"md" |
|
value |
string[] |
— |
+ 275 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).
import { CheckboxGroupItem } from "@synertech/ui";Props — CheckboxGroupItemProps
| Prop | Type | Default | Description |
|---|---|---|---|
value• |
string |
— | |
animation |
boolean |
— | |
borderColor |
string |
— | |
checkedColor |
string |
— | |
checkmarkColor |
string |
— | Classes of the check mark. Left out, it is the colour the brand is written in ( |
className |
string |
— | Classes of the box. The root takes |
containerClassName |
string |
— | |
defaultChecked |
boolean |
— | |
description |
string |
— | Written under the label, and describes the box. |
disabled |
boolean |
— | |
error |
boolean | string |
— |
|
errorColor |
string |
— | |
focusRingColor |
string |
— | Classes of the focus ring, written with their variant: |
hoverColor |
string |
— | Classes of the box under the pointer, written with their variant: |
icon |
ReactNode |
— | |
indeterminate |
boolean |
— | Draws a dash, the box neither checked nor not. Kept on the input as long as the prop says so: a click, which clears it in the browser, does not clear it while the dash is still drawn. |
label |
ReactNode |
— | |
labelColor |
string |
— | |
labelPosition |
"left" | "right" |
— | |
readOnly |
boolean |
— | |
required |
boolean |
— | |
shape |
"square" | "rounded" | "circle" |
— | |
showFocusRing |
boolean |
— | |
size |
"sm" | "md" | "lg" |
— | |
uncheckedColor |
string |
— | |
variant |
"default" | "filled" | "outlined" |
— |
+ 299 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).