{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "choice",
  "title": "Choice",
  "description": "What Checkbox, Radio and Switch share: the hit area, focus, invalid and disabled states, a held press, and the wipe that draws a mark. Also the cards of Checkbox cards and Radio cards, which fade to grey when picked.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/lib/choice.ts",
      "content": "import type { FocusEvent, KeyboardEvent } from 'react'\nimport { createContext } from 'react'\n\n/**\n * What Checkbox, Radio and Switch share, so a choice answers the same way\n * whichever control makes it: the hit area, focus, invalid, disabled and a\n * held press, and the wipe that draws a box's mark.\n */\n\n/**\n * Every choice control: a hit area 4px past its edge, the focus ring, the\n * invalid ring with a dashed outline where forced colours drop it, and the\n * disabled fade.\n */\nexport const choiceClassName =\n  'relative inline-flex shrink-0 items-center outline-offset-2 after:absolute after:-inset-1 focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-hidden aria-invalid:ring-3 aria-invalid:ring-destructive/20 forced-colors:aria-invalid:outline-2 forced-colors:aria-invalid:outline-dashed dark:aria-invalid:ring-destructive/40 data-disabled:pointer-events-none data-disabled:opacity-50'\n\n/** How a 16px box looks at rest: its border, surface and shadow, in either theme. */\nconst choiceBoxLookClassName =\n  'size-4 shrink-0 justify-center border border-muted-foreground/80 bg-background shadow-xs dark:bg-input/30'\n\n/**\n * The 16px box a Checkbox or Radio is drawn in. While held (by the pointer,\n * by Space, or by its label or its card) it shrinks by three times the feel's\n * press scale, since a press the size of a button's would be lost on a box\n * this small; it eases down quickly and back on the press role. A card's box\n * also takes the card's hover. An invalid box keeps its colour under hover. Read-only and disabled boxes take no hover or\n * press.\n */\nconst choiceBoxBaseClassName = `${choiceBoxLookClassName} transition-[background-color,border-color,box-shadow,scale] duration-(--motion-press-duration) ease-[var(--motion-press-fade-easing),var(--motion-press-fade-easing),var(--motion-press-fade-easing),var(--motion-press-easing)] not-data-checked:not-data-indeterminate:not-data-disabled:not-data-readonly:not-aria-invalid:hover:border-muted-foreground not-data-checked:not-data-indeterminate:not-data-disabled:not-data-readonly:[[data-choice-card]:hover:not(:has([aria-invalid=true]))_&]:border-muted-foreground aria-invalid:border-destructive active:duration-[calc(var(--motion-press-duration)*0.4)] data-pressing:duration-[calc(var(--motion-press-duration)*0.4)] [label:active_&]:duration-[calc(var(--motion-press-duration)*0.4)] [[data-slot=field]:has(>[data-slot=field-label]:active)_&]:duration-[calc(var(--motion-press-duration)*0.4)] motion-safe:not-data-readonly:active:scale-[calc(1_-_(1_-_var(--motion-press-scale))_*_3)] motion-safe:not-data-readonly:data-pressing:scale-[calc(1_-_(1_-_var(--motion-press-scale))_*_3)] motion-safe:[label:active:not(:has([data-disabled],[data-readonly]))_&]:scale-[calc(1_-_(1_-_var(--motion-press-scale))_*_3)] motion-safe:[[data-slot=field]:has(>[data-slot=field-label]:active):not(:has([data-disabled],[data-readonly]))_&]:scale-[calc(1_-_(1_-_var(--motion-press-scale))_*_3)]`\n\n/** A Checkbox's or Radio's box, whose border takes the focus colour. */\nexport const choiceBoxClassName = `${choiceBoxBaseClassName} focus-visible:border-ring`\n\n/**\n * The box a choice card's indicator is drawn in: the card draws the focus\n * ring and, in forced colours, the invalid outline, so the box keeps its\n * border and draws neither outline of its own.\n */\nexport const choiceCardBoxClassName = `${choiceBoxBaseClassName} focus-visible:outline-hidden forced-colors:aria-invalid:outline-0`\n\n/** The primary fill of a box that is ticked or mixed, kept in forced colours. */\nconst choiceFilledClassName =\n  'data-checked:border-primary data-checked:bg-primary data-indeterminate:border-primary data-indeterminate:bg-primary dark:data-checked:bg-primary dark:data-indeterminate:bg-primary forced-colors:data-checked:bg-[Highlight]! forced-colors:data-indeterminate:bg-[Highlight]!'\n\n/** A Checkbox's corner, small whatever the shape. */\nexport const choiceCheckboxCornerClassName =\n  'rounded-[min(calc(var(--control-radius-xs)/2),6px)]'\n\n/** A Checkbox's box: its corner, filled with the primary colour while ticked or mixed. */\nexport const choiceCheckboxClassName = `${choiceCheckboxCornerClassName} ${choiceFilledClassName}`\n\n/**\n * A mark that shows a state but takes no press, such as a rule a password has\n * met: a Checkbox's box at rest and its fill, round so it never reads as a box\n * to tick. Mark it `group/checkbox` and `data-checked` for a `CheckboxMark`\n * inside.\n */\nexport const choiceMarkBoxClassName = `inline-flex shrink-0 items-center rounded-full ${choiceBoxLookClassName} ${choiceFilledClassName} transition-[background-color,border-color] duration-(--motion-press-duration) ease-(--motion-press-fade-easing)`\n\ntype PressHandlers<K, F> = {\n  onKeyDown?: (event: K) => void\n  onKeyUp?: (event: K) => void\n  onBlur?: (event: F) => void\n}\n\n/**\n * Marks a choice `data-pressing` while Space is held on it, which CSS can't\n * see, so a key press shows the same way a pointer's does. Each handler also\n * calls the one passed in.\n */\nexport function choicePressHandlers<\n  K extends KeyboardEvent<Element>,\n  F extends FocusEvent<Element>,\n>({ onKeyDown, onKeyUp, onBlur }: PressHandlers<K, F>): Required<PressHandlers<K, F>> {\n  return {\n    onKeyDown: (event) => {\n      if (event.key === ' ') event.currentTarget.setAttribute('data-pressing', '')\n      onKeyDown?.(event)\n    },\n    onKeyUp: (event) => {\n      event.currentTarget.removeAttribute('data-pressing')\n      onKeyUp?.(event)\n    },\n    onBlur: (event) => {\n      event.currentTarget.removeAttribute('data-pressing')\n      onBlur?.(event)\n    },\n  }\n}\n\n/** A mark that wipes in along the reading direction on the draw role, and is simply there under reduced motion. */\nexport const choiceWipeClassName =\n  'transition-[clip-path] duration-(--motion-draw-duration) ease-(--motion-draw-easing) [clip-path:inset(0_100%_0_0)] motion-reduce:transition-none rtl:[clip-path:inset(0_0_0_100%)]'\n\n/**\n * A part marked `data-pressing` while held, such as a Rating's star, which\n * holds no box of its own: it shrinks as a held box does, by three times the\n * feel's press scale, quickly on the way down and back on the press role.\n */\nexport const choicePressingClassName =\n  'transition-[scale] duration-(--motion-press-duration) ease-(--motion-press-easing) data-pressing:duration-[calc(var(--motion-press-duration)*0.4)] motion-safe:data-pressing:scale-[calc(1_-_(1_-_var(--motion-press-scale))_*_3)]'\n\n/**\n * A card that is the choice itself, as in Radio cards and Checkbox cards: the\n * whole card takes the press, the focus ring and the invalid ring. Picked, its\n * surface fades to grey on the press role and its border and shadow go, so\n * the grey and the indicator's check carry the pick (in forced colours, the\n * border takes the system highlight). Muted text darkens on a picked card to\n * keep 4.5:1 on the grey. Disabled, its content fades and it takes no press.\n */\nexport const choiceCardClassName =\n  'relative flex min-w-0 flex-col gap-1 rounded-(--surface-radius) border bg-card p-(--surface-padding) text-start text-sm shadow-xs outline-offset-2 transition-[background-color,border-color,box-shadow] duration-(--motion-press-duration) ease-(--motion-press-fade-easing) select-none not-has-data-checked:not-has-data-disabled:not-has-data-readonly:not-has-aria-invalid:hover:border-muted-foreground/50 has-focus-visible:ring-3 has-focus-visible:ring-ring/50 has-focus-visible:outline-hidden has-data-checked:border-transparent has-data-checked:bg-muted has-data-checked:shadow-none has-data-checked:[--muted-foreground:color-mix(in_oklab,var(--foreground)_70%,var(--background))] forced-colors:has-data-checked:border-[Highlight] has-aria-invalid:border-destructive has-aria-invalid:ring-3 has-aria-invalid:ring-destructive/20 forced-colors:has-aria-invalid:outline-2 forced-colors:has-aria-invalid:outline-dashed dark:has-aria-invalid:ring-destructive/40 has-data-disabled:cursor-not-allowed has-data-disabled:shadow-none has-data-disabled:*:opacity-50 has-data-readonly:cursor-default'\n\n/**\n * A card's indicator: the box at rest, and once picked no box at all, only\n * its check, in the text colour, which wipes in on the draw role\n * (`CheckboxMark`). Mark it `group/checkbox`.\n */\nexport const choiceCardCheckedClassName =\n  'data-checked:border-transparent data-checked:bg-transparent data-checked:shadow-none dark:data-checked:bg-transparent data-indeterminate:border-transparent data-indeterminate:bg-transparent data-indeterminate:shadow-none dark:data-indeterminate:bg-transparent'\n\n/** The check a picked card's indicator shows, in the text colour, and in forced colours the text's. */\nexport const choiceCardMarkClassName =\n  'absolute inset-0 m-auto text-foreground forced-colors:text-[CanvasText]'\n\n/** A card's title: the choice's name. */\nexport const choiceCardTitleClassName = 'font-medium text-pretty'\n\n/** A card's description, under its title. */\nexport const choiceCardDescriptionClassName = 'text-muted-foreground text-pretty'\n\n/**\n * What a card hands its indicator, which is the choice's control: the ids of\n * the title and description that name and describe it, and the props the\n * card was given.\n */\nexport const ChoiceCardContext = createContext<{\n  title: string\n  description: string\n  control: Record<string, unknown>\n}>({\n  title: '',\n  description: '',\n  control: {},\n})\n",
      "type": "registry:lib",
      "target": "@lib/choice.ts"
    }
  ],
  "type": "registry:lib"
}