{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"expandable-dock","type":"registry:ui","title":"Expandable Dock","description":"A compact pill of actions that springs open into a panel (search, quick actions, inbox, player), morphing its size and corners between states.","dependencies":["motion","react-use-measure"],"registryDependencies":[],"files":[{"path":"registry/ui/expandable-dock.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type ReactNode } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport useMeasure from \"react-use-measure\";\n\nexport interface ExpandableDockItem {\n  id: string;\n  label: string;\n  icon: ReactNode;\n  /** Panel the dock morphs into when this item is picked. Items without one just call onClick. */\n  panel?: ReactNode;\n  onClick?: () => void;\n}\n\nexport interface ExpandableDockProps {\n  items: ExpandableDockItem[];\n  /** Id of the item whose panel is open at first render. */\n  defaultOpen?: string;\n  /** Spring bounce of the morph, 0 (none) to 0.5. */\n  bounce?: number;\n  /** Morph duration in seconds. */\n  duration?: number;\n  /** Corner radius of the expanded panel in px (the closed dock is always a pill). */\n  radius?: number;\n  onOpenChange?: (id: string | null) => void;\n  className?: string;\n}\n\n/**\n * A compact pill of actions that morphs into a panel. The box animates to the measured\n * size of whatever is inside, so any panel content works. Renders in normal flow: anchor it\n * with `absolute bottom-6` (or fixed) and it grows away from that edge.\n */\nexport function ExpandableDock({\n  items,\n  defaultOpen,\n  bounce = 0.2,\n  duration = 0.5,\n  radius = 24,\n  onOpenChange,\n  className,\n}: ExpandableDockProps) {\n  const [open, setOpen] = useState<string | null>(defaultOpen ?? null);\n  const [ref, bounds] = useMeasure({ offsetSize: true });\n  const body = useRef<HTMLDivElement>(null);\n  const reduce = useReducedMotion();\n  const root = useRef<HTMLDivElement>(null);\n  const triggers = useRef<Record<string, HTMLButtonElement | null>>({});\n  const uid = useId();\n  const current = items.find((i) => i.id === open && i.panel);\n\n  const set = (id: string | null) => {\n    setOpen(id);\n    onOpenChange?.(id);\n  };\n\n  const close = () => {\n    const last = open;\n    set(null);\n    // Return focus to the button that opened the panel once it is back in the DOM.\n    if (last) requestAnimationFrame(() => triggers.current[last]?.focus());\n  };\n\n  // Close on outside press / Escape while expanded.\n  useEffect(() => {\n    if (!open) return;\n    const onDown = (e: PointerEvent) => {\n      if (root.current && !root.current.contains(e.target as Node)) {\n        setOpen(null);\n        onOpenChange?.(null);\n      }\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open, onOpenChange]);\n\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, bounce, duration };\n  const fade = reduce ? { duration: 0 } : { duration: duration * 0.5, ease: [0.2, 0.7, 0.2, 1] as const };\n  const measured = bounds.width > 0;\n\n  return (\n    <motion.div\n      ref={root}\n      onKeyDown={(e) => {\n        if (e.key === \"Escape\" && open) {\n          e.stopPropagation();\n          close();\n        }\n      }}\n      initial={false}\n      animate={{\n        width: measured ? bounds.width : \"auto\",\n        height: measured ? bounds.height : \"auto\",\n        borderRadius: current ? radius : 999,\n      }}\n      transition={spring}\n      className={`relative overflow-hidden border border-border bg-card/85 text-foreground shadow-[0_24px_60px_-20px_rgba(0,0,0,.65),inset_0_1px_0_rgba(255,255,255,.06)] backdrop-blur-xl ${className ?? \"\"}`}\n    >\n      <div ref={ref} className=\"w-max\">\n        <AnimatePresence mode=\"popLayout\" initial={false}>\n          {current ? (\n            <motion.div\n              key={current.id}\n              id={`${uid}-panel`}\n              role=\"dialog\"\n              aria-label={current.label}\n              initial={{ opacity: 0, scale: 0.94, filter: reduce ? \"none\" : \"blur(6px)\" }}\n              animate={{ opacity: 1, scale: 1, filter: \"blur(0px)\" }}\n              exit={{ opacity: 0, scale: 0.94, filter: reduce ? \"none\" : \"blur(6px)\" }}\n              transition={fade}\n              className=\"origin-bottom p-2\"\n            >\n              <div className=\"flex items-center gap-2 px-2 pb-2 pt-1\">\n                <span className=\"grid size-6 place-items-center text-muted-foreground [&>svg]:size-4\">{current.icon}</span>\n                <span className=\"flex-1 text-sm font-medium\">{current.label}</span>\n                <button\n                  type=\"button\"\n                  onClick={close}\n                  aria-label=\"Close\"\n                  className=\"grid size-7 place-items-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n                >\n                  <svg viewBox=\"0 0 24 24\" className=\"size-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2} strokeLinecap=\"round\">\n                    <path d=\"M6 6l12 12M18 6 6 18\" />\n                  </svg>\n                </button>\n              </div>\n              <div ref={body}>{current.panel}</div>\n            </motion.div>\n          ) : (\n            <motion.div\n              key=\"dock\"\n              role=\"toolbar\"\n              aria-label=\"Dock\"\n              initial={{ opacity: 0, scale: 0.9, filter: reduce ? \"none\" : \"blur(4px)\" }}\n              animate={{ opacity: 1, scale: 1, filter: \"blur(0px)\" }}\n              exit={{ opacity: 0, scale: 0.9, filter: reduce ? \"none\" : \"blur(4px)\" }}\n              transition={fade}\n              className=\"flex items-center gap-1 p-1.5\"\n            >\n              {items.map((item) => (\n                <button\n                  key={item.id}\n                  ref={(el) => {\n                    triggers.current[item.id] = el;\n                  }}\n                  type=\"button\"\n                  aria-label={item.label}\n                  aria-haspopup={item.panel ? \"dialog\" : undefined}\n                  aria-expanded={item.panel ? false : undefined}\n                  onClick={() => {\n                    item.onClick?.();\n                    if (!item.panel) return;\n                    set(item.id);\n                    // Move focus into the panel (first control, else the close button).\n                    requestAnimationFrame(() => {\n                      const panel = body.current?.parentElement;\n                      const first =\n                        body.current?.querySelector<HTMLElement>(\"input, button, [href], [tabindex]:not([tabindex='-1'])\") ??\n                        panel?.querySelector<HTMLElement>(\"button\");\n                      first?.focus();\n                    });\n                  }}\n                  className=\"group relative grid size-11 place-items-center rounded-full text-muted-foreground outline-none transition-[color,background-color,transform] duration-200 hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring active:scale-90 [&>svg]:size-5\"\n                >\n                  {item.icon}\n                </button>\n              ))}\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </motion.div>\n  );\n}\n"}]}