{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"goo-radio","type":"registry:ui","title":"Goo Radio","description":"A radio group with one gooey dot that stretches as it slides to the new option, splats on landing and jiggles back into shape.","dependencies":["motion"],"registryDependencies":[],"files":[{"path":"registry/ui/goo-radio.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport { animate, motion, useMotionValue, useReducedMotion, useTransform, useVelocity } from \"motion/react\";\n\nexport interface GooRadioOption {\n  value: string;\n  label: string;\n  description?: string;\n}\n\nexport interface GooRadioProps {\n  options?: GooRadioOption[];\n  /** Controlled selected value. */\n  value?: string;\n  /** Initial value when uncontrolled. */\n  defaultValue?: string;\n  /** Called with the newly selected value. */\n  onValueChange?: (value: string) => void;\n  /** Group label, shown above the options. */\n  label?: string;\n  /** Form field name for the native radios. */\n  name?: string;\n  /** Dot and ring color. */\n  color?: string;\n  /** How wobbly the dot is, 0-1. */\n  wobble?: number;\n  className?: string;\n}\n\nconst defaultOptions: GooRadioOption[] = [\n  { value: \"starter\", label: \"Starter\", description: \"For side projects\" },\n  { value: \"pro\", label: \"Pro\", description: \"For growing teams\" },\n  { value: \"enterprise\", label: \"Enterprise\", description: \"SSO, audit logs, SLA\" },\n];\n\nconst DOT = 12;\n\nexport function GooRadio({\n  options = defaultOptions,\n  value,\n  defaultValue = \"pro\",\n  onValueChange,\n  label = \"Plan\",\n  name,\n  color = \"#fb7185\",\n  wobble = 0.6,\n  className,\n}: GooRadioProps) {\n  const [inner, setInner] = useState(defaultValue);\n  const current = value ?? inner;\n  const idx = options.findIndex((o) => o.value === current);\n  const autoName = useId();\n  const labelId = useId();\n  const reduce = useReducedMotion();\n\n  const rings = useRef<(HTMLSpanElement | null)[]>([]);\n  const blob = useRef<HTMLSpanElement>(null);\n  const placed = useRef(false);\n  const x = useMotionValue(0);\n  const visible = useMotionValue(0);\n\n  const y = useMotionValue(0);\n  const vy = useVelocity(y);\n  // Stretch along the direction of travel, thin out sideways (area stays roughly constant).\n  const scaleY = useTransform(vy, (v) => 1 + Math.min(Math.abs(v), 2200) / 1500);\n  const scaleX = useTransform(scaleY, (s) => 1 / Math.sqrt(s));\n\n  useEffect(() => {\n    const ring = rings.current[idx];\n    if (!ring) return;\n    const ty = ring.offsetTop + (ring.offsetHeight - DOT) / 2;\n    const tx = ring.offsetLeft + (ring.offsetWidth - DOT) / 2;\n    if (!placed.current || reduce) {\n      // Next frame: values set before Motion has mounted the element never reach the DOM.\n      const id = requestAnimationFrame(() => {\n        x.set(tx);\n        y.set(ty);\n        visible.set(1);\n        placed.current = true;\n      });\n      return () => cancelAnimationFrame(id);\n    }\n    x.set(tx);\n    const travel = Math.abs(ty - y.get());\n    animate(y, ty, { type: \"spring\", stiffness: 340, damping: 26 - 14 * wobble, mass: 1 });\n    // Splat on landing, then jiggle back into a circle.\n    if (blob.current)\n      animate(\n        blob.current,\n        { scaleX: [1, 1, 1 + 0.5 * wobble, 1 - 0.18 * wobble, 1 + 0.08 * wobble, 1], scaleY: [1, 1, 1 - 0.4 * wobble, 1 + 0.2 * wobble, 1 - 0.06 * wobble, 1] },\n        { duration: 0.35 + travel / 900, times: [0, 0.42, 0.55, 0.72, 0.86, 1], ease: \"easeOut\" },\n      );\n  }, [idx, reduce, wobble, options.length, x, y, visible]);\n\n  return (\n    <div\n      role=\"radiogroup\"\n      aria-labelledby={labelId}\n      className={`relative grid w-72 gap-1 rounded-2xl border border-border bg-card p-2 text-foreground shadow-xl ${className ?? \"\"}`}\n    >\n      <p id={labelId} className=\"px-3 pb-1 pt-2 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground\">\n        {label}\n      </p>\n      {options.map((o, i) => {\n        const on = i === idx;\n        return (\n          <label\n            key={o.value}\n            className=\"flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2.5 transition-colors hover:bg-muted/60\"\n          >\n            <input\n              type=\"radio\"\n              name={name ?? autoName}\n              value={o.value}\n              checked={on}\n              onChange={() => {\n                setInner(o.value);\n                onValueChange?.(o.value);\n              }}\n              className=\"peer sr-only\"\n            />\n            <motion.span\n              ref={(el) => {\n                rings.current[i] = el;\n              }}\n              aria-hidden\n              className=\"size-[22px] shrink-0 rounded-full border-2 transition-colors duration-200 peer-focus-visible:ring-[3px] peer-focus-visible:ring-ring/60 peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-card\"\n              style={{ borderColor: on ? color : \"var(--border)\" }}\n              whileTap={{ scale: 0.85 }}\n            />\n            <span className=\"grid leading-tight\">\n              <span className=\"text-sm font-medium\">{o.label}</span>\n              {o.description && <span className=\"text-xs text-muted-foreground\">{o.description}</span>}\n            </span>\n          </label>\n        );\n      })}\n      <motion.span\n        aria-hidden\n        className=\"pointer-events-none absolute left-0 top-0\"\n        style={{ x, y, scaleX, scaleY, width: DOT, height: DOT, opacity: idx < 0 ? 0 : visible }}\n      >\n        <span\n          ref={blob}\n          className=\"block size-full rounded-full\"\n          style={{ background: color, boxShadow: `0 0 12px -2px ${color}` }}\n        />\n      </motion.span>\n    </div>\n  );\n}\n"}]}