{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radio-group",
  "type": "registry:ui",
  "title": "Radio Group",
  "description": "One choice from a few visible options: native radio inputs in a fieldset with a legend, hint and error, form-ready without script.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/radio-group.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/radio-group.tsx",
      "content": "import { createContext, forwardRef, useContext, useId, useState, type InputHTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../lib/utils';\n\ninterface Ctx {\n  name: string;\n  value: string;\n  setValue: (v: string) => void;\n  disabled?: boolean;\n  invalid?: boolean;\n}\nconst RadioCtx = createContext<Ctx | null>(null);\n\nexport interface RadioGroupProps {\n  /** Required: the question the options answer. It names the group for assistive tech. */\n  legend: ReactNode;\n  /** The form field name. Radios sharing a name are one group to the browser. */\n  name?: string;\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  disabled?: boolean;\n  invalid?: boolean;\n  hint?: ReactNode;\n  className?: string;\n  children: ReactNode;\n}\n\n/**\n * One choice from a few, all visible. It is built on native radio inputs, so the arrow keys, the single tab stop and\n * form submission (even without script) are the browser's own. A fieldset and legend name the group.\n */\nexport function RadioGroup({ legend, name, value, defaultValue, onValueChange, disabled, invalid, hint, className, children }: RadioGroupProps) {\n  const auto = useId();\n  const [own, setOwn] = useState(defaultValue ?? '');\n  const current = value ?? own;\n  const hintId = hint ? `${auto}-h` : undefined;\n  return (\n    <fieldset role=\"radiogroup\" disabled={disabled} aria-describedby={hintId} aria-invalid={invalid || undefined} className={cn('m-0 flex min-w-0 flex-col gap-1 border-0 p-0', className)}>\n      <legend className=\"mb-1 p-0 text-kh-small font-medium text-kh-ink\">{legend}</legend>\n      <RadioCtx.Provider value={{ name: name ?? auto, value: current, setValue: (v) => { setOwn(v); onValueChange?.(v); }, disabled, invalid }}>\n        {children}\n      </RadioCtx.Provider>\n      {hint && <p id={hintId} className={cn('text-kh-small', invalid ? 'text-kh-danger' : 'text-kh-muted')}>{hint}</p>}\n    </fieldset>\n  );\n}\n\nexport interface RadioProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'name' | 'checked' | 'defaultChecked' | 'value' | 'onChange'> {\n  value: string;\n  label: ReactNode;\n  hint?: ReactNode;\n}\n\n/** One option inside a RadioGroup, with its label in a 44 px row. */\nexport const Radio = forwardRef<HTMLInputElement, RadioProps>(function Radio({ value, label, hint, className, id, ...rest }, ref) {\n  const ctx = useContext(RadioCtx);\n  if (!ctx) throw new Error('Radio must sit inside a RadioGroup');\n  const auto = useId();\n  const rid = id ?? auto;\n  return (\n    <div className=\"flex flex-col\">\n      <label htmlFor={rid} className=\"flex min-h-11 cursor-pointer items-center gap-3 text-kh-body text-kh-ink has-[:disabled]:cursor-not-allowed has-[:disabled]:text-kh-muted\">\n        <input\n          ref={ref}\n          id={rid}\n          type=\"radio\"\n          name={ctx.name}\n          value={value}\n          checked={ctx.value === value}\n          onChange={() => ctx.setValue(value)}\n          aria-describedby={hint ? `${rid}-h` : undefined}\n          className={cn(\n            'size-5 shrink-0 cursor-pointer appearance-none rounded-full border border-kh-line-strong bg-kh-surface shadow-kh-1',\n            'transition-[border-color] duration-(--kh-dur) hover:border-kh-muted checked:border-kh-ink checked:bg-[radial-gradient(circle,var(--kh-ink)_0_42%,transparent_46%)]',\n            'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus) disabled:cursor-not-allowed disabled:opacity-50',\n            ctx.invalid && 'border-kh-danger',\n            className,\n          )}\n          {...rest}\n        />\n        <span>{label}</span>\n      </label>\n      {hint && <p id={`${rid}-h`} className=\"pl-8 text-kh-small text-kh-muted\">{hint}</p>}\n    </div>\n  );\n});\n"
    }
  ]
}
