{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radio-group",
  "title": "Radio group",
  "description": "Exclusive choice as framed rows; the ink band stretches to the chosen row.",
  "dependencies": [
    "@base-ui/react@1.9.0"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/keyline-motion",
    "@keyline-ui/checkbox",
    "@keyline-ui/keyline-render",
    "@keyline-ui/keyline-scope"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/radio-group.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { RadioGroup as RadioGroupPrimitive } from \"@base-ui/react/radio-group\";\nimport { Radio as RadioPrimitive } from \"@base-ui/react/radio\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useStretch } from \"../lib/keyline-motion\";\nimport { resolveClassName } from \"../lib/keyline-render\";\nimport { useMergedRef } from \"../lib/keyline-scope\";\nimport { choiceStyles } from \"./checkbox\";\n\n/*\n * Radio group, as Base UI's parts (RadioGroup, Radio, also exported as RadioRoot, and RadioIndicator), and\n * RadioGroupItem, a labelled row built from them:\n *\n *   ┌────┬───────────────────────────┬──────┐\n *   │ ▣  │ Road  Door to door, 2–4 d │    € │   the chosen row is ink: one band that STRETCHES between rows\n *   ├────┼───────────────────────────┼──────┤\n *   │ □  │ Rail                      │   €€ │   rows: box cell · label + description · meta cell\n *   └────┴───────────────────────────┴──────┘\n */\n\n/**\n * The radio group's look, for a component that draws its rows over its own inputs (Questionnaire). `group` is the\n * frame (it carries the band and the rows), `band` the ink band, `row` a row, `indicator` the box and `dot` its dot,\n * `meta` a trailing cell. Rows read Base UI's state attributes and the band's `data-kl-covered`.\n */\nconst radioStyles = {\n  group: cn(\n    \"kl-ctl kl-rows group/radio-group relative isolate flex min-w-0 flex-col bg-kl-cell data-[kl-layout=cell]:bg-transparent\",\n    // a row with meta: the group says so to its rows (a :has() on the group itself; a group-has-* rule restyles the\n    // whole document on any DOM change)\n    \"[--kl-radio-fill:initial] has-[.kl-radio-meta]:[--kl-radio-fill:'']\",\n    // the band is the first child, so the first row is the second: it sits on the frame's top edge, not a divider\n    \"*:nth-2:[border-block-start:0]\",\n  ),\n  band: \"pointer-events-none absolute -z-1 bg-kl-inverse forced-colors:bg-[Highlight] forced-colors:forced-color-adjust-none\",\n  row: cn(\n    \"kl-key group/radio box-border flex min-h-(--kl-row) cursor-pointer items-stretch text-kl-ink\",\n    \"hover:not-data-checked:not-data-disabled:bg-kl-tint\",\n    \"focus-visible:outline-(length:--kl-ring) focus-visible:outline-offset-(--kl-ring-in) focus-visible:outline-kl-focus\",\n    \"focus-visible:outline-solid\",\n    // under the band the row reads covered (the band is drawn under it; its keylines stay on top)\n    \"data-kl-covered:text-kl-on-inverse\",\n    \"data-disabled:cursor-not-allowed data-disabled:bg-(image:--kl-hatch) data-disabled:text-kl-dis\",\n    \"data-disabled:data-kl-covered:text-kl-on-inverse\",\n    \"forced-colors:data-kl-covered:text-[HighlightText] forced-colors:data-kl-covered:forced-color-adjust-none\",\n    // one row with meta: every row keeps the meta column (an empty cell), so the divider runs straight\n    // (the cell exists only while the group's fill is set: without it the content is invalid, so no ::after)\n    \"not-has-[.kl-radio-meta]:after:min-w-(--kl-radio-meta,64px) not-has-[.kl-radio-meta]:after:flex-none\",\n    \"not-has-[.kl-radio-meta]:after:border-s-(length:--kl-k1) not-has-[.kl-radio-meta]:after:border-s-current\",\n    \"not-has-[.kl-radio-meta]:after:content-[var(--kl-radio-fill)]\",\n  ),\n  indicator: \"group/radio-indicator grid size-[18px] place-items-center border-2 border-current\",\n  dot: \"size-2 bg-current group-data-unchecked/radio-indicator:invisible\",\n  description: cn(choiceStyles.description, \"group-data-kl-covered/radio:text-inherit\"),\n  // kl-radio-meta: the theme keeps a meta cell in place while its row is pressed (its ink travels instead)\n  meta: cn(\n    \"kl-radio-meta flex min-w-(--kl-radio-meta,64px) flex-none items-center justify-end px-(--kl-inset)\",\n    \"border-s-(length:--kl-k1) border-s-current font-(--kl-weight-strong) text-kl-ink-2 tabular-nums\",\n    \"group-data-kl-covered/radio:text-inherit\",\n  ),\n};\n\ntype RadioGroupProps = Omit<RadioGroupPrimitive.Props, \"value\" | \"defaultValue\" | \"onValueChange\"> & {\n  value?: string;\n  defaultValue?: string;\n  /** Called with the chosen value and Base UI's event details (the reason, the event). */\n  onValueChange?: (value: string, eventDetails: RadioGroupPrimitive.ChangeEventDetails) => void;\n  /** control: its own 2px frame. cell: rows sit directly in an enclosing frame (e.g. a panel body). */\n  layout?: \"control\" | \"cell\";\n};\n\n/**\n * Exclusive choice as framed rows. The chosen row is ink: one band that STRETCHES between rows (leading edge first,\n * zero bounce), the same behaviour as the segmented control turned vertical. Arrow keys move and select (radio\n * semantics and roving focus from Base UI); the group participates in forms via `name`. Its rows are its direct\n * children (Radio or RadioGroupItem), each with a `value`.\n */\nfunction RadioGroup({\n  value,\n  defaultValue,\n  onValueChange,\n  layout = \"control\",\n  className,\n  children,\n  ref: refProp,\n  ...props\n}: RadioGroupProps): React.ReactElement {\n  const [inner, setInner] = React.useState(defaultValue);\n  const current = value ?? inner;\n  const ref = React.useRef<HTMLDivElement>(null);\n  const setRef = useMergedRef(ref, refProp as React.Ref<HTMLDivElement> | undefined);\n  const values = React.Children.toArray(children)\n    .filter(React.isValidElement)\n    .map((c) => (c.props as { value?: string }).value);\n  useStretch(ref, values.indexOf(current), { axis: \"y\" });\n  return (\n    <RadioGroupPrimitive\n      ref={setRef}\n      data-kl-stretch=\"\"\n      data-kl-layout={layout}\n      value={current}\n      onValueChange={(v, eventDetails) => {\n        setInner(v as string);\n        onValueChange?.(v as string, eventDetails);\n      }}\n      className={resolveClassName(radioStyles.group, className)}\n      {...props}\n      data-slot=\"radio-group\"\n    >\n      <span data-kl-band=\"\" className={radioStyles.band} aria-hidden hidden />\n      {children}\n    </RadioGroupPrimitive>\n  );\n}\n\n/** One row: Base UI's Radio.Root. Compose its contents (a RadioIndicator in a box cell, the label). */\nfunction Radio({ className, ...props }: RadioPrimitive.Root.Props): React.ReactElement {\n  return (\n    <RadioPrimitive.Root\n      data-kl-item=\"\"\n      className={resolveClassName(radioStyles.row, className)}\n      {...props}\n      data-slot=\"radio\"\n    />\n  );\n}\n\n/** Radio, by Base UI's name for the part. */\nconst RadioRoot = Radio;\n\n/** The box: hollow, with a dot while its row is chosen. Kept mounted by default, so the box is always drawn. */\nfunction RadioIndicator({\n  className,\n  keepMounted = true,\n  children,\n  ...props\n}: RadioPrimitive.Indicator.Props): React.ReactElement {\n  return (\n    <RadioPrimitive.Indicator\n      keepMounted={keepMounted}\n      className={resolveClassName(radioStyles.indicator, className)}\n      {...props}\n      data-slot=\"radio-indicator\"\n    >\n      {children ?? <span className={radioStyles.dot} />}\n    </RadioPrimitive.Indicator>\n  );\n}\n\n/**\n * A labelled row: the box cell, the label with an optional description, and an optional meta cell. Once one row has\n * meta, every row keeps the meta column.\n */\nfunction RadioGroupItem({\n  className,\n  label,\n  description,\n  meta,\n  ...props\n}: RadioPrimitive.Root.Props & {\n  value: string;\n  label: React.ReactNode;\n  description?: React.ReactNode;\n  /** Trailing cell: price, count, code. */ meta?: React.ReactNode;\n}): React.ReactElement {\n  const id = React.useId();\n  return (\n    <RadioPrimitive.Root\n      data-kl-item=\"\"\n      aria-labelledby={`${id}-l`}\n      aria-describedby={description ? `${id}-d` : undefined}\n      className={resolveClassName(radioStyles.row, className)}\n      {...props}\n      data-slot=\"radio-group-item\"\n    >\n      <span data-slot=\"radio-group-item-box\" className={choiceStyles.box} aria-hidden>\n        <RadioIndicator />\n      </span>\n      <span data-slot=\"radio-group-item-text\" className={choiceStyles.text}>\n        <span id={`${id}-l`} data-slot=\"radio-group-item-label\" className={choiceStyles.label}>\n          {label}\n        </span>\n        {description ? (\n          <span id={`${id}-d`} data-slot=\"radio-group-item-description\" className={radioStyles.description}>\n            {description}\n          </span>\n        ) : null}\n      </span>\n      {meta != null ? (\n        <span data-slot=\"radio-group-item-meta\" className={radioStyles.meta}>\n          {meta}\n        </span>\n      ) : null}\n    </RadioPrimitive.Root>\n  );\n}\n\nexport { RadioGroup, Radio, RadioRoot, RadioIndicator, RadioGroupItem, radioStyles, type RadioGroupProps };\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/radio-group.tsx"
    }
  ],
  "type": "registry:ui"
}