Dokumentation (english)
Components: Shadcn UI

Checkbox

Understand the design system and contribute to it

Component preview

The live preview for UI components is handled by components/atoms/codedocs/ComponentPreview.tsx. Use it directly inside MDX whenever you want a playground-style embed. Provide componentProps to set default values and propOptions to surface toggle-able props next to the preview.

Preview

Available props

Toggle to update the preview

Unchecked

checked: false

Disabled

disabled: true

Invalid

aria-invalid: true

Prop reference

Auto-generated from the component source

Checkbox

  • className

React.ComponentProps<typeof CheckboxPrimitive.Root>

Code
// owner: Sona
"use client";

import * as React from "react";

import { Checkbox } from "@/components/ui/checkbox";

const permissions = ["Read", "Create", "Update", "Delete"];

export default function CheckboxExample() {
  const [checked, setChecked] = React.useState(
    () => new Set(["Read", "Update"])
  );

  return (
    <div className="space-y-3">
      {permissions.map((permission) => (
        <label key={permission} className="flex items-center gap-3 text-sm">
          <Checkbox
            checked={checked.has(permission)}
            onCheckedChange={(value) => {
              setChecked((prev) => {
                const next = new Set(prev);
                if (value) {
                  next.add(permission);
                } else {
                  next.delete(permission);
                }
                return next;
              });
            }}
          />
          <span>{permission} access</span>
        </label>
      ))}
    </div>
  );
}

On this page


Command Palette

Search for a command to run...

Schnellzugriffe
STRG + KSuche
STRG + DNachtmodus / Tagmodus
STRG + LSprache ändern

Software-Details
Kompiliert vor 15 Tagen
Release: v4.0.0-production
Buildnummer: master@6fbd7b5
Historie: 13 Items