Checkbox

A box that turns an option on or off, filled with the action colour when checked and named by the Label tied to it through htmlFor.

import { Checkbox } from "@produkto/ui/Checkbox";
import { Label } from "@produkto/ui/Label";

const Example = () => (
  <div className="flex items-center gap-2">
    <Checkbox defaultChecked id="checkbox-preview" />
    <Label htmlFor="checkbox-preview">Label</Label>
  </div>
);

export default Example;

Usage

import { Checkbox } from "@produkto/ui/Checkbox";
<Checkbox />

Examples

Sizes

size sets the box and the check it draws: sm 14px, base 16px (the default) or lg 20px.

import { Checkbox, type CheckboxSize } from "@produkto/ui/Checkbox";
import { Label } from "@produkto/ui/Label";

const variants: { size: CheckboxSize; label: string }[] = [
  { size: "sm", label: "Small" },
  { size: "base", label: "Base" },
  { size: "lg", label: "Large" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex items-center gap-2" key={variant.size}>
        <Checkbox id={`checkbox-size-${variant.size}`} size={variant.size} />
        <Label htmlFor={`checkbox-size-${variant.size}`}>{variant.label}</Label>
      </div>
    ))}
  </div>
);

export default Example;

Border radius

borderRadius sets the box's corners on the kit's one scale: none, xs 4px (the default), sm 6px, base 8px, lg 12px, xl 16px, or full to make it round, which the 16px box already is from base up.

import {
  Checkbox,
  type CheckboxBorderRadius,
} from "@produkto/ui/Checkbox";
import { Label } from "@produkto/ui/Label";

const variants: { borderRadius: CheckboxBorderRadius; label: string }[] = [
  { borderRadius: "none", label: "None" },
  { borderRadius: "xs", label: "xs" },
  { borderRadius: "sm", label: "sm" },
  { borderRadius: "base", label: "base" },
  { borderRadius: "lg", label: "lg" },
  { borderRadius: "xl", label: "xl" },
  { borderRadius: "full", label: "full" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex items-center gap-2" key={variant.borderRadius}>
        <Checkbox
          id={`checkbox-radius-${variant.borderRadius}`}
          borderRadius={variant.borderRadius}
        />
        <Label htmlFor={`checkbox-radius-${variant.borderRadius}`}>
          {variant.label}
        </Label>
      </div>
    ))}
  </div>
);

export default Example;

Indeterminate

checked="indeterminate" draws a dash for a box that is only partly on, as one over a list of which only some are checked, beside a box as it is by default, unchecked.

import { Checkbox } from "@produkto/ui/Checkbox";
import { Label } from "@produkto/ui/Label";

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex items-center gap-2">
      <Checkbox id="checkbox-unchecked" />
      <Label htmlFor="checkbox-unchecked">Label</Label>
    </div>
    <div className="flex items-center gap-2">
      <Checkbox defaultChecked="indeterminate" id="checkbox-indeterminate" />
      <Label htmlFor="checkbox-indeterminate">Label</Label>
    </div>
  </div>
);

export default Example;

Disabled

disabled dims the box and its label and ignores clicks, beside one as it is by default.

import { Checkbox } from "@produkto/ui/Checkbox";
import { Label } from "@produkto/ui/Label";

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex items-center gap-2">
      <Checkbox id="checkbox-enabled" />
      <Label htmlFor="checkbox-enabled">Label</Label>
    </div>
    <div className="flex items-center gap-2">
      <Checkbox disabled id="checkbox-disabled" />
      <Label htmlFor="checkbox-disabled">Label</Label>
    </div>
  </div>
);

export default Example;

Invalid

error writes what is wrong under the box and its label, rings the box in the destructive colour and describes it to screen readers, beside one without an error.

import { Checkbox } from "@produkto/ui/Checkbox";
import { Label } from "@produkto/ui/Label";

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex items-center gap-2">
      <Checkbox id="checkbox-valid" />
      <Label htmlFor="checkbox-valid">Label</Label>
    </div>
    <div className="flex flex-wrap items-center gap-2">
      <Checkbox error="Description" id="checkbox-error" />
      <Label htmlFor="checkbox-error">Label</Label>
    </div>
  </div>
);

export default Example;

API Reference

Checkbox

CheckboxProps · components/Checkbox/Checkbox.types.ts
PropTypeDefault
sizeCheckboxSize"sm" | "base" | "lg""base"
borderRadiusCheckboxBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl" | "full""xs"
errorReactNode-

It also takes the props of Radix Checkbox.Root.