{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"radial-socials","type":"registry:ui","title":"Radial Socials","description":"A share button that fans social links out along a radial arc with a staggered spring, a drawn guide arc and brand-colored hovers.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/radial-socials.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type CSSProperties, type ReactNode } from \"react\";\nimport { AnimatePresence, MotionConfig, motion } from \"motion/react\";\nimport { Share2, X } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface RadialSocialItem {\n  label: string;\n  href: string;\n  icon: ReactNode;\n  /** Brand color used as the hover fill. */\n  color?: string;\n}\n\nexport interface RadialSocialsProps {\n  items: RadialSocialItem[];\n  /** Distance from the center button to each icon, in px. */\n  radius?: number;\n  /** Direction the arc faces, in degrees (-90 is up, 0 is right). */\n  angle?: number;\n  /** Width of the arc in degrees. 360 makes a full ring. */\n  spread?: number;\n  /** Seconds between each icon springing out. */\n  stagger?: number;\n  /** Start opened. */\n  defaultOpen?: boolean;\n  /** Accessible label of the center button. */\n  label?: string;\n  /** Show a faint guide arc behind the icons. */\n  guide?: boolean;\n  className?: string;\n}\n\nexport function RadialSocials({\n  items,\n  radius = 120,\n  angle = -90,\n  spread = 180,\n  stagger = 0.05,\n  defaultOpen = false,\n  label = \"Share\",\n  guide = true,\n  className,\n}: RadialSocialsProps) {\n  const [open, setOpen] = useState(false);\n  const root = useRef<HTMLDivElement>(null);\n  const trigger = useRef<HTMLButtonElement>(null);\n  const id = useId();\n  const n = items.length;\n\n  // Open after mount so a defaultOpen fan still springs out instead of popping in.\n  useEffect(() => {\n    if (!defaultOpen) return;\n    const t = window.setTimeout(() => setOpen(true), 350);\n    return () => window.clearTimeout(t);\n  }, [defaultOpen]);\n\n  useEffect(() => {\n    if (!open) return;\n    const onDown = (e: PointerEvent) => {\n      if (!root.current?.contains(e.target as Node)) setOpen(false);\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open]);\n\n  const full = spread >= 360;\n  const angles = items.map((_, i) => {\n    const t = n === 1 ? 0.5 : full ? i / n : i / (n - 1);\n    return ((angle - (full ? 0 : spread / 2) + t * (full ? 360 : spread)) * Math.PI) / 180;\n  });\n\n  // Guide arc (SVG sweep through the icon angles).\n  const box = radius * 2 + 80;\n  const c = box / 2;\n  const a0 = full ? 0 : ((angle - spread / 2) * Math.PI) / 180;\n  const a1 = full ? Math.PI * 2 - 0.001 : ((angle + spread / 2) * Math.PI) / 180;\n  const arc = `M${c + Math.cos(a0) * radius},${c + Math.sin(a0) * radius} A${radius},${radius} 0 ${a1 - a0 > Math.PI ? 1 : 0} 1 ${c + Math.cos(a1) * radius},${c + Math.sin(a1) * radius}`;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div\n        ref={root}\n        className={cn(\"relative grid size-16 place-items-center\", className)}\n        onKeyDown={(e) => {\n          if (e.key === \"Escape\" && open) {\n            setOpen(false);\n            trigger.current?.focus();\n          }\n        }}\n      >\n        {guide && (\n          <svg aria-hidden width={box} height={box} className=\"pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 overflow-visible\">\n            <motion.path\n              d={arc}\n              fill=\"none\"\n              stroke=\"currentColor\"\n              strokeWidth={1}\n              strokeDasharray=\"2 6\"\n              strokeLinecap=\"round\"\n              className=\"text-foreground/25\"\n              initial={false}\n              animate={{ pathLength: open ? 1 : 0, opacity: open ? 1 : 0 }}\n              transition={{ duration: open ? 0.6 : 0.3, ease: [0.2, 0.8, 0.2, 1] }}\n            />\n          </svg>\n        )}\n\n        <ul id={`${id}-list`} className=\"contents\">\n          {items.map((it, i) => {\n            const x = Math.cos(angles[i]) * radius;\n            const y = Math.sin(angles[i]) * radius;\n            return (\n              <motion.li\n                key={it.label}\n                className=\"absolute left-1/2 top-1/2 -ml-6 -mt-6 list-none\"\n                initial={false}\n                animate={open ? { x, y, scale: 1, opacity: 1, rotate: 0 } : { x: 0, y: 0, scale: 0.3, opacity: 0, rotate: -120 }}\n                transition={{\n                  type: \"spring\",\n                  stiffness: open ? 360 : 500,\n                  damping: open ? 20 : 34,\n                  delay: open ? i * stagger : (n - 1 - i) * stagger * 0.5,\n                }}\n                style={{ pointerEvents: open ? \"auto\" : \"none\" }}\n              >\n                <a\n                  href={it.href}\n                  target=\"_blank\"\n                  rel=\"noreferrer\"\n                  aria-label={it.label}\n                  tabIndex={open ? 0 : -1}\n                  aria-hidden={!open}\n                  className=\"group/rs relative grid size-12 place-items-center rounded-full border border-border bg-card text-foreground shadow-[0_10px_30px_-10px_rgba(0,0,0,.6)] outline-none transition-[background-color,color,border-color,transform,box-shadow] duration-200 hover:-translate-y-0.5 hover:border-transparent hover:bg-[var(--c)] hover:text-white hover:shadow-[0_10px_30px_-6px_var(--c)] focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-5\"\n                  style={{ [\"--c\" as string]: it.color ?? \"var(--foreground)\" } as CSSProperties}\n                >\n                  {it.icon}\n                  <span className=\"pointer-events-none absolute bottom-full left-1/2 mb-2 -translate-x-1/2 translate-y-1 whitespace-nowrap rounded-md border border-border bg-card px-2 py-1 text-xs font-medium text-foreground opacity-0 shadow-md transition duration-150 group-hover/rs:translate-y-0 group-hover/rs:opacity-100 group-focus-visible/rs:translate-y-0 group-focus-visible/rs:opacity-100\">\n                    {it.label}\n                  </span>\n                </a>\n              </motion.li>\n            );\n          })}\n        </ul>\n\n        {/* Idle ping so the button reads as interactive. */}\n        {!open && (\n          <span aria-hidden className=\"absolute inset-0 animate-ping rounded-full bg-foreground/15 [animation-duration:2.4s] motion-reduce:hidden\" />\n        )}\n        <motion.button\n          ref={trigger}\n          type=\"button\"\n          aria-label={open ? `Close ${label.toLowerCase()} menu` : label}\n          aria-expanded={open}\n          aria-controls={`${id}-list`}\n          onClick={() => setOpen((o) => !o)}\n          whileTap={{ scale: 0.9 }}\n          className=\"relative z-10 grid size-16 place-items-center rounded-full bg-foreground text-background shadow-[0_16px_40px_-12px_rgba(0,0,0,.7)] outline-none ring-offset-2 ring-offset-background transition-shadow focus-visible:ring-2 focus-visible:ring-ring\"\n        >\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            <motion.span\n              key={open ? \"x\" : \"share\"}\n              initial={{ rotate: -90, scale: 0.4, opacity: 0 }}\n              animate={{ rotate: 0, scale: 1, opacity: 1 }}\n              exit={{ rotate: 90, scale: 0.4, opacity: 0 }}\n              transition={{ type: \"spring\", stiffness: 500, damping: 30 }}\n              className=\"grid place-items-center\"\n            >\n              {open ? <X className=\"size-6\" aria-hidden /> : <Share2 className=\"size-6\" aria-hidden />}\n            </motion.span>\n          </AnimatePresence>\n        </motion.button>\n      </div>\n    </MotionConfig>\n  );\n}\n"}]}