{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkbox",
  "title": "Checkbox & Radio",
  "description": "Checkbox and RadioGroup on real inputs with default, filled, outline, circle, neo and whole-card variants, draw, pop and bounce animations, tones, sizes, shadows, indeterminate, invalid and descriptions.",
  "dependencies": [],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/sounds.json"
  ],
  "files": [
    {
      "path": "registry/components/core/checkbox.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"@/lib/utils\"\nimport type { SoundName } from \"@/lib/goodui-sounds\"\nimport { GooduiTokens } from \"@/lib/goodui-motion\"\n\n/*\n * Checkbox and RadioGroup/Radio sharing the same independent layers:\n *   variant    default, filled, outline, circle, neo, card (the whole card is the hit area)\n *   tone       which color when checked     animation  none, draw (stroke), pop, bounce\n *   shadow     none, sm, glow               size       sm, md, lg\n * plus indeterminate, label + description on either side, invalid and extra card content.\n * Both render real <input> elements, so forms, labels and keyboard (Space, arrows in a group) just work.\n */\n\nexport type CheckboxVariant = \"default\" | \"filled\" | \"outline\" | \"circle\" | \"neo\" | \"card\"\nexport type CheckboxTone = \"primary\" | \"neutral\" | \"success\" | \"warning\" | \"danger\" | \"info\"\nexport type CheckboxAnimation = \"none\" | \"draw\" | \"pop\" | \"bounce\"\nexport type CheckboxShadow = \"none\" | \"sm\" | \"glow\"\nexport type CheckboxSize = \"sm\" | \"md\" | \"lg\"\n\ntype Layers = {\n  /** Box style: default, filled, outline (tinted when checked), circle, neo, or card (the whole card is the hit area). */\n  variant?: CheckboxVariant\n  /** Color when checked. */\n  tone?: CheckboxTone\n  /** How the mark appears: draw (stroke, default), pop, bounce or none. */\n  animation?: CheckboxAnimation\n  /** Box shadow; glow only shows when checked. */\n  shadow?: CheckboxShadow\n  size?: CheckboxSize\n}\n\ntype Text = {\n  /** Visible label, linked with aria-labelledby. */\n  label?: React.ReactNode\n  /** Muted helper text under the label, linked with aria-describedby. */\n  description?: React.ReactNode\n  /** Which side of the box the text sits on. \"left\" spreads the row (text start, box end). */\n  labelPosition?: \"left\" | \"right\"\n  /** Shows the danger state, e.g. an unaccepted required checkbox. */\n  invalid?: boolean\n}\n\nconst tones = (c: string) => `\n.${c}{--pc-c:var(--primary);--pc-fg:var(--primary-foreground)}\n.${c}[data-tone=neutral]{--pc-c:var(--foreground);--pc-fg:var(--background)}\n.${c}[data-tone=success]{--pc-c:oklch(0.53 0.13 155);--pc-fg:#fff}\n.${c}[data-tone=warning]{--pc-c:oklch(0.75 0.16 70);--pc-fg:oklch(0.25 0.05 70)}\n.${c}[data-tone=danger]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff}\n.${c}[data-tone=info]{--pc-c:oklch(0.55 0.17 250);--pc-fg:#fff}\n.dark .${c}[data-tone=success]{--pc-c:oklch(0.7 0.16 155);--pc-fg:oklch(0.2 0.05 155)}\n.dark .${c}[data-tone=danger]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25)}\n.dark .${c}[data-tone=info]{--pc-c:oklch(0.7 0.15 245);--pc-fg:oklch(0.2 0.05 245)}\n.${c}{--pc-tint:color-mix(in oklab,var(--pc-c) 14%,transparent);--pc-ink:color-mix(in oklab,var(--pc-c) 82%,var(--foreground))}\n.${c}[data-tone=warning]{--pc-ink:color-mix(in oklab,var(--pc-c) 62%,var(--foreground))}\n`\n\nconst R = \".pc-checkbox\"\nconst B = \".pc-checkbox-box\"\nconst ON = `${R}:is([data-state=checked],[data-state=indeterminate])`\nconst CSS = `${tones(\"pc-checkbox\")}\n${R}{--pc-edge:color-mix(in oklab,var(--foreground) 28%,transparent);-webkit-tap-highlight-color:transparent}\n${R}[data-invalid]{--pc-edge:oklch(0.56 0.21 27)}\n${B}{background:var(--background);border:1.5px solid var(--pc-edge);color:var(--pc-fg)}\n.pc-checkbox-desc{color:color-mix(in oklab,var(--muted-foreground) 85%,var(--foreground))}\n${R}[data-state=unchecked]:not([data-disabled]):hover ${B}{border-color:color-mix(in oklab,var(--pc-c) 55%,var(--pc-edge))}\n${ON} ${B}{background:var(--pc-c);border-color:var(--pc-c)}\n${R}:has(input:focus-visible) ${B}{box-shadow:0 0 0 3px color-mix(in oklab,var(--pc-c) 35%,transparent)}\n\n${R}[data-variant=filled] ${B}{background:color-mix(in oklab,var(--foreground) 9%,transparent);border-color:transparent}\n${R}[data-variant=filled]${ON.slice(R.length)} ${B}{background:var(--pc-c)}\n${R}[data-variant=outline]${ON.slice(R.length)} ${B}{background:var(--pc-tint);border-color:var(--pc-c);color:var(--pc-ink)}\n${R}[data-variant=neo] ${B}{border:2px solid var(--foreground);box-shadow:2px 2px 0 var(--foreground)}\n${R}[data-variant=neo]:not([data-disabled]):hover ${B}{border-color:var(--foreground)}\n${R}[data-variant=neo]${ON.slice(R.length)} ${B}{border-color:var(--foreground)}\n${R}[data-variant=neo]:not([data-disabled]):active ${B}{transform:translate(2px,2px);box-shadow:0 0 0 var(--foreground)}\n\n${R}[data-variant=card]{background:var(--card);border:1px solid var(--border);box-shadow:0 1px 2px rgb(0 0 0/.04)}\n${R}[data-variant=card]:not([data-disabled]):hover{border-color:color-mix(in oklab,var(--pc-c) 35%,var(--border))}\n${R}[data-variant=card]${ON.slice(R.length)}{border-color:var(--pc-c);box-shadow:0 0 0 1px var(--pc-c);background:color-mix(in oklab,var(--pc-c) 5%,var(--card))}\n${R}[data-variant=card]:has(input:focus-visible){box-shadow:0 0 0 1px var(--pc-c),0 0 0 4px color-mix(in oklab,var(--pc-c) 30%,transparent)}\n${R}[data-variant=card][data-invalid]{border-color:oklch(0.56 0.21 27)}\n\n${R}[data-shadow=sm] ${B},${R}[data-variant=card][data-shadow=sm]{box-shadow:0 1px 3px rgb(0 0 0/.14),0 1px 1px rgb(0 0 0/.06)}\n${R}[data-shadow=glow]${ON.slice(R.length)} ${B}{box-shadow:0 0 0 3px var(--pc-tint),0 2px 10px -1px color-mix(in oklab,var(--pc-c) 65%,transparent)}\n${R}[data-variant=card][data-shadow=glow]${ON.slice(R.length)}{box-shadow:0 0 0 1px var(--pc-c),0 8px 24px -8px color-mix(in oklab,var(--pc-c) 55%,transparent)}\n${R}[data-variant=card][data-shadow=glow]${ON.slice(R.length)} ${B}{box-shadow:none}\n\n/* Radio: classic ring + dot by default; filled and circle fill the disc. */\n${R}[data-kind=radio] ${B}{color:var(--pc-c)}\n${R}[data-kind=radio]${ON.slice(R.length)}:is([data-variant=default],[data-variant=card],[data-variant=outline]) ${B}{background:var(--background)}\n${R}[data-kind=radio][data-variant=outline]${ON.slice(R.length)} ${B}{border-width:5px;background:var(--background)}\n${R}[data-kind=radio]:is([data-variant=filled],[data-variant=circle],[data-variant=neo])${ON.slice(R.length)} ${B}{color:var(--pc-fg)}\n\n/* Marks */\n.pc-checkbox-mark{fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;opacity:0;transform-box:fill-box;transform-origin:center}\n.pc-checkbox-dot{fill:currentColor;stroke:none}\n${R}[data-state=checked] .pc-checkbox-check,${R}[data-state=checked] .pc-checkbox-dot,${R}[data-state=indeterminate] .pc-checkbox-dash{opacity:1}\n${R}[data-anim]:not([data-anim=none]) ${B}{transition:background-color .16s,border-color .16s,box-shadow .2s,color .16s,transform .12s}\n${R}[data-anim]:not([data-anim=none]):not([data-variant=neo]):not([data-disabled]):active ${B}{transform:scale(.9)}\n${R}[data-variant=card][data-anim]:not([data-anim=none]){transition:border-color .18s,box-shadow .2s,background-color .18s}\n\n${R}[data-anim=draw] .pc-checkbox-mark:not(.pc-checkbox-dot){stroke-dasharray:1;stroke-dashoffset:1;transition:stroke-dashoffset .26s var(--pc-ease-in-out),opacity 0s .26s}\n${R}[data-anim=draw][data-state=checked] .pc-checkbox-check,${R}[data-anim=draw][data-state=indeterminate] .pc-checkbox-dash{stroke-dashoffset:0;transition:stroke-dashoffset .3s var(--pc-ease-in-out) .05s,opacity 0s}\n${R}[data-anim=draw] .pc-checkbox-dot{transform:scale(0);transition:transform .2s var(--pc-ease-out),opacity .15s}\n${R}[data-anim=draw][data-state=checked] .pc-checkbox-dot{transform:scale(1)}\n\n${R}[data-anim=pop] .pc-checkbox-mark{transition:opacity .12s}\n${R}[data-anim=pop][data-touched]${ON.slice(R.length)} ${B}{animation:pc-checkbox-pop .34s var(--pc-ease-spring)}\n@keyframes pc-checkbox-pop{0%{transform:scale(.72)}55%{transform:scale(1.14)}100%{transform:scale(1)}}\n\n${R}[data-anim=bounce] .pc-checkbox-mark{transform:scale(0);transition:transform .38s var(--pc-ease-spring),opacity .1s}\n${R}[data-anim=bounce][data-state=checked] .pc-checkbox-check,${R}[data-anim=bounce][data-state=checked] .pc-checkbox-dot,${R}[data-anim=bounce][data-state=indeterminate] .pc-checkbox-dash{transform:scale(1)}\n${R}[data-anim=bounce][data-touched]${ON.slice(R.length)} ${B}{animation:pc-checkbox-squish .4s var(--pc-ease-spring)}\n@keyframes pc-checkbox-squish{0%{transform:scale(1.18,.82)}50%{transform:scale(.92,1.08)}100%{transform:scale(1)}}\n\n@media (prefers-reduced-motion:reduce){\n  ${R},${R} *{transition:none!important;animation:none!important}\n  ${R} .pc-checkbox-mark{stroke-dashoffset:0!important;transform:none!important}\n}\n`\n\nconst BOX: Record<CheckboxSize, string> = { sm: \"size-3.5 rounded-[4px]\", md: \"size-4 rounded-[5px]\", lg: \"size-5 rounded-[6px]\" }\nconst TEXT: Record<CheckboxSize, { label: string; line: string; card: string }> = {\n  sm: { label: \"text-[13px]\", line: \"h-[18px]\", card: \"p-3 gap-2.5 rounded-lg\" },\n  md: { label: \"text-sm\", line: \"h-5\", card: \"p-4 gap-3 rounded-xl\" },\n  lg: { label: \"text-[15px]\", line: \"h-[22px]\", card: \"p-5 gap-3.5 rounded-xl\" },\n}\n\ntype ChoiceProps = Required<Layers> &\n  Text & {\n    kind: \"checkbox\" | \"radio\"\n    state: \"checked\" | \"unchecked\" | \"indeterminate\"\n    touched: boolean\n    disabled?: boolean\n    className?: string\n    children?: React.ReactNode\n    input: React.ReactElement\n    id: string\n  }\n\nfunction Choice({ kind, state, touched, variant, tone, animation, shadow, size, label, description, labelPosition = \"right\", invalid, disabled, className, children, input, id }: ChoiceProps) {\n  const round = kind === \"radio\" || variant === \"circle\"\n  const text = (label || description || children) && (\n    <span className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n      {label && (\n        <span id={`${id}-label`} className={cn(\"leading-snug font-medium\", TEXT[size].label)}>\n          {label}\n        </span>\n      )}\n      {description && (\n        <span id={`${id}-desc`} className=\"pc-checkbox-desc text-[13px] leading-snug\">\n          {description}\n        </span>\n      )}\n      {children}\n    </span>\n  )\n  const box = (\n    <span className={cn(\"flex shrink-0 items-center\", (label || description) && TEXT[size].line)}>\n      <span data-slot=\"checkbox-box\" className={cn(\"pc-checkbox-box relative grid place-items-center\", BOX[size], round && \"rounded-full\", variant === \"neo\" && !round && \"rounded-[3px]\")}>\n        {input}\n        <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" className=\"pointer-events-none size-full\">\n          {kind === \"radio\" && variant !== \"circle\" ? (\n            <circle className=\"pc-checkbox-mark pc-checkbox-dot\" cx=\"12\" cy=\"12\" r={variant === \"outline\" ? 0 : 5.5} />\n          ) : (\n            <>\n              <path className=\"pc-checkbox-mark pc-checkbox-check\" d=\"M6 12.5l4 4L18 8\" pathLength={1} strokeWidth={3} />\n              <path className=\"pc-checkbox-mark pc-checkbox-dash\" d=\"M7 12h10\" pathLength={1} strokeWidth={3} />\n            </>\n          )}\n        </svg>\n      </span>\n    </span>\n  )\n  return (\n    <>\n      <style href=\"pc-checkbox\" precedence=\"default\">\n        {CSS}\n      </style>\n      <label\n        htmlFor={id}\n        data-slot={kind}\n        data-kind={kind}\n        data-variant={variant}\n        data-tone={tone}\n        data-anim={animation}\n        data-shadow={shadow}\n        data-state={state}\n        data-touched={touched || undefined}\n        data-invalid={invalid || undefined}\n        data-disabled={disabled || undefined}\n        className={cn(\n          \"pc-checkbox relative items-start select-none\",\n          variant === \"card\" ? cn(\"flex\", TEXT[size].card) : cn(\"inline-flex\", size === \"sm\" ? \"gap-2\" : \"gap-2.5\"),\n          labelPosition === \"left\" && \"flex justify-between\",\n          disabled ? \"cursor-not-allowed opacity-55\" : \"cursor-pointer\",\n          className,\n        )}\n      >\n        {labelPosition === \"left\" ? (\n          <>\n            {text}\n            {box}\n          </>\n        ) : (\n          <>\n            {box}\n            {text}\n          </>\n        )}\n      </label>\n    </>\n  )\n}\n\nconst INPUT = \"absolute inset-0 m-0 size-full cursor-[inherit] appearance-none rounded-[inherit] opacity-0 outline-none\"\n\nexport type CheckboxProps = Omit<React.ComponentProps<\"input\">, \"type\" | \"size\" | \"checked\" | \"defaultChecked\" | \"onChange\"> &\n  Layers &\n  Text & {\n    /** Checked state (controlled). */\n    checked?: boolean\n    /** Initial state when uncontrolled. */\n    defaultChecked?: boolean\n    /** Called with the new checked state. */\n    onCheckedChange?: (checked: boolean) => void\n    /** Native change event of the hidden input. */\n    onChange?: React.ChangeEventHandler<HTMLInputElement>\n    /** Shows a dash, e.g. a \"select all\" with some rows selected. Clicking it checks the box. */\n    indeterminate?: boolean\n    /** Extra content under the description (prices, badges), handy with the card variant. */\n    children?: React.ReactNode\n    /** Plays \"pop\" when checked and \"tick\" when unchecked, when the visitor has sounds on (lib/goodui-sounds); pass a sound name to use one sound for both. Off by default. */\n    sound?: boolean | SoundName\n  }\n\n// Optional UI sound: the sound module is loaded only when `sound` is on, so silent apps pay nothing.\nfunction useCue(sound: boolean | SoundName | undefined) {\n  React.useEffect(() => {\n    if (sound) void import(\"@/lib/goodui-sounds\")\n  }, [sound])\n  return React.useCallback(\n    (fallback: SoundName, o?: { rate?: number; exact?: boolean }) => {\n      if (!sound) return\n      void import(\"@/lib/goodui-sounds\").then((m) => m.play(sound === true || o?.exact ? fallback : sound, { rate: o?.rate }))\n    },\n    [sound],\n  )\n}\n\nexport function Checkbox({\n  checked: checkedProp,\n  defaultChecked = false,\n  onCheckedChange,\n  onChange,\n  indeterminate = false,\n  variant = \"default\",\n  tone = \"primary\",\n  animation = \"draw\",\n  shadow = \"none\",\n  size = \"md\",\n  label,\n  description,\n  labelPosition,\n  invalid,\n  disabled,\n  className,\n  children,\n  sound,\n  id: idProp,\n  ref: refProp,\n  ...props\n}: CheckboxProps) {\n  const uid = React.useId()\n  const id = idProp ?? uid\n  const cue = useCue(sound)\n  const ref = React.useRef<HTMLInputElement>(null)\n  // Merge the caller's ref (e.g. react-hook-form's register) with the internal one.\n  const setRef = React.useCallback(\n    (el: HTMLInputElement | null) => {\n      ref.current = el\n      if (typeof refProp === \"function\") refProp(el)\n      else if (refProp) refProp.current = el\n    },\n    [refProp],\n  )\n  const [inner, setInner] = React.useState(defaultChecked)\n  const [touched, setTouched] = React.useState(false)\n  const controlled = checkedProp !== undefined\n  const checked = checkedProp ?? inner\n  // Uncontrolled boxes stay native (defaultChecked) so libraries that set el.checked keep working; read it back once.\n  React.useEffect(() => {\n    if (!controlled && ref.current) setInner(ref.current.checked)\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [])\n  // A click clears el.indeterminate natively; re-apply the prop after every render so a parent that keeps\n  // indeterminate=true stays in sync.\n  React.useEffect(() => {\n    if (ref.current) ref.current.indeterminate = indeterminate\n  })\n  const state = indeterminate ? \"indeterminate\" : checked ? \"checked\" : \"unchecked\"\n\n  return (\n    <Choice\n      kind=\"checkbox\"\n      id={id}\n      state={state}\n      touched={touched}\n      {...{ variant, tone, animation, shadow, size, label, description, labelPosition, invalid, disabled, className, children }}\n      input={\n        <input\n          ref={setRef}\n          type=\"checkbox\"\n          id={id}\n          {...(controlled ? { checked } : { defaultChecked })}\n          disabled={disabled}\n          aria-invalid={invalid || undefined}\n          aria-labelledby={label ? `${id}-label` : undefined}\n          aria-describedby={description ? `${id}-desc` : undefined}\n          onChange={(e) => {\n            onChange?.(e)\n            setTouched(true)\n            if (!controlled) setInner(e.target.checked)\n            onCheckedChange?.(e.target.checked)\n            cue(e.target.checked ? \"pop\" : \"tick\")\n            e.target.indeterminate = indeterminate\n          }}\n          className={INPUT}\n          {...props}\n        />\n      }\n    />\n  )\n}\n\ntype GroupCtx = Required<Layers> & {\n  name: string\n  value: string | undefined\n  select: (v: string) => void\n  touched: boolean\n  disabled?: boolean\n  labelPosition?: \"left\" | \"right\"\n}\nconst RadioContext = React.createContext<GroupCtx | null>(null)\n\nexport type RadioGroupProps = Omit<React.ComponentProps<\"div\">, \"defaultValue\" | \"onChange\" | \"dir\"> &\n  Layers & {\n    /** Selected radio value (controlled). */\n    value?: string\n    /** Initially selected value when uncontrolled. */\n    defaultValue?: string\n    /** Called with the value of the newly selected radio. */\n    onValueChange?: (value: string) => void\n    /** Form field name. Generated when omitted. */\n    name?: string\n    /** Disables every radio in the group. */\n    disabled?: boolean\n    /** horizontal lays the radios out in equal columns. */\n    orientation?: \"vertical\" | \"horizontal\"\n    /** Default text side for every radio. */\n    labelPosition?: \"left\" | \"right\"\n  }\n\nexport function RadioGroup({\n  value: valueProp,\n  defaultValue,\n  onValueChange,\n  name,\n  disabled,\n  orientation = \"vertical\",\n  variant = \"default\",\n  tone = \"primary\",\n  animation = \"draw\",\n  shadow = \"none\",\n  size = \"md\",\n  labelPosition,\n  className,\n  children,\n  ...props\n}: RadioGroupProps) {\n  const uid = React.useId()\n  const [inner, setInner] = React.useState(defaultValue)\n  const [touched, setTouched] = React.useState(false)\n  const value = valueProp ?? inner\n  const select = React.useCallback(\n    (v: string) => {\n      setTouched(true)\n      if (valueProp === undefined) setInner(v)\n      onValueChange?.(v)\n    },\n    [valueProp, onValueChange],\n  )\n  return (\n    <RadioContext.Provider value={{ name: name ?? uid, value, select, touched, disabled, variant, tone, animation, shadow, size, labelPosition }}>\n      <GooduiTokens />\n      <div\n        role=\"radiogroup\"\n        aria-orientation={orientation}\n        aria-disabled={disabled || undefined}\n        data-slot=\"radio-group\"\n        className={cn(\"grid\", orientation === \"horizontal\" ? \"grid-flow-col auto-cols-fr gap-3\" : variant === \"card\" ? \"gap-2.5\" : \"gap-3\", className)}\n        {...props}\n      >\n        {children}\n      </div>\n    </RadioContext.Provider>\n  )\n}\n\nexport type RadioProps = Omit<React.ComponentProps<\"input\">, \"type\" | \"size\" | \"value\" | \"checked\" | \"defaultChecked\"> &\n  Layers &\n  Text & {\n    /** Value reported to RadioGroup and submitted with the form. */\n    value: string\n    /** Extra content under the description (prices, badges), handy with the card variant. */\n    children?: React.ReactNode\n  }\n\nexport function Radio({ value, label, description, labelPosition, invalid, disabled, className, children, id: idProp, onChange, variant, tone, animation, shadow, size, ...props }: RadioProps) {\n  const ctx = React.useContext(RadioContext)\n  if (!ctx) throw new Error(\"<Radio> must be used inside <RadioGroup>\")\n  const uid = React.useId()\n  const id = idProp ?? uid\n  const checked = ctx.value === value\n  const off = disabled || ctx.disabled\n  return (\n    <Choice\n      kind=\"radio\"\n      id={id}\n      state={checked ? \"checked\" : \"unchecked\"}\n      touched={ctx.touched}\n      variant={variant ?? ctx.variant}\n      tone={tone ?? ctx.tone}\n      animation={animation ?? ctx.animation}\n      shadow={shadow ?? ctx.shadow}\n      size={size ?? ctx.size}\n      labelPosition={labelPosition ?? ctx.labelPosition}\n      {...{ label, description, invalid, className, children }}\n      disabled={off}\n      input={\n        <input\n          type=\"radio\"\n          id={id}\n          name={ctx.name}\n          value={value}\n          checked={checked}\n          disabled={off}\n          aria-labelledby={label ? `${id}-label` : undefined}\n          aria-describedby={description ? `${id}-desc` : undefined}\n          onChange={(e) => {\n            onChange?.(e)\n            if (e.target.checked) ctx.select(value)\n          }}\n          className={INPUT}\n          {...props}\n        />\n      }\n    />\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/checkbox.tsx"
    }
  ],
  "categories": [
    "components",
    "core"
  ],
  "type": "registry:component"
}