{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"radio-group","type":"registry:ui","title":"Radio group","description":"Single-choice group with roving focus and a selected dot that glides between options on a spring; card mode turns options into tiles a volt ring slides across.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/geturui/ui/radio-group.tsx","type":"registry:ui","target":"components/ui/radio-group.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion, type Transition } from \"motion/react\";\nimport { AlertCircle, Check } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type RadioSize = \"sm\" | \"md\" | \"lg\";\nexport type RadioVariant = \"default\" | \"card\";\nexport type RadioCardIndicator = \"radio\" | \"check\" | \"none\";\n\nconst ringSize: Record<RadioSize, string> = { sm: \"size-4\", md: \"size-5\", lg: \"size-6\" };\nconst dotSize: Record<RadioSize, string> = { sm: \"size-1.5\", md: \"size-2\", lg: \"size-2.5\" };\nconst lineBox: Record<RadioSize, string> = { sm: \"h-4\", md: \"h-5\", lg: \"h-6\" };\nconst labelText: Record<RadioSize, string> = { sm: \"text-[13px] leading-4\", md: \"text-sm leading-5\", lg: \"text-[15px] leading-6\" };\nconst hintText: Record<RadioSize, string> = { sm: \"text-xs leading-4\", md: \"text-[13px] leading-5\", lg: \"text-sm leading-5\" };\nconst listGap: Record<RadioSize, string> = { sm: \"gap-2.5\", md: \"gap-3\", lg: \"gap-4\" };\nconst cardPad: Record<RadioSize, string> = { sm: \"p-3 gap-2.5\", md: \"p-4 gap-3\", lg: \"p-5 gap-3.5\" };\nconst cardMedia: Record<RadioSize, string> = { sm: \"size-8 rounded-[9px]\", md: \"size-10 rounded-sm\", lg: \"size-11 rounded-sm\" };\n\nconst glide: Transition = { type: \"spring\", stiffness: 520, damping: 34, mass: 0.8 };\nconst soft: Transition = { type: \"spring\", stiffness: 340, damping: 30 };\n\ninterface RadioContextValue {\n  name: string;\n  value: string | null;\n  select: (value: string) => void;\n  size: RadioSize;\n  variant: RadioVariant;\n  indicator: RadioCardIndicator;\n  disabled: boolean;\n  required: boolean;\n  invalid: boolean;\n  /** Prefix for the shared layoutIds (dot / card ring). */\n  layoutKey: string;\n  /** True when the new selection should glide in from a previous one. */\n  glides: boolean;\n}\n\nconst RadioContext = React.createContext<RadioContextValue | null>(null);\n\nexport interface RadioIndicatorProps {\n  checked: boolean;\n  size?: RadioSize;\n  disabled?: boolean;\n  invalid?: boolean;\n  /** Shared layoutId so the filled disc glides between indicators. */\n  layoutId?: string;\n  /** Spring in from a smaller scale on mount instead of appearing. @default true */\n  popIn?: boolean;\n  className?: string;\n}\n\n/**\n * Visual-only radio circle. Place it right after a `peer` radio input to inherit focus and hover styles;\n * reuse it inside table rows or custom cards.\n */\nexport function RadioIndicator({ checked, size = \"md\", disabled, invalid, layoutId, popIn = true, className }: RadioIndicatorProps) {\n  const reduce = useReducedMotion();\n  return (\n    <>\n      <span\n        aria-hidden\n        className={cn(\n          \"pointer-events-none absolute inset-0 rounded-full border transition-[border-color,box-shadow,transform] duration-200 ease-spring\",\n          \"peer-focus-visible:shadow-[var(--focus-ring)] group-active/radio:scale-[0.9]\",\n          checked ? \"border-volt\" : invalid ? \"border-danger bg-surface-sunken\" : \"border-border-strong bg-surface-sunken peer-hover:border-ink-subtle\",\n          disabled && !checked && \"bg-surface-hover\",\n          className,\n        )}\n      />\n      {checked && (\n        <motion.span\n          aria-hidden\n          layoutId={reduce ? undefined : layoutId}\n          initial={popIn ? (reduce ? { opacity: 0 } : { scale: 0.3, opacity: 0 }) : false}\n          animate={{ scale: 1, opacity: 1 }}\n          transition={reduce ? { duration: 0.12 } : glide}\n          className=\"pointer-events-none absolute inset-0 grid place-items-center rounded-full bg-volt\"\n        >\n          <span className={cn(\"rounded-full bg-on-volt\", dotSize[size])} />\n        </motion.span>\n      )}\n    </>\n  );\n}\n\nexport interface RadioGroupProps {\n  /** Visible group label; also names the radiogroup. Use `aria-label` when there is none. */\n  label?: React.ReactNode;\n  \"aria-label\"?: string;\n  /** Helper text under the options. Replaced by `error` when both are set. */\n  hint?: React.ReactNode;\n  /** Error message; any truthy value marks every radio invalid. */\n  error?: React.ReactNode;\n  value?: string | null;\n  defaultValue?: string | null;\n  onValueChange?: (value: string) => void;\n  /** Form field name. Generated when omitted. */\n  name?: string;\n  /** 16 / 20 / 24 px indicator; card padding scales too. @default \"md\" */\n  size?: RadioSize;\n  /** \"card\" renders each option as a selectable tile with a gliding volt ring. @default \"default\" */\n  variant?: RadioVariant;\n  /** Card mode only: the mark in the corner of each card. @default \"check\" */\n  indicator?: RadioCardIndicator;\n  /** Options in a column, or a wrapping row (cards: a responsive grid). @default \"vertical\" */\n  orientation?: \"vertical\" | \"horizontal\";\n  disabled?: boolean;\n  required?: boolean;\n  className?: string;\n  children: React.ReactNode;\n}\n\n/** Single-choice group with roving focus: arrows move and select, and the selected dot glides between options on a spring. */\nexport function RadioGroup({\n  label,\n  \"aria-label\": ariaLabel,\n  hint,\n  error,\n  value,\n  defaultValue = null,\n  onValueChange,\n  name,\n  size = \"md\",\n  variant = \"default\",\n  indicator = \"check\",\n  orientation = \"vertical\",\n  disabled = false,\n  required = false,\n  className,\n  children,\n}: RadioGroupProps) {\n  const auto = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const [own, setOwn] = React.useState<string | null>(defaultValue);\n  const current = value === undefined ? own : value;\n  // Remember the previous selection so the new indicator knows whether to glide or pop in.\n  const [last, setLast] = React.useState<string | null>(current);\n  const [glides, setGlides] = React.useState(false);\n  if (last !== current) {\n    setGlides(last !== null);\n    setLast(current);\n  }\n\n  const root = React.useRef<HTMLDivElement>(null);\n  const invalid = Boolean(error);\n  const message = typeof error === \"boolean\" ? hint : error || hint;\n  const labelId = `rg${auto}-label`;\n  const msgId = message ? `rg${auto}-msg` : undefined;\n\n  const select = React.useCallback(\n    (next: string) => {\n      if (value === undefined) setOwn(next);\n      onValueChange?.(next);\n    },\n    [value, onValueChange],\n  );\n\n  // Roving tabindex: one tab stop on the checked radio, or the first enabled one.\n  React.useLayoutEffect(() => {\n    const inputs = radios(root.current);\n    const enabled = inputs.filter((i) => !i.disabled);\n    const stop = enabled.find((i) => i.checked) ?? enabled[0];\n    inputs.forEach((i) => {\n      i.tabIndex = i === stop ? 0 : -1;\n    });\n  });\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const target = e.target as HTMLElement;\n    if (!(target instanceof HTMLInputElement) || target.type !== \"radio\") return;\n    const enabled = radios(root.current).filter((i) => !i.disabled);\n    const at = enabled.indexOf(target);\n    if (at < 0) return;\n    let next: HTMLInputElement | undefined;\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowRight\") next = enabled[(at + 1) % enabled.length];\n    else if (e.key === \"ArrowUp\" || e.key === \"ArrowLeft\") next = enabled[(at - 1 + enabled.length) % enabled.length];\n    else if (e.key === \"Home\") next = enabled[0];\n    else if (e.key === \"End\") next = enabled[enabled.length - 1];\n    if (!next) return;\n    e.preventDefault();\n    next.focus();\n    select(next.value);\n  };\n\n  const ctx: RadioContextValue = {\n    name: name ?? `rg${auto}`,\n    value: current,\n    select,\n    size,\n    variant,\n    indicator,\n    disabled,\n    required,\n    invalid,\n    layoutKey: `rg${auto}`,\n    glides,\n  };\n\n  const reduce = useReducedMotion();\n  return (\n    <div className={cn(\"grid min-w-0 gap-2.5\", className)}>\n      {label && (\n        <span id={labelId} className=\"text-[13px] font-medium leading-[18px] text-ink\">\n          {label}\n          {required && (\n            <span aria-hidden className=\"ml-0.5 text-volt-ink\">\n              *\n            </span>\n          )}\n        </span>\n      )}\n      <RadioContext.Provider value={ctx}>\n        <div\n          ref={root}\n          role=\"radiogroup\"\n          aria-labelledby={label ? labelId : undefined}\n          aria-label={label ? undefined : ariaLabel}\n          aria-describedby={msgId}\n          aria-invalid={invalid || undefined}\n          aria-required={required || undefined}\n          aria-disabled={disabled || undefined}\n          aria-orientation={orientation}\n          onKeyDown={onKeyDown}\n          className={cn(\n            variant === \"card\"\n              ? cn(\"grid gap-3\", orientation === \"horizontal\" && \"sm:grid-cols-[repeat(auto-fit,minmax(190px,1fr))]\")\n              : orientation === \"horizontal\"\n                ? \"flex flex-wrap gap-x-6 gap-y-3\"\n                : cn(\"grid\", listGap[size]),\n          )}\n        >\n          {children}\n        </div>\n      </RadioContext.Provider>\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        {message && (\n          <motion.p\n            key={invalid && typeof error !== \"boolean\" ? \"error\" : \"hint\"}\n            id={msgId}\n            initial={reduce ? { opacity: 0 } : { opacity: 0, filter: \"blur(4px)\", y: -2 }}\n            animate={{ opacity: 1, filter: \"blur(0px)\", y: 0 }}\n            exit={{ opacity: 0, filter: \"blur(4px)\" }}\n            transition={{ duration: 0.18 }}\n            className={cn(\n              \"m-0 flex items-center gap-1 text-xs font-medium leading-4\",\n              invalid && typeof error !== \"boolean\" ? \"text-danger\" : \"text-ink-subtle\",\n            )}\n          >\n            {invalid && typeof error !== \"boolean\" && <AlertCircle aria-hidden className=\"size-3.5 shrink-0\" />}\n            {message}\n          </motion.p>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nfunction radios(root: HTMLElement | null): HTMLInputElement[] {\n  if (!root) return [];\n  return Array.from(root.querySelectorAll<HTMLInputElement>('input[type=\"radio\"]'));\n}\n\nexport interface RadioProps {\n  value: string;\n  /** Option label (card mode: the card title). */\n  label?: React.ReactNode;\n  /** Supporting line (card mode: the description). Linked with aria-describedby. */\n  hint?: React.ReactNode;\n  disabled?: boolean;\n  /** Accessible name when there is no visible label. */\n  \"aria-label\"?: string;\n  /** Card mode: leading icon, avatar or logo tile. */\n  icon?: React.ReactNode;\n  /** Card mode: inline text after the title, such as a handle or \"per seat\". */\n  meta?: React.ReactNode;\n  /** Card mode: large figure under the title, such as a price. */\n  price?: React.ReactNode;\n  /** Card mode: small pill under the description. */\n  badge?: React.ReactNode;\n  /** Card mode: actions rendered below the card body, outside the click target. */\n  footer?: React.ReactNode;\n  className?: string;\n}\n\n/** One option inside a RadioGroup: a native radio under a drawn indicator, or a selectable card in card mode. */\nexport function Radio({ value, label, hint, disabled: own, \"aria-label\": ariaLabel, icon, meta, price, badge, footer, className }: RadioProps) {\n  const ctx = React.useContext(RadioContext);\n  if (!ctx) throw new Error(\"Radio must be rendered inside a RadioGroup.\");\n  const reduce = useReducedMotion();\n  const auto = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const id = `r${auto}`;\n  const checked = ctx.value === value;\n  const disabled = ctx.disabled || Boolean(own);\n  const labelId = label ? `${id}-label` : undefined;\n  const hintId = hint ? `${id}-hint` : undefined;\n\n  const input = (\n    <input\n      id={id}\n      type=\"radio\"\n      name={ctx.name}\n      value={value}\n      checked={checked}\n      disabled={disabled}\n      required={ctx.required}\n      aria-labelledby={labelId}\n      aria-label={labelId ? undefined : ariaLabel}\n      aria-describedby={hintId}\n      onChange={() => ctx.select(value)}\n      className={cn(\n        ctx.variant === \"card\"\n          ? \"peer absolute size-px overflow-hidden opacity-0\"\n          : \"peer absolute inset-0 m-0 cursor-[inherit] appearance-none rounded-full opacity-0\",\n      )}\n    />\n  );\n\n  if (ctx.variant === \"card\") {\n    return (\n      <motion.div\n        animate={{ y: checked && !reduce ? -2 : 0 }}\n        transition={soft}\n        className={cn(\n          \"relative flex flex-col rounded-md border bg-surface transition-[border-color,background-color,box-shadow] duration-200\",\n          \"has-[input:focus-visible]:shadow-[var(--focus-ring)]\",\n          checked ? \"border-transparent bg-surface-raised shadow-md\" : ctx.invalid ? \"border-danger\" : \"border-border hover:border-border-strong hover:bg-surface-hover\",\n          disabled && \"opacity-45 hover:border-border hover:bg-surface\",\n          className,\n        )}\n      >\n        <label htmlFor={id} className={cn(\"relative flex flex-1 items-start\", cardPad[ctx.size], disabled ? \"cursor-not-allowed\" : \"cursor-pointer\")}>\n          {input}\n          {icon && (\n            <span\n              aria-hidden\n              className={cn(\n                \"grid shrink-0 place-items-center border transition-colors duration-200\",\n                cardMedia[ctx.size],\n                checked ? \"border-volt-ink/40 bg-volt-soft text-volt-ink\" : \"border-border bg-surface-raised text-ink-muted\",\n              )}\n            >\n              {icon}\n            </span>\n          )}\n          <span className={cn(\"grid min-w-0 flex-1 gap-1\", ctx.indicator !== \"none\" && \"pr-7\")}>\n            <span className=\"flex flex-wrap items-baseline gap-x-2 gap-y-0.5\">\n              {label && (\n                <span id={labelId} className={cn(\"font-medium text-ink\", labelText[ctx.size])}>\n                  {label}\n                </span>\n              )}\n              {meta && <span className=\"text-[13px] leading-5 text-ink-subtle\">{meta}</span>}\n            </span>\n            {price && <span className=\"font-display text-2xl font-semibold leading-8 tracking-[-0.5px] text-ink\">{price}</span>}\n            {hint && (\n              <span id={hintId} className={cn(\"text-ink-muted\", hintText[ctx.size])}>\n                {hint}\n              </span>\n            )}\n            {badge && <span className=\"mt-1 flex\">{badge}</span>}\n          </span>\n          {ctx.indicator !== \"none\" && (\n            <span className={cn(\"absolute\", ctx.size === \"sm\" ? \"right-3 top-3\" : \"right-4 top-4\")}>\n              {ctx.indicator === \"radio\" ? (\n                <span className={cn(\"relative inline-grid\", ringSize.sm)}>\n                  <RadioIndicator checked={checked} size=\"sm\" disabled={disabled} invalid={ctx.invalid} />\n                </span>\n              ) : (\n                <CheckMark checked={checked} invalid={ctx.invalid} />\n              )}\n            </span>\n          )}\n        </label>\n        {footer && <div className=\"flex flex-wrap items-center gap-x-4 gap-y-1 border-t border-border px-4 py-2.5 text-[13px] text-ink-muted\">{footer}</div>}\n        {checked && (\n          <motion.span\n            aria-hidden\n            layoutId={reduce ? undefined : `${ctx.layoutKey}-ring`}\n            initial={ctx.glides || reduce ? false : { opacity: 0, scale: 0.98 }}\n            animate={{ opacity: 1, scale: 1 }}\n            transition={soft}\n            className=\"pointer-events-none absolute -inset-px rounded-[inherit] border-2 border-volt-ink shadow-[0_0_0_4px_var(--volt-soft)]\"\n          />\n        )}\n      </motion.div>\n    );\n  }\n\n  return (\n    <label\n      htmlFor={id}\n      className={cn(\"group/radio flex items-start gap-2.5\", disabled ? \"cursor-not-allowed opacity-45\" : \"cursor-pointer\", className)}\n    >\n      <span className={cn(\"flex shrink-0 items-center\", lineBox[ctx.size])}>\n        <span className={cn(\"relative inline-grid\", ringSize[ctx.size])}>\n          {input}\n          <RadioIndicator\n            checked={checked}\n            size={ctx.size}\n            disabled={disabled}\n            invalid={ctx.invalid}\n            layoutId={`${ctx.layoutKey}-dot`}\n            popIn={!ctx.glides}\n          />\n        </span>\n      </span>\n      {(label || hint) && (\n        <span className=\"grid min-w-0 gap-0.5\">\n          {label && (\n            <span id={labelId} className={cn(\"font-medium text-ink\", labelText[ctx.size])}>\n              {label}\n            </span>\n          )}\n          {hint && (\n            <span id={hintId} className={cn(\"text-ink-muted\", hintText[ctx.size])}>\n              {hint}\n            </span>\n          )}\n        </span>\n      )}\n    </label>\n  );\n}\n\nfunction CheckMark({ checked, invalid }: { checked: boolean; invalid: boolean }) {\n  const reduce = useReducedMotion();\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        \"relative grid size-5 place-items-center rounded-full border transition-[background-color,border-color] duration-200\",\n        checked ? \"border-volt bg-volt text-on-volt\" : invalid ? \"border-danger bg-surface-sunken\" : \"border-border-strong bg-surface-sunken\",\n      )}\n    >\n      <AnimatePresence initial={false}>\n        {checked && (\n          <motion.span\n            initial={reduce ? { opacity: 0 } : { scale: 0.2, opacity: 0, rotate: -30 }}\n            animate={{ scale: 1, opacity: 1, rotate: 0 }}\n            exit={{ scale: 0.4, opacity: 0 }}\n            transition={reduce ? { duration: 0.12 } : glide}\n            className=\"grid place-items-center\"\n          >\n            <Check className=\"size-3\" strokeWidth={3} />\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </span>\n  );\n}\n"},{"path":"LICENSE-geturui.md","type":"registry:file","target":"LICENSE-geturui.md","content":"MIT License\n\nCopyright (c) 2026 geturui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"}],"categories":["components","radio","form","radio group","radio cards","plan picker","choice"],"meta":{"tier":"free","license":"MIT","docs":"https://geturui.com/docs/radio-group"}}