{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"sprout-menu","type":"registry:ui","title":"Sprout Menu","description":"A trigger that grows curved branches out to its sub-actions, then pulls them back in when it closes.","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/ui/sprout-menu.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type KeyboardEvent, type ReactNode } from \"react\";\nimport { AnimatePresence, MotionConfig, motion } from \"motion/react\";\nimport { Camera, FileText, ImageIcon, MapPin, Mic, Plus } from \"lucide-react\";\n\nexport interface SproutMenuItem {\n  label: string;\n  icon?: ReactNode;\n}\n\nexport interface SproutMenuProps {\n  /** Sub-actions that sprout at the ends of the branches. */\n  items?: SproutMenuItem[];\n  /** Branch length in px. */\n  radius?: number;\n  /** Fan angle in degrees across which the branches spread. */\n  spread?: number;\n  /** Branch stroke color. */\n  color?: string;\n  /** Accessible name of the trigger. */\n  label?: string;\n  /** Called with the chosen item and its index; the menu then collapses. */\n  onSelect?: (item: SproutMenuItem, index: number) => void;\n  className?: string;\n}\n\nconst defaultItems: SproutMenuItem[] = [\n  { label: \"Photo\", icon: <Camera /> },\n  { label: \"Gallery\", icon: <ImageIcon /> },\n  { label: \"Note\", icon: <FileText /> },\n  { label: \"Voice\", icon: <Mic /> },\n  { label: \"Place\", icon: <MapPin /> },\n];\n\nconst PAD = 40;\n\nexport function SproutMenu({\n  items = defaultItems,\n  radius = 130,\n  spread = 150,\n  color = \"#a3e635\",\n  label = \"Create\",\n  onSelect,\n  className,\n}: SproutMenuProps) {\n  const [open, setOpen] = useState(false);\n  const trigger = useRef<HTMLButtonElement>(null);\n  const refs = useRef<(HTMLButtonElement | null)[]>([]);\n  const menuId = useId();\n\n  const w = radius * 2 + PAD * 2;\n  const h = radius + PAD * 2;\n  const ox = w / 2;\n  const oy = h - PAD;\n  const n = items.length;\n\n  const nodes = items.map((item, i) => {\n    const a = ((-90 - spread / 2 + (n > 1 ? (i * spread) / (n - 1) : spread / 2)) * Math.PI) / 180;\n    const ex = ox + Math.cos(a) * radius;\n    const ey = oy + Math.sin(a) * radius;\n    // Grow straight up out of the trunk first, then bend out toward the leaf.\n    const d = `M${ox} ${oy - 22}C${ox} ${oy - radius * 0.55} ${ex - (ex - ox) * 0.3} ${ey + (oy - ey) * 0.22} ${ex} ${ey}`;\n    return { item, ex, ey, d };\n  });\n\n  useEffect(() => {\n    if (open) refs.current[0]?.focus();\n  }, [open]);\n\n  const close = (refocus: boolean) => {\n    setOpen(false);\n    if (refocus) trigger.current?.focus();\n  };\n\n  const onMenuKey = (e: KeyboardEvent) => {\n    const i = refs.current.findIndex((el) => el === document.activeElement);\n    const move = (to: number) => {\n      e.preventDefault();\n      refs.current[(to + n) % n]?.focus();\n    };\n    if (e.key === \"Escape\") {\n      e.preventDefault();\n      close(true);\n    } else if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") move(i + 1);\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") move(i - 1);\n    else if (e.key === \"Home\") move(0);\n    else if (e.key === \"End\") move(n - 1);\n  };\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div\n        className={`relative ${className ?? \"\"}`}\n        style={{ width: w, height: h }}\n        onBlur={(e) => {\n          if (open && !e.currentTarget.contains(e.relatedTarget as Node | null)) setOpen(false);\n        }}\n      >\n        <svg aria-hidden width={w} height={h} className=\"pointer-events-none absolute inset-0 overflow-visible\">\n          <AnimatePresence>\n            {open &&\n              nodes.map(({ d }, i) => (\n                <motion.path\n                  key={i}\n                  d={d}\n                  fill=\"none\"\n                  stroke={color}\n                  strokeWidth={2.5}\n                  strokeLinecap=\"round\"\n                  initial={{ pathLength: 0, opacity: 0 }}\n                  animate={{ pathLength: 1, opacity: 1, transition: { duration: 0.42, delay: i * 0.045, ease: [0.3, 0.7, 0.2, 1] } }}\n                  exit={{ pathLength: 0, opacity: 0, transition: { duration: 0.3, delay: 0.12 + (n - 1 - i) * 0.03, ease: \"easeIn\" } }}\n                  style={{ filter: `drop-shadow(0 0 6px ${color}66)` }}\n                />\n              ))}\n          </AnimatePresence>\n        </svg>\n\n        <AnimatePresence>\n          {open && (\n            <motion.div id={menuId} role=\"menu\" aria-label={label} onKeyDown={onMenuKey} exit={{ opacity: 1 }}>\n              {nodes.map(({ item, ex, ey }, i) => (\n                <motion.div\n                  key={item.label + i}\n                  className=\"absolute -translate-x-1/2 -translate-y-1/2\"\n                  style={{ left: ex, top: ey }}\n                  initial={{ scale: 0, opacity: 0 }}\n                  animate={{ scale: 1, opacity: 1, transition: { type: \"spring\", stiffness: 460, damping: 17, delay: 0.24 + i * 0.045 } }}\n                  exit={{ scale: 0, opacity: 0, transition: { duration: 0.16, delay: (n - 1 - i) * 0.02, ease: \"easeIn\" } }}\n                >\n                  <button\n                    ref={(el) => {\n                      refs.current[i] = el;\n                    }}\n                    type=\"button\"\n                    role=\"menuitem\"\n                    tabIndex={-1}\n                    onClick={() => {\n                      onSelect?.(item, i);\n                      close(true);\n                    }}\n                    className=\"group/item peer grid size-11 place-items-center rounded-full border border-border bg-card text-foreground shadow-lg outline-none transition-[scale,box-shadow,background-color] duration-200 hover:scale-110 focus-visible:scale-110 focus-visible:ring-[3px] focus-visible:ring-ring/60 active:scale-95 [&_svg]:size-5\"\n                    style={{ boxShadow: `0 0 0 1px ${color}40, 0 8px 20px -8px ${color}` }}\n                  >\n                    {item.icon}\n                    <span className=\"sr-only\">{item.label}</span>\n                  </button>\n                  <span\n                    aria-hidden\n                    className=\"pointer-events-none absolute left-1/2 top-full mt-1.5 -translate-x-1/2 whitespace-nowrap rounded-md bg-foreground px-1.5 py-0.5 text-[11px] font-medium text-background opacity-0 transition-opacity duration-150 peer-hover:opacity-100 peer-focus-visible:opacity-100\"\n                  >\n                    {item.label}\n                  </span>\n                </motion.div>\n              ))}\n            </motion.div>\n          )}\n        </AnimatePresence>\n\n        <motion.button\n          ref={trigger}\n          type=\"button\"\n          aria-haspopup=\"menu\"\n          aria-expanded={open}\n          aria-controls={open ? menuId : undefined}\n          aria-label={label}\n          onClick={() => setOpen((o) => !o)}\n          onKeyDown={(e) => {\n            if (e.key === \"Escape\" && open) close(true);\n          }}\n          whileTap={{ scaleX: 1.14, scaleY: 0.86 }}\n          animate={{ scale: open ? 0.92 : 1 }}\n          transition={{ type: \"spring\", stiffness: 500, damping: 18 }}\n          className=\"absolute grid size-12 -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full bg-primary text-primary-foreground shadow-[inset_0_1px_0_rgb(255_255_255/.35),0_10px_28px_-10px_var(--primary)] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/60 focus-visible:ring-offset-2 focus-visible:ring-offset-background\"\n          style={{ left: ox, top: oy }}\n        >\n          <motion.span\n            aria-hidden\n            className=\"grid place-items-center\"\n            animate={{ rotate: open ? 135 : 0 }}\n            transition={{ type: \"spring\", stiffness: 380, damping: 16 }}\n          >\n            <Plus className=\"size-6\" strokeWidth={2.5} />\n          </motion.span>\n        </motion.button>\n      </div>\n    </MotionConfig>\n  );\n}\n"}]}