{"$schema":"https:\/\/ui.shadcn.com\/schema\/registry-item.json","name":"radio","type":"registry:component","title":"Radio Group","description":"Single-select choice control with a gliding layoutId indicator dot and spring press feedback.","author":"Saurabh <saurabh10102@gmail.com>","dependencies":["clsx","motion","tailwind-merge"],"registryDependencies":[],"docs":"Radio Group: usage, props and types at https:\/\/beui.dev\/components\/motion\/radio.md","files":[{"path":"components\/motion\/radio.tsx","type":"registry:component","target":"@components\/motion\/radio.tsx","content":"\"use client\";\n\/\/ beui.dev\/components\/motion\/radio\n\nimport { motion, MotionConfig, useReducedMotion } from \"motion\/react\";\nimport {\n  createContext,\n  type KeyboardEvent,\n  useCallback,\n  useContext,\n  useId,\n  useLayoutEffect,\n  useMemo,\n  useState,\n  type ReactNode,\n} from \"react\";\nimport { SPRING_LAYOUT, SPRING_PRESS } from \"@\/lib\/ease\";\nimport { cn } from \"@\/lib\/utils\";\n\ntype RadioCtx = {\n  value: string;\n  setValue: (value: string) => void;\n  layoutId: string;\n  \/**\n   * The one option Tab reaches: the selected option, or the first enabled one\n   * when nothing enabled is selected. `null` until the options have\n   * registered, when every enabled option stays reachable.\n   *\/\n  tabStop: string | null;\n  register: (value: string, disabled: boolean) => void;\n  unregister: (value: string) => void;\n};\n\nconst RadioCtx = createContext<RadioCtx | null>(null);\n\nfunction useRadioGroup() {\n  const ctx = useContext(RadioCtx);\n  if (!ctx) {\n    throw new Error(\"RadioGroupItem must be used inside <RadioGroup>\");\n  }\n  return ctx;\n}\n\nexport interface RadioGroupProps {\n  \/** The selected value, for controlled use. *\/\n  value?: string;\n  \/** The initial value when uncontrolled. Default: \"\" *\/\n  defaultValue?: string;\n  \/** Called with the item's value when the selection changes. *\/\n  onValueChange?: (value: string) => void;\n  children: ReactNode;\n  \/** Classes merged onto the root element. *\/\n  className?: string;\n  \/** Stacks items in a column or wraps them in a row. Default: \"vertical\" *\/\n  orientation?: \"vertical\" | \"horizontal\";\n  \/** Accessible name for the group when no visible label names it. *\/\n  \"aria-label\"?: string;\n  \/** Id of a visible element that names the group. *\/\n  \"aria-labelledby\"?: string;\n}\n\nexport function RadioGroup({\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  children,\n  className,\n  orientation = \"vertical\",\n  \"aria-label\": ariaLabel,\n  \"aria-labelledby\": ariaLabelledBy,\n}: RadioGroupProps) {\n  const [internal, setInternal] = useState(defaultValue);\n  const layoutId = useId();\n  const reduce = useReducedMotion();\n  const controlled = value !== undefined;\n  const current = controlled ? value : internal;\n  const setValue = useCallback(\n    (next: string) => {\n      if (!controlled) setInternal(next);\n      onValueChange?.(next);\n    },\n    [controlled, onValueChange],\n  );\n  const [options, setOptions] = useState<Map<string, boolean>>(new Map());\n  const register = useCallback((option: string, disabled: boolean) => {\n    setOptions((map) =>\n      map.get(option) === disabled ? map : new Map(map).set(option, disabled),\n    );\n  }, []);\n  const unregister = useCallback((option: string) => {\n    setOptions((map) => {\n      if (!map.has(option)) return map;\n      const next = new Map(map);\n      next.delete(option);\n      return next;\n    });\n  }, []);\n  \/\/ Resolved during render so the group has exactly one tab stop in the same\n  \/\/ commit that changes the selection or the options.\n  let tabStop: string | null = null;\n  if (options.size > 0) {\n    const enabled = Array.from(options).filter(([, disabled]) => !disabled);\n    tabStop = enabled.some(([option]) => option === current)\n      ? current\n      : (enabled[0]?.[0] ?? \"\");\n  }\n  const contextValue = useMemo(\n    () => ({ value: current, setValue, layoutId, tabStop, register, unregister }),\n    [current, layoutId, setValue, tabStop, register, unregister],\n  );\n\n  return (\n    <MotionConfig transition={reduce ? { duration: 0 } : SPRING_LAYOUT}>\n      <RadioCtx.Provider value={contextValue}>\n        <div\n          role=\"radiogroup\"\n          aria-label={ariaLabel}\n          aria-labelledby={ariaLabelledBy}\n          className={cn(\n            \"flex gap-3\",\n            orientation === \"vertical\" ? \"flex-col\" : \"flex-row flex-wrap\",\n            className,\n          )}\n        >\n          {children}\n        <\/div>\n      <\/RadioCtx.Provider>\n    <\/MotionConfig>\n  );\n}\n\nexport interface RadioGroupItemProps {\n  \/** The value the group takes when this item is picked. *\/\n  value: string;\n  \/** Text shown beside the radio, used as its name. *\/\n  label?: string;\n  \/** Supporting text under the label, announced as the description rather than the name. *\/\n  description?: string;\n  \/** Dims the item and stops it from being picked. *\/\n  disabled?: boolean;\n  \/** Classes merged onto the item's label element. *\/\n  className?: string;\n  \/** Id for the radio button. Default: a generated id *\/\n  id?: string;\n}\n\nexport function RadioGroupItem({\n  value,\n  label,\n  description,\n  disabled,\n  className,\n  id: idProp,\n}: RadioGroupItemProps) {\n  const {\n    value: groupValue,\n    setValue,\n    layoutId,\n    tabStop,\n    register,\n    unregister,\n  } = useRadioGroup();\n  const autoId = useId();\n  const id = idProp ?? autoId;\n  const reduce = useReducedMotion();\n  const selected = groupValue === value;\n  const descriptionId = description ? `${id}-description` : undefined;\n  \/\/ The wrapping <label> would fold the description into the name, so name from the label text alone.\n  const labelId = description && label ? `${id}-label` : undefined;\n\n  useLayoutEffect(() => {\n    register(value, Boolean(disabled));\n  }, [register, value, disabled]);\n  useLayoutEffect(() => () => unregister(value), [unregister, value]);\n\n  const reachable =\n    !disabled && (tabStop === null ? true : tabStop === value);\n\n  \/\/ Arrow keys move to the next enabled option in the group, wrapping at the\n  \/\/ ends, and select it as focus arrives, like native radio buttons.\n  const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n    const step =\n      event.key === \"ArrowDown\" || event.key === \"ArrowRight\"\n        ? 1\n        : event.key === \"ArrowUp\" || event.key === \"ArrowLeft\"\n          ? -1\n          : 0;\n    if (!step) return;\n    const group = event.currentTarget.closest('[role=\"radiogroup\"]');\n    const radios = Array.from(\n      group?.querySelectorAll<HTMLButtonElement>('[role=\"radio\"]') ?? [],\n    ).filter(\n      (radio) =>\n        !radio.disabled &&\n        radio.closest('[role=\"radiogroup\"]') === group,\n    );\n    const at = radios.indexOf(event.currentTarget);\n    if (at < 0 || radios.length < 2) return;\n    event.preventDefault();\n    const next = radios[(at + step + radios.length) % radios.length];\n    next.focus();\n    next.click();\n  };\n\n  return (\n    <label\n      htmlFor={id}\n      className={cn(\n        \"inline-flex gap-3\",\n        description ? \"items-start\" : \"items-center\",\n        disabled ? \"cursor-not-allowed\" : \"cursor-pointer\",\n        className,\n      )}\n    >\n      <motion.button\n        id={id}\n        type=\"button\"\n        role=\"radio\"\n        aria-checked={selected}\n        aria-labelledby={labelId}\n        aria-describedby={descriptionId}\n        disabled={disabled}\n        tabIndex={reachable ? 0 : -1}\n        onClick={() => !disabled && setValue(value)}\n        onKeyDown={onKeyDown}\n        whileTap={reduce || disabled ? undefined : { scale: 0.92 }}\n        transition={SPRING_PRESS}\n        data-state={selected ? \"checked\" : \"unchecked\"}\n        className={cn(\n          \"relative inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 outline-none transition-colors duration-200\",\n          \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n          \"disabled:cursor-not-allowed disabled:opacity-60\",\n          selected\n            ? \"border-primary\"\n            : \"border-muted-foreground\/50 hover:border-muted-foreground\",\n        )}\n      >\n        {selected ? (\n          <motion.span\n            layoutId={layoutId}\n            className=\"absolute inset-1 rounded-full bg-primary\"\n            transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n          \/>\n        ) : null}\n      <\/motion.button>\n      {label || description ? (\n        <span className={cn(\"flex min-w-0 flex-col gap-0.5 select-none\", disabled && \"opacity-60\")}>\n          {label ? (\n            <span\n              id={labelId}\n              \/\/ Geist sits low in a 20px line; a 16px line lifts the text onto the control.\n              className={cn(\"text-sm text-foreground\", description && \"leading-4\")}\n            >\n              {label}\n            <\/span>\n          ) : null}\n          {description ? (\n            <span id={descriptionId} className=\"text-xs text-muted-foreground\">\n              {description}\n            <\/span>\n          ) : null}\n        <\/span>\n      ) : null}\n    <\/label>\n  );\n}\n"},{"path":"lib\/ease.ts","type":"registry:lib","target":"@lib\/ease.ts","content":"\/\/ Shared motion tokens. Easing curves mirror the CSS custom properties in\n\/\/ globals.css; springs are the canonical physics used across components.\n\/\/ Strong custom variants - defaults like `ease-in`\/`ease-out` feel weak.\n\nexport const EASE_OUT = [0.16, 1, 0.3, 1] as const;\n\/** Accelerating curve for things that fall (a dropped ball, a toppled block). Not for UI entrances. *\/\nexport const EASE_IN = [0.55, 0, 1, 0.45] as const;\nexport const EASE_IN_OUT = [0.77, 0, 0.175, 1] as const;\nexport const EASE_DRAWER = [0.32, 0.72, 0, 1] as const;\n\n\/** CSS string form of EASE_OUT for inline style transitions. *\/\nexport const EASE_OUT_CSS = \"cubic-bezier(0.16, 1, 0.3, 1)\";\n\n\/** Press feedback on buttons and other tappable surfaces. *\/\nexport const SPRING_PRESS = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 30,\n  mass: 0.6,\n} as const;\n\n\/** Content swaps - label\/icon slots trading places inside a control. *\/\nexport const SPRING_SWAP = {\n  type: \"spring\",\n  stiffness: 460,\n  damping: 30,\n  mass: 0.55,\n} as const;\n\n\/** Overlay panel entrances - modals and sheets summoned by pointer. *\/\nexport const SPRING_PANEL = {\n  type: \"spring\",\n  stiffness: 420,\n  damping: 40,\n  mass: 0.5,\n} as const;\n\n\/** Shared-layout glides - pills, indicators and panels morphing between positions. *\/\nexport const SPRING_LAYOUT = {\n  type: \"spring\",\n  stiffness: 360,\n  damping: 32,\n  mass: 0.6,\n} as const;\n\n\/** Cursor-follow physics for decorative mouse tracking (magnetic, tilt, dock). *\/\nexport const SPRING_MOUSE = {\n  stiffness: 200,\n  damping: 15,\n  mass: 0.3,\n} as const;\n\n\/** Dragged handles and fills (sliders) - critically damped `useSpring` config,\n * so the value follows the pointer butterily and never rebounds off an end. *\/\nexport const SPRING_GLIDE = {\n  stiffness: 700,\n  damping: 50,\n  mass: 0.5,\n} as const;\n\n\/** Shared-surface morphs: a trigger growing into its panel and back on one\n * weighted spring, so opening and closing travel the same path. *\/\nexport const SPRING_MORPH = {\n  type: \"spring\",\n  duration: 0.5,\n  bounce: 0.22,\n} as const;\n"},{"path":"lib\/utils.ts","type":"registry:lib","target":"@lib\/utils.ts","content":"import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs))\n}\n"}]}