Synertech Web/ui v0.57.5 Site Storybook

Documentation / Forms

Checkbox

Client@synertech/uiOpen in Storybook

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.

Open in a tab
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.

Open in a tab
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.

Open in a tab
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.

Open in a tab
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.

Open in a tab
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.

Open in a tab
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

Checkbox

ComponentClient
import { Checkbox } from "@synertech/ui";

Props — CheckboxProps

PropTypeDefaultDescription
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 (text-synertech-on-primary) on the default fill, and text-white on a fill passed as checkedColor. The outlined variant has no fill: its mark is drawn in the colour of its outline.

className string —

Classes of the box. The root takes containerClassName.

containerClassName string —
defaultChecked boolean false
description string —

Written under the label, and describes the box.

disabled boolean false
error boolean | string —

true marks the box invalid; a message also does, and is written under it. The box is then aria-invalid and described by the message. false and "" are no error.

errorColor string "text-red-600 dark:text-red-400"
focusRingColor string —

Classes of the focus ring, written with their variant: peer-focus-visible:ring-red-500 (the input is the peer of the box). Defaults to the brand's ring.

hoverColor string —

Classes of the box under the pointer, written with their variant: hover:bg-gray-100. Written that way, the application's Tailwind sees them in its own sources and generates them; a class handed without its variant is given hover:, and exists only if something else wrote it.

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…).

CheckboxGroup

ComponentClient
import { CheckboxGroup } from "@synertech/ui";

Props — CheckboxGroupProps

PropTypeDefaultDescription
children• ReactNode —
className string —
defaultValue string[] []
description string —

Written under the label, and describes the group.

disabled boolean false
error boolean | string —

true marks the group invalid; a message also does, and is written under the boxes. The group is then described by the message. false and "" are no error.

label ReactNode —

Names the group of boxes (aria-labelledby).

labelClassName string —
name string —

The name the checked items are submitted under, each with its own value: a form gets one entry per checked item. The name of an item wins over it.

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…).

CheckboxGroupItem

ComponentClient
import { CheckboxGroupItem } from "@synertech/ui";

Props — CheckboxGroupItemProps

PropTypeDefaultDescription
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 (text-synertech-on-primary) on the default fill, and text-white on a fill passed as checkedColor. The outlined variant has no fill: its mark is drawn in the colour of its outline.

className string —

Classes of the box. The root takes containerClassName.

containerClassName string —
defaultChecked boolean —
description string —

Written under the label, and describes the box.

disabled boolean —
error boolean | string —

true marks the box invalid; a message also does, and is written under it. The box is then aria-invalid and described by the message. false and "" are no error.

errorColor string —
focusRingColor string —

Classes of the focus ring, written with their variant: peer-focus-visible:ring-red-500 (the input is the peer of the box). Defaults to the brand's ring.

hoverColor string —

Classes of the box under the pointer, written with their variant: hover:bg-gray-100. Written that way, the application's Tailwind sees them in its own sources and generates them; a class handed without its variant is given hover:, and exists only if something else wrote it.

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…).