Checkbox

Controlled checkbox with optional label and description.

With description

import { useState } from 'react'
import { Checkbox } from '@canarist/ui'

function Example() {
  const [checked, setChecked] = useState(false)
  return (
    <Checkbox
      label="Enable notifications"
      description="Receive email alerts for matching events."
      checked={checked}
      onChange={(e) => setChecked(e.target.checked)}
    />
  )
}

Group

function NotificationPrefs() {
  const [values, setValues] = useState({ email: true, sms: false })
  return (
    <>
      <Checkbox
        label="Email"
        checked={values.email}
        onChange={(e) => setValues((v) => ({ ...v, email: e.target.checked }))}
      />
      <Checkbox
        label="SMS"
        checked={values.sms}
        onChange={(e) => setValues((v) => ({ ...v, sms: e.target.checked }))}
      />
    </>
  )
}

Disabled

<Checkbox label="Disabled option" checked disabled />

Reference

PropTypeDefaultDescription
labelstringVisible label rendered next to the checkbox.
descriptionstringSecondary text below the label.
checkedbooleanControlled checked state.
onChangeReact.ChangeEventHandler<HTMLInputElement>Called when the checkbox value changes.
disabledbooleanDisable the checkbox.