{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkbox",
  "type": "registry:ui",
  "title": "Checkbox",
  "description": "A labelled checkbox with hint and error text, a checked, unchecked or indeterminate state, built on Radix Checkbox.",
  "dependencies": [
    "lucide-react@^1.49.0"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/checkbox.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/checkbox.tsx",
      "content": "import { forwardRef, useId, useState, type ButtonHTMLAttributes, type ReactNode } from 'react';\nimport { Check, Minus } from 'lucide-react';\nimport { cn } from '../lib/utils';\n\n// Own implementation (not Radix): Radix Checkbox writes a hidden input with an inline style attribute into server-rendered HTML.\nexport interface CheckboxProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'onChange' | 'role' | 'value'> {\n  /** Visible label. Without one, pass aria-label. */\n  label?: ReactNode;\n  hint?: ReactNode;\n  invalid?: boolean;\n  checked?: boolean | 'indeterminate';\n  defaultChecked?: boolean;\n  onCheckedChange?: (checked: boolean) => void;\n  /** With a name, the checkbox posts `value` (default \"on\") when checked. */\n  name?: string;\n  value?: string;\n  required?: boolean;\n}\n\n/** A checkbox with its label inside a 44 px row. Controlled or not; `checked=\"indeterminate\"` shows a dash for \"some\". */\nexport const Checkbox = forwardRef<HTMLButtonElement, CheckboxProps>(function Checkbox(\n  { label, hint, invalid, className, id, checked, defaultChecked = false, onCheckedChange, name, value = 'on', required, form, disabled, onClick, ...rest }, ref) {\n  const auto = useId();\n  const cid = id ?? auto;\n  const [inner, setInner] = useState(defaultChecked);\n  const state = checked ?? inner;\n  const mixed = state === 'indeterminate';\n  const on = state === true;\n  const dataState = mixed ? 'indeterminate' : on ? 'checked' : 'unchecked';\n  const box = (\n    <>\n      <button\n        ref={ref}\n        id={cid}\n        type=\"button\"\n        role=\"checkbox\"\n        aria-checked={mixed ? 'mixed' : on}\n        aria-required={required || undefined}\n        aria-invalid={invalid || undefined}\n        aria-describedby={hint ? `${cid}-h` : undefined}\n        data-state={dataState}\n        data-disabled={disabled ? '' : undefined}\n        disabled={disabled}\n        form={form}\n        onClick={(e) => {\n          onClick?.(e);\n          if (e.defaultPrevented) return;\n          const next = mixed ? true : !on;\n          if (checked === undefined) setInner(next);\n          onCheckedChange?.(next);\n        }}\n        className={cn(\n          'peer relative inline-flex size-5 shrink-0 items-center justify-center rounded-kh-sm border border-kh-line-strong bg-kh-surface text-kh-on-ink shadow-kh-1',\n          'transition-[background-color,border-color] duration-(--kh-dur) hover:border-kh-muted',\n          'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus)',\n          'data-[state=checked]:border-kh-ink data-[state=checked]:bg-kh-ink data-[state=indeterminate]:border-kh-ink data-[state=indeterminate]:bg-kh-ink',\n          'disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-kh-danger',\n          // Beside a label the box sits on the label's first line, not the middle of a wrapped one.\n          label ? 'mt-[calc((1lh-1.25rem)/2)]' : 'after:absolute after:-inset-3 after:content-[\"\"]',\n          className,\n        )}\n        {...rest}\n      >\n        {mixed ? <Minus aria-hidden className=\"size-3.5\" /> : on ? <Check aria-hidden className=\"size-3.5\" /> : null}\n      </button>\n      {name && on && !disabled && <input type=\"hidden\" name={name} value={value} form={form} />}\n    </>\n  );\n  if (!label) return box;\n  return (\n    <div className=\"flex flex-col gap-1\">\n      <label htmlFor={cid} className=\"flex min-h-11 cursor-pointer items-start gap-3 py-[max(0px,calc((2.75rem-1lh)/2))] text-kh-body text-kh-ink has-[:disabled]:cursor-not-allowed has-[:disabled]:text-kh-muted\">\n        {box}\n        <span>{label}</span>\n      </label>\n      {hint && <p id={`${cid}-h`} className={cn('pl-8 text-kh-small', invalid ? 'text-kh-danger' : 'text-kh-muted')}>{hint}</p>}\n    </div>\n  );\n});\n"
    }
  ]
}
