{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "choice-list",
  "title": "Choice list",
  "description": "Replies to choose from: rows in the signal color, the chosen one a solid yellow bar.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5",
    "lucide-react@1.73.0"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/choice-list.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { CornerDownLeft } from \"lucide-react\"\nimport { Radio, RadioGroup, RadioIndicator } from \"@ui-sdk/react/radio\"\nimport \"@/registry/cyber/ui/cyber/choice-list.css\"\n\ntype Choice<T extends string = string> = {\n  value: T\n  label: string\n  code?: string\n  disabled?: boolean\n}\n\n// The serial printed beside a reply when it isn't given one: three lines of\n// hex that are always the same for the same value, so they don't change\n// between renders or between the server and the page.\nfunction serialOf(value: string) {\n  let seed = 0x9e37\n  for (const char of value) seed = (Math.imul(seed ^ char.charCodeAt(0), 0x45d9f3b) >>> 0) % 0xffffffff\n  return Array.from({ length: 3 }, () => {\n    seed = (Math.imul(seed, 0x19660d) + 0x3c6ef35f) >>> 0\n    const hex = seed.toString(16).toUpperCase().padStart(8, \"0\")\n    return `${hex.slice(0, 4)} ${hex.slice(4)}`\n  }).join(\"\\n\")\n}\n\n// The replies under a message: sentences to answer with, one of which is the\n// answer. They read in the signal color off a line down the leading edge,\n// and the chosen one is a solid flag-yellow bar with a cut corner.\n//\n// It's a radio group, and each whole row is its radio: Tab reaches the\n// chosen reply, and the arrow keys move the choice, as they would on the\n// screen it's modelled on.\n//\n// - `options` are the replies: a `value`, the sentence as `label`, and\n//   optionally the `code` printed beside it (decoration; one is made up\n//   from the value otherwise).\n// - `hideLabel` keeps the label as the group's name without showing it, for\n//   a list that sits directly under the message it answers.\nfunction ChoiceList<T extends string = string>({\n  label,\n  hideLabel,\n  options,\n  onValueChange,\n  ...props\n}: Omit<React.ComponentProps<typeof RadioGroup<T>>, \"children\"> & {\n  label: string\n  hideLabel?: boolean\n  options: Choice<T>[]\n}) {\n  const id = React.useId()\n  // The chosen reply tears in as it's picked, but not the one that was\n  // already chosen when the list appeared.\n  const [picked, setPicked] = React.useState(false)\n  return (\n    <div data-kit=\"choice-list\">\n      {!hideLabel && (\n        <span data-kit=\"label\" id={id}>\n          {label}\n        </span>\n      )}\n      <RadioGroup<T>\n        data-kit=\"choice-list-group\"\n        data-picked={picked ? \"\" : undefined}\n        aria-label={hideLabel ? label : undefined}\n        aria-labelledby={hideLabel ? undefined : id}\n        onValueChange={(next, details) => {\n          onValueChange?.(next, details)\n          if (!details.canceled) setPicked(true)\n        }}\n        {...props}\n      >\n        {options.map((option) => (\n          <Radio key={option.value} data-kit=\"choice\" data-frame=\"br\" value={option.value} disabled={option.disabled}>\n            <span data-kit=\"choice-code\" data-micro aria-hidden>\n              {option.code ?? serialOf(option.value)}\n            </span>\n            <span data-kit=\"choice-text\">{option.label}</span>\n            <RadioIndicator data-kit=\"choice-mark\" aria-hidden>\n              <CornerDownLeft />\n            </RadioIndicator>\n          </Radio>\n        ))}\n      </RadioGroup>\n    </div>\n  )\n}\n\nexport { ChoiceList }\nexport type { Choice }\n",
      "type": "registry:ui",
      "target": "@ui/choice-list.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/choice-list.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  [data-skin=\"cyber\"] [data-kit=\"choice-list\"] {\n    display: grid;\n    gap: 6px;\n    width: 100%;\n    min-width: 0;\n    text-align: start;\n    container-type: inline-size;\n  }\n\n  /* The replies hang off one line down the leading edge. */\n  [data-skin=\"cyber\"] [data-kit=\"choice-list-group\"] {\n    display: grid;\n    min-width: 0;\n    padding-inline-start: 4px;\n    border-inline-start: 2px solid var(--cy-signal-dim);\n\n    &[data-disabled] {\n      border-inline-start-color: var(--cy-line-deco);\n    }\n  }\n\n  /* A reply: its serial in a narrow column, then the sentence. The row is a\n     frame with no edge and no fill until it's chosen, so its cut corner and\n     its focus ring are the frame's. */\n  [data-skin=\"cyber\"] [data-kit=\"choice\"] {\n    --frame-cut: var(--cy-cut);\n    --frame-line: transparent;\n    --frame-fill: transparent;\n    --frame-image: none;\n\n    display: grid;\n    grid-template-columns: 52px minmax(0, 1fr) 16px;\n    align-items: center;\n    column-gap: 10px;\n    width: 100%;\n    min-height: calc(var(--cy-h) + 4px);\n    padding: 6px 12px 6px 8px;\n    font-size: var(--cy-text-md);\n    font-weight: 500;\n    line-height: 1.3;\n    text-align: start;\n    color: var(--cy-signal);\n    cursor: pointer;\n    transition:\n      background-color var(--cy-t-fast) linear,\n      border-color var(--cy-t-fast) linear,\n      color var(--cy-t-fast) linear;\n\n    /* Under the pointer: the signal's own faint fill, and a bar on the\n       leading edge. */\n    @media (hover: hover) {\n      &:hover:not([data-checked], [data-disabled], [data-readonly]) {\n        --frame-fill: var(--cy-signal-fill);\n        --frame-image: linear-gradient(to right, var(--cy-signal) 3px, transparent 3px);\n        color: var(--cy-ink-hi);\n\n        &:dir(rtl) {\n          --frame-image: linear-gradient(to left, var(--cy-signal) 3px, transparent 3px);\n        }\n      }\n    }\n\n    /* The answer: solid yellow, dark ink. */\n    &[data-checked] {\n      --frame-line: var(--cy-flag);\n      --frame-fill: var(--cy-flag);\n      --frame-focus: var(--cy-flag);\n      color: var(--cy-on-solid);\n    }\n\n    /* A dark edge on a yellow bar would vanish into the panel behind it, so\n       the chosen reply's focus is a second, dark frame inside the bar. */\n    &[data-checked]:focus-visible::after {\n      content: \"\";\n      position: absolute;\n      inset: 2px;\n      border: 2px solid var(--cy-on-solid);\n      pointer-events: none;\n    }\n\n    [data-picked] > &[data-checked] {\n      animation: var(--cy-fx-rgb) 240ms var(--cy-ease-snap);\n    }\n\n    &[data-readonly] {\n      cursor: default;\n    }\n\n    &[data-disabled] {\n      --frame-image: repeating-linear-gradient(135deg, transparent 0 5px, var(--cy-line-deco) 5px 6px);\n      color: var(--cy-ink-mute);\n      cursor: not-allowed;\n\n      &[data-checked] {\n        --frame-line: var(--cy-line-deco);\n        --frame-fill: var(--cy-panel-2);\n      }\n    }\n  }\n\n  /* The serial: three lines of micro-print. Decoration, so it's hidden from\n     assistive technology and takes its ink from the row. */\n  [data-skin=\"cyber\"] [data-kit=\"choice-code\"] {\n    color: var(--cy-signal);\n    opacity: 0.55;\n    white-space: pre;\n    overflow: hidden;\n\n    [data-checked] > & {\n      color: var(--cy-on-solid);\n      opacity: 0.7;\n    }\n\n    [data-disabled] > & {\n      color: var(--cy-ink-mute);\n    }\n  }\n\n  /* In a narrow column the sentence needs the room more than the serial\n     does. */\n  @container (width < 280px) {\n    [data-skin=\"cyber\"] [data-kit=\"choice\"] {\n      grid-template-columns: minmax(0, 1fr) 16px;\n      padding-inline-start: 10px;\n    }\n\n    [data-skin=\"cyber\"] [data-kit=\"choice-code\"] {\n      display: none;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"choice-text\"] {\n    min-width: 0;\n    text-wrap: pretty;\n  }\n\n  /* The mark that says which reply goes, so the choice isn't carried by the\n     yellow alone. */\n  [data-skin=\"cyber\"] [data-kit=\"choice-mark\"] {\n    grid-column: -2;\n    display: grid;\n    place-items: center;\n\n    & svg {\n      width: 14px;\n      height: 14px;\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/choice-list.css"
    }
  ],
  "type": "registry:ui"
}
