{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"radio-group","type":"registry:ui","title":"Radio Group","description":"Native radio group restyled with a springy dot and ripple, plus a card variant whose selection outline slides between options. Arrow keys just work.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/radio-group.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { createContext, useContext, useId, useState, type HTMLAttributes, type ReactNode } from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\n// Native radios (same `name`) give arrow-key navigation, roving tab stop and form\n// submission for free; we only restyle them and animate the selection.\nconst css = `\n@keyframes ui-radio-ripple{from{opacity:.55;scale:1}to{opacity:0;scale:2.4}}\n.ui-radio:checked~.ui-radio-ripple{animation:ui-radio-ripple .5s ease-out}\n@media (prefers-reduced-motion:reduce){.ui-radio:checked~.ui-radio-ripple{animation:none}}\n`;\n\ntype Ctx = {\n  name: string;\n  value: string | undefined;\n  select: (v: string) => void;\n  variant: \"default\" | \"card\";\n  disabled: boolean;\n  required: boolean;\n  indicatorId: string;\n};\nconst RadioContext = createContext<Ctx | null>(null);\n\nexport interface RadioGroupProps extends Omit<HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\"> {\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  /** Form field name. Auto-generated if omitted. */\n  name?: string;\n  /** `card` renders each option as a selectable card with a sliding outline. */\n  variant?: \"default\" | \"card\";\n  orientation?: \"vertical\" | \"horizontal\";\n  disabled?: boolean;\n  required?: boolean;\n}\n\nexport function RadioGroup({\n  value,\n  defaultValue,\n  onValueChange,\n  name,\n  variant = \"default\",\n  orientation = \"vertical\",\n  disabled = false,\n  required = false,\n  className,\n  children,\n  ...props\n}: RadioGroupProps) {\n  const [inner, setInner] = useState(defaultValue);\n  const id = useId();\n  const current = value ?? inner;\n  const select = (v: string) => {\n    if (value === undefined) setInner(v);\n    onValueChange?.(v);\n  };\n  return (\n    <RadioContext value={{ name: name ?? id, value: current, select, variant, disabled, required, indicatorId: `${id}-indicator` }}>\n      <style href=\"ui-radio-group\" precedence=\"default\">\n        {css}\n      </style>\n      <div\n        {...props}\n        role=\"radiogroup\"\n        aria-orientation={orientation}\n        aria-disabled={disabled || undefined}\n        className={cn(\n          \"grid\",\n          variant === \"card\" ? \"gap-3\" : \"gap-3.5\",\n          orientation === \"horizontal\" && (variant === \"card\" ? \"auto-cols-fr grid-flow-col\" : \"grid-flow-col justify-start gap-6\"),\n          className,\n        )}\n      >\n        {children}\n      </div>\n    </RadioContext>\n  );\n}\n\nexport interface RadioGroupItemProps {\n  value: string;\n  label?: ReactNode;\n  description?: ReactNode;\n  /** Card variant: leading icon. */\n  icon?: ReactNode;\n  disabled?: boolean;\n  className?: string;\n  children?: ReactNode;\n}\n\nexport function RadioGroupItem({ value, label, description, icon, disabled: itemDisabled, className, children }: RadioGroupItemProps) {\n  const ctx = useContext(RadioContext);\n  if (!ctx) throw new Error(\"<RadioGroupItem> must be rendered inside <RadioGroup>.\");\n  const reduce = useReducedMotion();\n  const id = useId();\n  const checked = ctx.value === value;\n  const disabled = ctx.disabled || !!itemDisabled;\n  const card = ctx.variant === \"card\";\n\n  const radio = (\n    <span className=\"relative grid size-5 shrink-0 place-items-center\">\n      <input\n        type=\"radio\"\n        id={id}\n        name={ctx.name}\n        value={value}\n        checked={checked}\n        disabled={disabled}\n        required={ctx.required}\n        aria-describedby={description ? `${id}-d` : undefined}\n        onChange={() => ctx.select(value)}\n        className={cn(\n          \"ui-radio peer absolute inset-0 m-0 cursor-pointer appearance-none rounded-full border border-input bg-background shadow-xs outline-none\",\n          \"transition-[border-color,box-shadow] duration-200 hover:border-primary/60 checked:border-primary\",\n          \"focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed\",\n        )}\n      />\n      <span\n        aria-hidden\n        className=\"pointer-events-none size-2.5 scale-0 rounded-full bg-primary transition-[scale] duration-300 ease-[cubic-bezier(.3,1.8,.5,1)] peer-checked:scale-100 motion-reduce:transition-none\"\n      />\n      <span aria-hidden className=\"ui-radio-ripple pointer-events-none absolute inset-0 rounded-full bg-primary/40 opacity-0\" />\n    </span>\n  );\n\n  const text = (label || description || children) && (\n    <span className=\"grid gap-0.5 text-sm leading-5\">\n      {label && <span className=\"font-medium text-foreground\">{label}</span>}\n      {description && (\n        <span id={`${id}-d`} className=\"text-muted-foreground\">\n          {description}\n        </span>\n      )}\n      {children}\n    </span>\n  );\n\n  if (!card) {\n    return (\n      <label\n        htmlFor={id}\n        className={cn(\"flex cursor-pointer items-start gap-3 select-none\", disabled && \"cursor-not-allowed opacity-50\", className)}\n      >\n        {radio}\n        {text}\n      </label>\n    );\n  }\n\n  return (\n    <label\n      htmlFor={id}\n      className={cn(\n        \"relative flex cursor-pointer items-start gap-3 rounded-xl border border-border bg-card p-4 select-none\",\n        \"transition-[border-color,background-color,scale] duration-200 hover:bg-muted/50 active:scale-[0.99]\",\n        \"has-focus-visible:ring-[3px] has-focus-visible:ring-ring/50\",\n        disabled && \"cursor-not-allowed opacity-50\",\n        className,\n      )}\n    >\n      {checked && (\n        <motion.span\n          aria-hidden\n          layoutId={ctx.indicatorId}\n          transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 34 }}\n          className=\"pointer-events-none absolute -inset-px rounded-[inherit] border-2 border-primary bg-primary/6\"\n        />\n      )}\n      {icon && (\n        <span\n          aria-hidden\n          className={cn(\n            \"relative grid size-9 shrink-0 place-items-center rounded-lg bg-muted text-muted-foreground transition-colors duration-200 [&_svg]:size-4.5\",\n            checked && \"bg-primary/15 text-primary\",\n          )}\n        >\n          {icon}\n        </span>\n      )}\n      <span className=\"relative flex-1\">{text}</span>\n      <span className=\"relative\">{radio}</span>\n    </label>\n  );\n}\n"}]}