{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink/radio-group",
  "title": "Radio Group",
  "description": "Mutually exclusive radio button group",
  "dependencies": [
    "ink"
  ],
  "registryDependencies": [
    "https://termcn.dev/r/ink/interaction.json",
    "https://termcn.dev/r/ink/terminal-symbols.json",
    "https://termcn.dev/r/ink/use-theme.json",
    "https://termcn.dev/r/ink/use-unicode.json"
  ],
  "files": [
    {
      "path": "registry/ui/radio-group.tsx",
      "content": "import { Box, Text } from \"ink\";\nimport React, { useState } from \"react\";\n\nimport { useInteraction } from \"@/hooks/use-interaction\";\nimport { useTheme } from \"@/hooks/use-theme\";\nimport { useUnicode } from \"@/hooks/use-unicode\";\nimport { resolveTerminalSymbol } from \"@/lib/terminal-symbols\";\n\nexport interface RadioOption<T = string> {\n  value: T;\n  label: string;\n  hint?: string;\n  disabled?: boolean;\n}\n\nexport interface RadioGroupProps<T = string> {\n  options: RadioOption<T>[];\n  value?: T;\n  defaultValue?: T;\n  onValueChange?: (value: T) => void;\n  onChange?: (value: T) => void;\n  name?: string;\n  cursor?: string;\n  id?: string;\n  autoFocus?: boolean;\n  isActive?: boolean;\n  disabled?: boolean;\n  \"aria-label\"?: string;\n}\n\nconst getOptionColor = (\n  disabled: boolean | undefined,\n  isHighlighted: boolean,\n  theme: ReturnType<typeof useTheme>\n): string => {\n  if (disabled) {\n    return theme.colors.mutedForeground;\n  }\n  if (isHighlighted) {\n    return theme.colors.primary;\n  }\n  return theme.colors.foreground;\n};\n\nexport const RadioGroup = <T = string,>({\n  options,\n  value: controlledValue,\n  defaultValue,\n  onValueChange,\n  onChange,\n  name,\n  cursor,\n  id,\n  autoFocus = false,\n  isActive = true,\n  disabled = false,\n  \"aria-label\": ariaLabel,\n}: RadioGroupProps<T>) => {\n  const theme = useTheme();\n  const unicode = useUnicode();\n  const resolvedCursor = cursor ?? resolveTerminalSymbol(unicode, \"›\", \">\");\n  const [activeIndex, setActiveIndex] = useState(() => {\n    if (controlledValue === undefined) {\n      return 0;\n    }\n    const idx = options.findIndex((o) => o.value === controlledValue);\n    return Math.max(idx, 0);\n  });\n  const [internalValue, setInternalValue] = useState<T | undefined>(\n    defaultValue\n  );\n\n  const selected = controlledValue ?? internalValue;\n\n  const select = (idx: number) => {\n    const opt = options[idx];\n    if (!opt || opt.disabled) {\n      return;\n    }\n    if (controlledValue === undefined) {\n      setInternalValue(opt.value);\n    }\n    (onValueChange ?? onChange)?.(opt.value);\n  };\n\n  const { isFocused } = useInteraction(\n    (input, key) => {\n      if (key.upArrow) {\n        setActiveIndex((i) => {\n          let next = i - 1;\n          while (next >= 0 && options[next]?.disabled) {\n            next -= 1;\n          }\n          return next < 0 ? i : next;\n        });\n      } else if (key.downArrow) {\n        setActiveIndex((i) => {\n          let next = i + 1;\n          while (next < options.length && options[next]?.disabled) {\n            next += 1;\n          }\n          return next >= options.length ? i : next;\n        });\n      } else if (key.home) {\n        const firstEnabled = options.findIndex((option) => !option.disabled);\n        if (firstEnabled !== -1) {\n          setActiveIndex(firstEnabled);\n        }\n      } else if (key.end) {\n        const lastEnabled = options.findLastIndex((option) => !option.disabled);\n        if (lastEnabled !== -1) {\n          setActiveIndex(lastEnabled);\n        }\n      } else if (input === \" \" || key.return) {\n        select(activeIndex);\n      }\n    },\n    { autoFocus, disabled, id, isActive }\n  );\n\n  return (\n    <Box\n      aria-role=\"radiogroup\"\n      aria-state={{ disabled }}\n      flexDirection=\"column\"\n    >\n      <Text\n        aria-label={ariaLabel ?? name ?? \"Radio group\"}\n        bold={Boolean(name)}\n      >\n        {name ?? \"\"}\n      </Text>\n      {options.map((opt, idx) => {\n        const isActive = idx === activeIndex;\n        const isSelected = selected !== undefined && opt.value === selected;\n        const icon = isSelected\n          ? resolveTerminalSymbol(unicode, \"◉\", \"(*)\")\n          : resolveTerminalSymbol(unicode, \"○\", \"( )\");\n\n        return (\n          <Box\n            key={idx}\n            aria-label={opt.hint ? `${opt.label}: ${opt.hint}` : opt.label}\n            aria-role=\"radio\"\n            aria-state={{\n              checked: isSelected,\n              disabled: disabled || opt.disabled,\n            }}\n            gap={1}\n          >\n            <Text\n              aria-hidden\n              color={isActive ? theme.colors.primary : undefined}\n            >\n              {isActive ? resolvedCursor : \" \"}\n            </Text>\n            <Text\n              aria-hidden\n              color={getOptionColor(opt.disabled, isSelected, theme)}\n              dimColor={opt.disabled}\n            >\n              {icon}\n            </Text>\n            <Text\n              aria-hidden\n              color={getOptionColor(opt.disabled, isActive, theme)}\n              bold={isActive || isSelected}\n              dimColor={opt.disabled}\n            >\n              {opt.label}\n            </Text>\n            {opt.hint && (\n              <Text aria-hidden color={theme.colors.mutedForeground} dimColor>\n                {opt.hint}\n              </Text>\n            )}\n          </Box>\n        );\n      })}\n    </Box>\n  );\n};\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "selection"
  ],
  "type": "registry:ui"
}