{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "buoy",
  "type": "registry:ui",
  "title": "Buoy",
  "description": "Floating action button that springs open an arc of glass bubble actions — buoyant overshoot with a bottom-up stagger, asynchronous idle bob, liquid squash on toggle, and a single coral accent on the active bubble. Full menu-button keyboard support with Escape to close.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/navigation/buoy/buoy.tsx",
      "type": "registry:ui",
      "target": "components/crucible/buoy.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\n\nexport interface BuoyItem {\n  /** Icon node rendered inside the bubble (decorative — the label is the accessible name). */\n  icon: React.ReactNode;\n  /** Accessible name, also shown as a small tooltip on hover/focus. */\n  label: string;\n  /** Fires on activation. The menu closes afterwards. */\n  onClick?: () => void;\n  /** Renders the bubble as a link instead of a button. */\n  href?: string;\n}\n\nexport interface BuoyProps\n  extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"onClick\"> {\n  /** Action bubbles, in arc order. Defaults to a sample set of four. */\n  items?: BuoyItem[];\n  /** Controlled open state. */\n  open?: boolean;\n  /** Initial open state when uncontrolled. @default false */\n  defaultOpen?: boolean;\n  /** Fires whenever the menu opens or closes, controlled or not. */\n  onOpenChange?: (open: boolean) => void;\n  /** Distance from the button center to each bubble center, in px. @default 92 */\n  radius?: number;\n  /**\n   * Arc the bubbles fan across, as `[fromDeg, toDeg]` — 0° points right,\n   * 90° straight up. @default [150, 30] (fanned overhead)\n   */\n  arc?: [number, number];\n  /** Accent fill for the hovered/focused bubble — the set's single warm note. @default \"#ff8a73\" (coral) */\n  accentColor?: string;\n  /** Accessible name for the toggle button and menu. @default \"Quick actions\" */\n  label?: string;\n}\n\nfunction DefaultIcon({ d }: { d: string }) {\n  return (\n    <svg\n      aria-hidden\n      viewBox=\"0 0 24 24\"\n      className=\"size-[18px]\"\n      fill=\"none\"\n      stroke=\"currentColor\"\n      strokeWidth=\"1.8\"\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n    >\n      <path d={d} />\n    </svg>\n  );\n}\n\nconst DEFAULT_ITEMS: BuoyItem[] = [\n  {\n    label: \"Search\",\n    icon: <DefaultIcon d=\"M10.5 3.5a7 7 0 1 1 0 14 7 7 0 0 1 0-14Zm5 12 5 5\" />,\n  },\n  {\n    label: \"Alerts\",\n    icon: (\n      <DefaultIcon d=\"M12 3a6 6 0 0 1 6 6v3l1.7 3.2a1 1 0 0 1-.9 1.5H5.2a1 1 0 0 1-.9-1.5L6 12V9a6 6 0 0 1 6-6Zm-2 15.5a2 2 0 0 0 4 0\" />\n    ),\n  },\n  {\n    label: \"Favorites\",\n    icon: (\n      <DefaultIcon d=\"M12 20.5 4.7 13a4.8 4.8 0 0 1 6.8-6.8l.5.5.5-.5a4.8 4.8 0 0 1 6.8 6.8L12 20.5Z\" />\n    ),\n  },\n  {\n    label: \"Compose\",\n    icon: <DefaultIcon d=\"m16.5 4.5 3 3L8 19H5v-3L16.5 4.5Zm-3 3 3 3\" />,\n  },\n];\n\n/**\n * Buoy — a floating action button that springs open an arc of glass action\n * bubbles. Buoyancy is the motion signature: bubbles overshoot their seat and\n * settle with a slow bob, opening bottom-up (a buoyant rise) and closing\n * top-down; the button itself squashes liquidly on toggle and carries a gentle\n * idle float. Neutral dark-glass bubbles, with a single soft coral fill on the\n * hovered or focused item.\n *\n * Full menu-button keyboard support: the toggle exposes aria-expanded and\n * aria-controls, opening focuses the first bubble, Arrow keys cycle, Escape and\n * Tab close and return focus. Honors prefers-reduced-motion: bubbles fade in\n * place with no springs, bob, or squash.\n */\nexport function Buoy({\n  items = DEFAULT_ITEMS,\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  radius = 92,\n  arc = [150, 30],\n  accentColor = \"#ff8a73\",\n  label = \"Quick actions\",\n  className,\n  style,\n  ...props\n}: BuoyProps) {\n  const reducedMotion = useReducedMotion();\n  const menuId = React.useId();\n  const fabRef = React.useRef<HTMLButtonElement>(null);\n  const itemRefs = React.useRef<Array<HTMLButtonElement | HTMLAnchorElement | null>>(\n    []\n  );\n\n  const isControlled = openProp !== undefined;\n  const [internalOpen, setInternalOpen] = React.useState(defaultOpen);\n  const [hasToggled, setHasToggled] = React.useState(false);\n  const open = isControlled ? openProp : internalOpen;\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      setHasToggled(true);\n      if (!isControlled) setInternalOpen(next);\n      onOpenChange?.(next);\n    },\n    [isControlled, onOpenChange]\n  );\n\n  // Bubble seats + bottom-up open order (lowest bubble rises first).\n  const positions = React.useMemo(() => {\n    const n = items.length;\n    const seats = items.map((_, i) => {\n      const t = n > 1 ? i / (n - 1) : 0.5;\n      const deg = arc[0] + (arc[1] - arc[0]) * t;\n      const rad = (deg * Math.PI) / 180;\n      return { x: Math.cos(rad) * radius, y: -Math.sin(rad) * radius };\n    });\n    const byDepth = seats\n      .map((seat, i) => ({ i, y: seat.y }))\n      .sort((a, b) => b.y - a.y); // largest y = lowest on screen = first out\n    const rank = new Array<number>(n);\n    byDepth.forEach((entry, order) => {\n      rank[entry.i] = order;\n    });\n    return seats.map((seat, i) => ({ ...seat, rank: rank[i] }));\n  }, [items, arc, radius]);\n\n  // Focus management: opening focuses the first bubble.\n  const prevOpenRef = React.useRef(open);\n  React.useEffect(() => {\n    if (open && !prevOpenRef.current) itemRefs.current[0]?.focus();\n    prevOpenRef.current = open;\n  }, [open]);\n\n  const close = React.useCallback(\n    (refocus: boolean) => {\n      setOpen(false);\n      if (refocus) fabRef.current?.focus();\n    },\n    [setOpen]\n  );\n\n  const focusItem = React.useCallback(\n    (index: number) => {\n      const n = items.length;\n      itemRefs.current[((index % n) + n) % n]?.focus();\n    },\n    [items.length]\n  );\n\n  const handleMenuKeyDown = React.useCallback(\n    (event: React.KeyboardEvent<HTMLDivElement>) => {\n      const current = itemRefs.current.findIndex(\n        (el) => el === document.activeElement\n      );\n      if (event.key === \"Escape\") {\n        event.preventDefault();\n        close(true);\n      } else if (event.key === \"ArrowDown\" || event.key === \"ArrowRight\") {\n        event.preventDefault();\n        focusItem(current + 1);\n      } else if (event.key === \"ArrowUp\" || event.key === \"ArrowLeft\") {\n        event.preventDefault();\n        focusItem(current - 1);\n      } else if (event.key === \"Home\") {\n        event.preventDefault();\n        focusItem(0);\n      } else if (event.key === \"End\") {\n        event.preventDefault();\n        focusItem(items.length - 1);\n      } else if (event.key === \"Tab\") {\n        // Close, park focus on the toggle, and let Tab continue from there.\n        setOpen(false);\n        fabRef.current?.focus();\n      }\n    },\n    [close, focusItem, items.length, setOpen]\n  );\n\n  const handleFabKeyDown = React.useCallback(\n    (event: React.KeyboardEvent<HTMLButtonElement>) => {\n      if ((event.key === \"ArrowDown\" || event.key === \"ArrowUp\") && !open) {\n        event.preventDefault();\n        setOpen(true);\n      }\n    },\n    [open, setOpen]\n  );\n\n  const activate = React.useCallback(\n    (item: BuoyItem) => {\n      item.onClick?.();\n      close(true);\n    },\n    [close]\n  );\n\n  const maxRank = items.length - 1;\n  const bubbleClass = cn(\n    \"group relative flex size-11 items-center justify-center rounded-full border border-white/15 bg-white/[0.08] text-neutral-200 backdrop-blur-md\",\n    \"shadow-[0_10px_24px_-10px_rgba(0,0,0,0.7),inset_0_1px_0_rgba(255,255,255,0.12)] transition-colors duration-200\",\n    \"hover:border-transparent hover:bg-(--buoy-accent) hover:text-neutral-950\",\n    \"focus-visible:border-transparent focus-visible:bg-(--buoy-accent) focus-visible:text-neutral-950 focus-visible:outline-none\"\n  );\n\n  return (\n    <div\n      data-crucible=\"buoy\"\n      className={cn(\"relative inline-block\", className)}\n      style={{ [\"--buoy-accent\" as string]: accentColor, ...style }}\n      {...props}\n    >\n      {/* Bubble layer, anchored at the button's center. */}\n      <div\n        id={menuId}\n        role=\"menu\"\n        aria-label={label}\n        aria-hidden={!open}\n        onKeyDown={handleMenuKeyDown}\n        className=\"absolute left-1/2 top-1/2 z-10 size-0\"\n      >\n        <AnimatePresence>\n          {open &&\n            items.map((item, i) => {\n              const seat = positions[i];\n              const openDelay = reducedMotion ? 0 : seat.rank * 0.06;\n              const exitDelay = reducedMotion ? 0 : (maxRank - seat.rank) * 0.045;\n              const isLink = typeof item.href === \"string\";\n              const setItemRef = (\n                el: HTMLButtonElement | HTMLAnchorElement | null\n              ) => {\n                itemRefs.current[i] = el;\n              };\n              const inner = (\n                <>\n                  <span aria-hidden>{item.icon}</span>\n                  <span\n                    aria-hidden\n                    className=\"pointer-events-none absolute -top-9 left-1/2 -translate-x-1/2 whitespace-nowrap rounded-full border border-white/10 bg-neutral-900 px-2.5 py-1 text-[11px] font-medium text-neutral-200 opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-visible:opacity-100\"\n                  >\n                    {item.label}\n                  </span>\n                </>\n              );\n              return (\n                <motion.div\n                  key={item.label}\n                  className=\"absolute -ml-[22px] -mt-[22px]\"\n                  initial={\n                    reducedMotion\n                      ? { x: seat.x, y: seat.y, scale: 1, opacity: 0 }\n                      : { x: 0, y: 0, scale: 0.35, opacity: 0 }\n                  }\n                  animate={{ x: seat.x, y: seat.y, scale: 1, opacity: 1 }}\n                  exit={\n                    reducedMotion\n                      ? { opacity: 0, transition: { duration: 0.12 } }\n                      : {\n                          x: 0,\n                          y: 0,\n                          scale: 0.35,\n                          opacity: 0,\n                          transition: {\n                            delay: exitDelay,\n                            duration: 0.26,\n                            ease: \"easeIn\",\n                          },\n                        }\n                  }\n                  transition={\n                    reducedMotion\n                      ? { duration: 0.15 }\n                      : {\n                          type: \"spring\",\n                          stiffness: 420,\n                          damping: 15,\n                          mass: 0.8,\n                          delay: openDelay,\n                        }\n                  }\n                >\n                  {/* Asynchronous idle bob — objects on still water. */}\n                  <motion.div\n                    animate={reducedMotion ? { y: 0 } : { y: [0, -2.5, 0] }}\n                    transition={\n                      reducedMotion\n                        ? { duration: 0 }\n                        : {\n                            duration: 2.6 + (i % 3) * 0.45,\n                            repeat: Infinity,\n                            ease: \"easeInOut\",\n                            delay: 0.9 + i * 0.3,\n                          }\n                    }\n                  >\n                    {isLink ? (\n                      <a\n                        ref={setItemRef}\n                        role=\"menuitem\"\n                        tabIndex={-1}\n                        href={item.href}\n                        aria-label={item.label}\n                        onClick={() => activate(item)}\n                        className={bubbleClass}\n                      >\n                        {inner}\n                      </a>\n                    ) : (\n                      <button\n                        ref={setItemRef}\n                        role=\"menuitem\"\n                        tabIndex={-1}\n                        type=\"button\"\n                        aria-label={item.label}\n                        onClick={() => activate(item)}\n                        className={bubbleClass}\n                      >\n                        {inner}\n                      </button>\n                    )}\n                  </motion.div>\n                </motion.div>\n              );\n            })}\n        </AnimatePresence>\n      </div>\n\n      {/* The buoy itself — gentle idle bob, liquid squash on toggle. */}\n      <motion.div\n        animate={reducedMotion ? { y: 0 } : { y: [0, -4, 0] }}\n        transition={\n          reducedMotion\n            ? { duration: 0 }\n            : { duration: 3.4, repeat: Infinity, ease: \"easeInOut\" }\n        }\n      >\n        <motion.button\n          ref={fabRef}\n          type=\"button\"\n          aria-expanded={open}\n          aria-controls={menuId}\n          aria-label={label}\n          aria-haspopup=\"menu\"\n          onClick={() => setOpen(!open)}\n          onKeyDown={handleFabKeyDown}\n          whileTap={reducedMotion ? undefined : { scale: 0.92 }}\n          className=\"relative flex size-14 items-center justify-center rounded-full border border-white/15 bg-white/[0.08] text-white backdrop-blur-md shadow-[0_16px_36px_-12px_rgba(0,0,0,0.8),inset_0_1px_0_rgba(255,255,255,0.14)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/60 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-950\"\n        >\n          <motion.span\n            key={hasToggled ? String(open) : \"initial\"}\n            aria-hidden\n            className=\"grid h-full w-full place-items-center\"\n            initial={{ scaleX: 1, scaleY: 1 }}\n            animate={\n              hasToggled && !reducedMotion\n                ? {\n                    scaleX: [1, 1.14, 0.94, 1],\n                    scaleY: [1, 0.84, 1.08, 1],\n                  }\n                : { scaleX: 1, scaleY: 1 }\n            }\n            transition={{ duration: 0.45, ease: \"easeOut\" }}\n          >\n            <motion.svg\n              viewBox=\"0 0 24 24\"\n              className=\"size-6\"\n              fill=\"none\"\n              stroke=\"currentColor\"\n              strokeWidth=\"1.8\"\n              strokeLinecap=\"round\"\n              animate={{ rotate: open ? 45 : 0 }}\n              transition={\n                reducedMotion\n                  ? { duration: 0 }\n                  : { type: \"spring\", stiffness: 380, damping: 22 }\n              }\n            >\n              <path d=\"M12 5v14M5 12h14\" />\n            </motion.svg>\n          </motion.span>\n        </motion.button>\n      </motion.div>\n    </div>\n  );\n}\n"
    }
  ]
}