Skip to Content

Checkbox

A control that allows the user to toggle between checked and not checked.

import { Checkbox } from "@dapplelight/signet-ui/components/checkbox"

export function Demo() {
  return (
    <div className="flex items-center gap-2">
      <Checkbox id="terms" />
      <label htmlFor="terms" className="text-sm">Accept terms and conditions</label>
    </div>
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import { Checkbox } from "@dapplelight/signet-ui/components/checkbox"

<Checkbox />

Examples

Checked

import { Checkbox } from "@dapplelight/signet-ui/components/checkbox"

<Checkbox id="receipts" defaultChecked />
<label htmlFor="receipts">Email me receipts</label>

Disabled

import { Checkbox } from "@dapplelight/signet-ui/components/checkbox"

<Checkbox id="sso" disabled />
<label htmlFor="sso">Enforce SSO (Enterprise plan)</label>

Controlled

1 selected

import * as React from "react"
import { Checkbox } from "@dapplelight/signet-ui/components/checkbox"
import { invoices, toggle } from "./invoices"

const [selected, setSelected] = React.useState<string[]>(["INV-2041"])

{invoices.map((id) => (
  <div key={id} className="flex items-center gap-2">
    <Checkbox
      id={id}
      checked={selected.includes(id)}
      onCheckedChange={(v) => toggle(id, v === true)}
    />
    <label htmlFor={id}>{id}</label>
  </div>
))}

API Reference

Checkbox

PropTypeDefaultDescription
checkedboolean | "indeterminate"-Controlled state.
defaultCheckedboolean | "indeterminate"-Initial state when uncontrolled.
onCheckedChange(checked: boolean | "indeterminate") => void-Runs when the state changes.
disabledbooleanfalsePrevents interaction.
requiredbooleanfalseMarks it required in a form.
namestring-Form field name.
valuestring"on"Form value when checked.
classNamestring-Merged last.

Built on a Radix checkbox, so it takes every button prop. Pair it with a label using id and htmlFor.