{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dock",
  "title": "Dock",
  "description": "macOS-style dock whose tiles magnify on a spring as the pointer nears, with tooltips, running dots, badges and a launch bounce, falling back to a simple press scale on touch.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/navigation/dock.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  AnimatePresence,\n  motion,\n  useAnimationControls,\n  useMotionValue,\n  useReducedMotion,\n  useMotionValueEvent,\n  useSpring,\n  type MotionValue,\n} from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, follow, spring } from \"@/lib/goodui-motion\"\n\nconst CSS = `\n.pc-dock{position:relative;isolation:isolate;background:color-mix(in oklab,var(--card) 58%,transparent);-webkit-backdrop-filter:blur(20px) saturate(1.7);backdrop-filter:blur(20px) saturate(1.7);box-shadow:inset 0 1px rgb(255 255 255/.6),inset 0 0 0 1px rgb(255 255 255/.14),var(--pc-e3)}\n.dark .pc-dock{box-shadow:inset 0 1px rgb(255 255 255/.16),inset 0 0 0 1px rgb(255 255 255/.05),var(--pc-e3)}\n.pc-dock::before{content:\"\";position:absolute;inset:0;z-index:-1;border-radius:inherit;pointer-events:none;background:linear-gradient(rgb(255 255 255/.2),transparent 62%)}\n.dark .pc-dock::before{background:linear-gradient(rgb(255 255 255/.07),transparent 62%)}\n.pc-dock-tile{box-shadow:inset 0 1px rgb(255 255 255/.7),inset 0 -1px rgb(0 0 0/.08),0 0 0 .5px rgb(0 0 0/.1),0 1px 2px rgb(0 0 0/.14),0 6px 12px -6px rgb(0 0 0/.3)}\n.dark .pc-dock-tile{box-shadow:inset 0 1px rgb(255 255 255/.2),inset 0 -1px rgb(0 0 0/.25),0 0 0 .5px rgb(0 0 0/.6),0 1px 2px rgb(0 0 0/.4),0 6px 12px -6px rgb(0 0 0/.6)}\n.pc-dock-tile::before{content:\"\";position:absolute;inset:0;border-radius:inherit;pointer-events:none;background:linear-gradient(rgb(255 255 255/.24),transparent 55%)}\n`\n\nexport type DockItem =\n  | {\n      /** Unique key of the tile. */\n      id: string\n      /** Tooltip text and the button's accessible name. */\n      label: string\n      /** Icon component (e.g. a lucide icon), sized to 45% of the tile. */\n      icon: React.ComponentType<{ className?: string }>\n      onClick?: () => void\n      /** Shows the running dot under the icon. */\n      active?: boolean\n      /** Count bubble on the icon, e.g. unread messages. */\n      badge?: number\n      /** Tailwind classes for the icon tile, e.g. a brand gradient. */\n      tileClassName?: string\n    }\n  | { id: string; separator: true }\n\nexport type DockProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** Tiles from left to right; { id, separator: true } draws a divider between groups. */\n  items: DockItem[]\n  /** Resting tile size in px. */\n  size?: number\n  /** Tile size in px right under the pointer. */\n  magnification?: number\n  /** Pointer distance in px over which neighbours grow. */\n  distance?: number\n  /** Bounce the icon when clicked, like an app launching. */\n  bounce?: boolean\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<DockLabels>\n}\n\n/** Screen-reader text for the count bubble, read after the tile label. */\nexport type DockLabels = { badge: (count: number) => string }\nconst DEFAULT_LABELS: DockLabels = { badge: (count) => `${count} new` }\n\ntype DockButtonItem = Exclude<DockItem, { separator: true }>\n\nfunction DockIcon({\n  item,\n  mouseX,\n  size,\n  magnification,\n  distance,\n  magnify,\n  bounce,\n  reduce,\n  index,\n  focusable,\n  onFocusItem,\n  onKeyDown,\n  refCb,\n  tipId,\n  l,\n}: {\n  item: DockButtonItem\n  mouseX: MotionValue<number>\n  size: number\n  magnification: number\n  distance: number\n  magnify: boolean\n  bounce: boolean\n  reduce: boolean\n  index: number\n  focusable: boolean\n  onFocusItem: (index: number) => void\n  onKeyDown: (e: React.KeyboardEvent, index: number) => void\n  refCb: (el: HTMLButtonElement | null) => void\n  tipId: string\n  l: DockLabels\n}) {\n  const ref = React.useRef<HTMLButtonElement>(null)\n  const [tip, setTip] = React.useState(false)\n  const controls = useAnimationControls()\n\n  // Size from the pointer's distance to this tile's centre, smoothed by a spring.\n  const sizeFor = (x: number) => {\n    const r = ref.current?.getBoundingClientRect()\n    if (!magnify || !r || !Number.isFinite(x)) return size\n    const t = Math.max(0, 1 - Math.abs(x - (r.left + r.width / 2)) / distance)\n    // Cosine falloff reads smoother than a linear ramp.\n    return size + (magnification - size) * (0.5 - 0.5 * Math.cos(Math.PI * t))\n  }\n  const width = useSpring(size, follow)\n  useMotionValueEvent(mouseX, \"change\", (x) => width.set(sizeFor(x)))\n  React.useEffect(() => {\n    width.set(sizeFor(mouseX.get()))\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [size, magnification, distance, magnify])\n\n  const Icon = item.icon\n  const click = () => {\n    if (bounce && !reduce) controls.start({\n        y: [0, -18, 0, -6, 0],\n        scaleX: [1, 0.96, 1.07, 0.99, 1],\n        scaleY: [1, 1.05, 0.91, 1.02, 1],\n        transition: { duration: 0.66, times: [0, 0.32, 0.6, 0.8, 1], ease: [\"easeOut\", \"easeIn\", \"easeOut\", \"easeIn\"] },\n      })\n    item.onClick?.()\n  }\n\n  return (\n    <motion.div style={{ width, height: width }} className=\"relative flex shrink-0 items-end justify-center\">\n      <AnimatePresence>\n        {tip && (\n          <motion.span\n            role=\"tooltip\"\n            id={tipId}\n            initial={{ opacity: 0, y: 6, scale: 0.95, x: \"-50%\" }}\n            animate={{ opacity: 1, y: 0, scale: 1, x: \"-50%\" }}\n            exit={{ opacity: 0, y: 4, scale: 0.95, x: \"-50%\" }}\n            transition={reduce ? { duration: 0 } : spring.ui}\n            className=\"pointer-events-none absolute -top-9 left-1/2 z-20 rounded-md border bg-popover px-2 py-1 text-xs font-medium whitespace-nowrap text-popover-foreground shadow-[var(--pc-e2)]\"\n          >\n            {item.label}\n          </motion.span>\n        )}\n      </AnimatePresence>\n      <motion.div animate={controls} className=\"size-full origin-bottom\">\n      <motion.button\n        ref={(el) => {\n          ref.current = el\n          refCb(el)\n        }}\n        type=\"button\"\n        aria-describedby={tip ? tipId : undefined}\n        aria-current={item.active ? \"page\" : undefined}\n        tabIndex={focusable ? 0 : -1}\n        whileTap={reduce ? undefined : { scale: 0.9 }}\n        whileHover={!magnify && !reduce ? { scale: 1.08, y: -2 } : undefined}\n        onClick={click}\n        onKeyDown={(e) => onKeyDown(e, index)}\n        onPointerEnter={() => setTip(true)}\n        onPointerLeave={() => setTip(false)}\n        onFocus={() => {\n          setTip(true)\n          onFocusItem(index)\n        }}\n        onBlur={() => setTip(false)}\n        className={cn(\n          \"pc-dock-tile relative flex size-full cursor-pointer items-center justify-center rounded-[28%] bg-linear-to-b from-background to-muted text-foreground outline-none focus-visible:ring-3 focus-visible:ring-ring/50 dark:from-muted dark:to-card [&_svg]:relative [&_svg]:size-[45%]\",\n          item.tileClassName,\n        )}\n      >\n        {/* The name comes from content (label + count), so the visible count is always part of it. */}\n        <span className=\"sr-only\">{item.label}</span>\n        <Icon aria-hidden=\"true\" />\n        <AnimatePresence>\n          {!!item.badge && (\n            <motion.span\n              key=\"badge\"\n              initial={{ scale: 0 }}\n              animate={{ scale: 1 }}\n              exit={{ scale: 0 }}\n              transition={reduce ? { duration: 0 } : spring.play}\n              className=\"absolute -end-1 -top-1 flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-rose-600 px-1 text-[10px] leading-none font-semibold text-white tabular-nums shadow-[var(--pc-e1)] ring-2 ring-card\"\n            >\n              <span aria-hidden=\"true\">{item.badge > 99 ? \"99+\" : item.badge}</span>\n              <span className=\"sr-only\">, {l.badge(item.badge)}</span>\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </motion.button>\n      </motion.div>\n      <motion.span\n        aria-hidden=\"true\"\n        className=\"absolute -bottom-[7px] left-1/2 size-1 -translate-x-1/2 rounded-full bg-foreground/80 shadow-[0_0_6px_var(--foreground)]\"\n        initial={false}\n        animate={{ opacity: item.active ? 1 : 0, scale: item.active ? 1 : 0.4 }}\n        transition={reduce ? { duration: 0 } : { ...spring.play, delay: item.active ? 0.3 : 0 }}\n      />\n    </motion.div>\n  )\n}\n\n/**\n * macOS-style dock: tiles near the pointer magnify on a spring, with tooltips, running dots, badges and a launch\n * bounce. On touch screens and with reduced motion it falls back to a simple press/hover scale.\n * Arrow keys move focus between tiles (role=\"toolbar\").\n */\nexport function Dock({ items, size = 44, magnification = 68, distance = 140, bounce = true, labels, className, ...props }: DockProps) {\n  const l = useLabels(\"dock\", DEFAULT_LABELS, labels)\n  const uid = React.useId()\n  const reduce = useReducedMotion() ?? false\n  const mouseX = useMotionValue(Number.POSITIVE_INFINITY)\n  const [touch, setTouch] = React.useState(false)\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([])\n  const [focusIndex, setFocusIndex] = React.useState(0)\n\n  React.useEffect(() => {\n    const mq = window.matchMedia(\"(hover: none)\")\n    const update = () => setTouch(mq.matches)\n    update()\n    mq.addEventListener(\"change\", update)\n    return () => mq.removeEventListener(\"change\", update)\n  }, [])\n\n  const magnify = !touch && !reduce\n  const buttons = items.filter((i): i is DockButtonItem => !(\"separator\" in i))\n\n  const onKeyDown = (e: React.KeyboardEvent, i: number) => {\n    let next = -1\n    // Mirror the arrows in right-to-left layouts so they follow the visual order.\n    const rtl = getComputedStyle(e.currentTarget).direction === \"rtl\"\n    if (e.key === (rtl ? \"ArrowLeft\" : \"ArrowRight\")) next = (i + 1) % buttons.length\n    else if (e.key === (rtl ? \"ArrowRight\" : \"ArrowLeft\")) next = (i - 1 + buttons.length) % buttons.length\n    else if (e.key === \"Home\") next = 0\n    else if (e.key === \"End\") next = buttons.length - 1\n    if (next < 0) return\n    e.preventDefault()\n    setFocusIndex(next)\n    refs.current[next]?.focus()\n  }\n\n  let index = -1\n  return (\n    <div\n      role=\"toolbar\"\n      aria-orientation=\"horizontal\"\n      data-slot=\"dock\"\n      onPointerMove={(e) => magnify && e.pointerType === \"mouse\" && mouseX.set(e.clientX)}\n      onPointerLeave={() => mouseX.set(Number.POSITIVE_INFINITY)}\n      className={cn(\n        \"pc-dock mx-auto flex w-max max-w-full items-end gap-2 rounded-[22px] px-2 pt-2 pb-3\",\n        className,\n      )}\n      style={{ height: size + 20 }}\n      {...props}\n    >\n      <GooduiTokens />\n      <style href=\"pc-dock\" precedence=\"default\">\n        {CSS}\n      </style>\n      {items.map((item) => {\n        if (\"separator\" in item) {\n          return <span key={item.id} role=\"separator\" aria-orientation=\"vertical\" className=\"mx-1 w-px self-stretch bg-linear-to-b from-transparent via-foreground/15 to-transparent\" />\n        }\n        index += 1\n        const i = index\n        return (\n          <DockIcon\n            key={item.id}\n            item={item}\n            index={i}\n            focusable={i === focusIndex}\n            onFocusItem={setFocusIndex}\n            mouseX={mouseX}\n            size={size}\n            magnification={magnification}\n            distance={distance}\n            magnify={magnify}\n            bounce={bounce}\n            reduce={reduce}\n            tipId={`${uid}-tip-${i}`}\n            l={l}\n            onKeyDown={onKeyDown}\n            refCb={(el) => {\n              refs.current[i] = el\n            }}\n          />\n        )\n      })}\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/dock.tsx"
    }
  ],
  "categories": [
    "components",
    "navigation"
  ],
  "type": "registry:component"
}