{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-checkbox",
  "type": "registry:ui",
  "title": "react-tw/checkbox.tsx",
  "description": "Carbon `Checkbox` as a React + Tailwind component: a native checkbox (kept for keyboard, forms Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/tw-field",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/checkbox.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/checkbox.tsx",
      "content": "import { createContext, useContext, useId, type ComponentProps, type ReactNode } from 'react';\nimport { Checkbox as CheckboxPrimitive } from '@purpurabog/ui/headless';\nimport { FieldMessageLine, useFieldDisabled, fieldMessage } from './field.tsx';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon `Checkbox` as a React + Tailwind component: a native checkbox (kept for keyboard, forms\n * and screen readers, invisible on top of the drawn 16px box) inside a `<label>`, so the whole row\n * is clickable — the look of `<ui-checkbox>`, Carbon's check mark and indeterminate bar included.\n * `readOnly` keeps the state but blocks toggling; the focus ring shows on `:focus`, as Carbon.\n */\nexport interface CheckboxProps extends Omit<ComponentProps<'input'>, 'type' | 'size'> {\n    /** Text beside the box (`hideLabel` keeps it for screen readers only, e.g. in a table row). */\n    label: ReactNode;\n    hideLabel?: boolean;\n    /** Mixed state (a parent of some checked children): the bar instead of the check. */\n    indeterminate?: boolean;\n    helperText?: ReactNode;\n    invalid?: boolean;\n    invalidText?: ReactNode;\n    warn?: boolean;\n    warnText?: ReactNode;\n}\n\n/** What a CheckboxGroup tells the boxes inside (Checkbox, SelectableTile), as `<ui-checkbox-group>` sets its boxes' group state. */\nexport interface CheckboxGroupState {\n    /** Every box disabled; a box's own `disabled` still counts on its own. */\n    disabled: boolean;\n    /** Every box read-only; a box's own `readOnly` still counts on its own. */\n    readOnly: boolean;\n    /** The group shows its error: every box reddens and reports `aria-invalid` (Lit `data-group-invalid`). */\n    invalid: boolean;\n    /** The group's error line while it shows, added to every box's description (Lit `groupMessage`). */\n    describedBy?: string;\n}\n\nconst CheckboxGroupContext = createContext<CheckboxGroupState | null>(null);\n\n/** Internal: a CheckboxGroup tells the boxes inside. */\nexport const CheckboxGroupProvider = CheckboxGroupContext.Provider;\n\nconst NO_GROUP: CheckboxGroupState = { disabled: false, readOnly: false, invalid: false };\n\n/** The surrounding CheckboxGroup's state; outside one, nothing is set. */\nexport function useCheckboxGroup(): CheckboxGroupState {\n    return useContext(CheckboxGroupContext) ?? NO_GROUP;\n}\n\n/** A box's description: its own message line, then its group's error line. */\nexport const describedByOf = (own: string | undefined, group: CheckboxGroupState) => [own, group.describedBy].filter(Boolean).join(' ') || undefined;\n\nconst box = [\n    // the checkbox settings (--ui-checkbox-border / -checked / -mark): Carbon draws in primary ink, a design can use its brand colour\n    'relative mt-px box-border block size-4 shrink-0 rounded-xs border border-solid border-[color:var(--ui-checkbox-border,var(--ui-ink))] bg-transparent text-[color:var(--ui-checkbox-mark,var(--ui-icon-inverse))]',\n    // Carbon's check: a 9×5 L of 1.5px borders rotated −45° about its bottom-right corner\n    \"after:absolute after:start-[3px] after:top-[-0.5px] after:box-border after:h-[5px] after:w-[9px] after:origin-bottom-right after:border-0 after:border-b-[1.5px] after:border-l-[1.5px] after:border-solid after:border-current after:content-['']\",\n    'after:[transform:scale(0)_rotate(-45deg)]',\n    'peer-checked:border-[color:var(--ui-checkbox-checked,var(--ui-ink))] peer-checked:bg-[color:var(--ui-checkbox-checked,var(--ui-ink))] peer-checked:after:[transform:scale(1)_rotate(-45deg)]',\n    // indeterminate: an 8px bar, 2px thick (rows 8–10 of the box, 1px below centre as Carbon)\n    'peer-indeterminate:border-[color:var(--ui-checkbox-checked,var(--ui-ink))] peer-indeterminate:bg-[color:var(--ui-checkbox-checked,var(--ui-ink))] peer-indeterminate:after:top-1 peer-indeterminate:after:w-2 peer-indeterminate:after:border-b-2 peer-indeterminate:after:border-l-0 peer-indeterminate:after:[transform:scale(1)_rotate(0deg)]',\n    // Carbon checkbox:focus (not :focus-visible), so a click shows the ring too\n    'peer-focus:outline-[length:var(--ui-focus-width,2px)] peer-focus:outline-offset-1 peer-focus:outline-focus peer-[:focus:not(:focus-visible)]:outline-[color:var(--ui-pointer-focus,var(--ui-focus))]',\n    'forced-colors:border-[CanvasText] forced-colors:peer-checked:border-[CanvasText] forced-colors:peer-indeterminate:border-[CanvasText] forced-colors:[forced-color-adjust:none] forced-colors:peer-checked:bg-[Highlight] forced-colors:peer-checked:text-[HighlightText] forced-colors:peer-indeterminate:bg-[Highlight] forced-colors:peer-indeterminate:text-[HighlightText]',\n];\n\nexport function Checkbox({ label, hideLabel, indeterminate = false, helperText, invalid, invalidText, warn, warnText, disabled: ownDisabled, readOnly: ownReadOnly, id, className, ...rest }: Readonly<CheckboxProps>) {\n    const group = useCheckboxGroup();\n    const disabled = useFieldDisabled(ownDisabled) || group.disabled;\n    const readOnly = !!ownReadOnly || group.readOnly;\n    const autoId = useId();\n    const inputId = id ?? autoId;\n    const interactive = !disabled && !readOnly;\n    const { message, content } = fieldMessage({ interactive, invalid, invalidText, warn, warnText, helperText });\n    // its own error, or its group's (Lit data-group-invalid: disabled / read-only recolour the 2px border)\n    const showError = message?.kind === 'error' || group.invalid;\n    return (\n        <div className={cn('block font-sans', className)}>\n            <label\n                className={cn(\n                    'relative box-border inline-flex min-h-6 cursor-pointer items-start gap-[14px] py-1 type-body-sm text-ink',\n                    disabled && 'cursor-not-allowed text-ink-disabled',\n                    readOnly && !disabled && 'cursor-default',\n                )}\n            >\n                <CheckboxPrimitive.Root\n                    {...rest}\n                    id={inputId}\n                    indeterminate={indeterminate}\n                    disabled={disabled}\n                    readOnly={readOnly}\n                    invalid={showError}\n                    aria-describedby={describedByOf(message ? `${inputId}-message` : undefined, group)}\n                    className=\"peer absolute start-0 top-1 z-1 m-0 size-4 cursor-[inherit] opacity-0\"\n                />\n                <span\n                    aria-hidden=\"true\"\n                    className={cn(\n                        box,\n                        showError && 'border-2 border-error peer-checked:border-error peer-indeterminate:border-error',\n                        disabled && 'border-ink-disabled peer-checked:border-ink-disabled peer-indeterminate:border-ink-disabled peer-checked:bg-ink-disabled peer-indeterminate:bg-ink-disabled',\n                        readOnly && !disabled && 'border-ink-subtle peer-checked:border-ink-subtle peer-indeterminate:border-ink-subtle peer-checked:bg-ink-muted peer-indeterminate:bg-ink-muted',\n                    )}\n                />\n                <span className={hideLabel ? 'sr-only' : undefined}>{label}</span>\n            </label>\n            <FieldMessageLine id={`${inputId}-message`} message={message} content={content} disabled={disabled} withIcon className=\"ps-6\" />\n        </div>\n    );\n}\n\n/** Carbon `CheckboxSkeleton`: an empty 16px box and a 100×16 label bar. Hidden from assistive tech. */\nexport function CheckboxSkeleton({ className, ...rest }: Readonly<ComponentProps<'div'>>) {\n    return (\n        <div {...rest} aria-hidden=\"true\" className={cn('relative block h-5', className)}>\n            {/* where Checkbox draws its box: 3px in, 3px down */}\n            <span className=\"absolute start-[3px] top-[3px] box-border block size-4 rounded-[2px] border border-solid border-icon-primary\" />\n            <span className=\"skeleton absolute start-[26px] top-0.5 block h-4 w-[100px]\" />\n        </div>\n    );\n}\n"
    }
  ]
}
