{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"dock","type":"registry:ui","title":"Dock","description":"A macOS-style dock whose icons swell on springs as the cursor nears; labels rise above and the active dot glides between apps.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion"],"registryDependencies":[],"files":[{"path":"registry/geturui/ui/dock.tsx","type":"registry:ui","target":"components/ui/dock.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport {\n  AnimatePresence,\n  motion,\n  useMotionValue,\n  useReducedMotion,\n  useSpring,\n  useTransform,\n  type MotionValue,\n} from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface DockItem {\n  id: string;\n  label: string;\n  icon: React.ReactNode;\n  /** Items are split by a separator wherever the group changes. */\n  group?: string;\n  /** Number or dot shown on the icon's corner. */\n  badge?: number | boolean;\n  href?: string;\n  onClick?: () => void;\n}\n\nexport interface DockProps {\n  items: DockItem[];\n  /** Id of the item with the active dot. */\n  activeId?: string;\n  defaultActiveId?: string;\n  onActiveChange?: (id: string) => void;\n  /** Resting icon size, px. */\n  size?: number;\n  /** Size of the icon under the cursor, px. */\n  magnification?: number;\n  /** How far (px) the magnification reaches either side of the cursor. */\n  distance?: number;\n  className?: string;\n  \"aria-label\"?: string;\n}\n\n/** macOS-style dock: icons swell with cursor proximity on springs, labels rise above, and the active dot glides between apps. */\nexport function Dock({\n  items,\n  activeId,\n  defaultActiveId,\n  onActiveChange,\n  size = 44,\n  magnification = 68,\n  distance = 140,\n  className,\n  ...rest\n}: DockProps) {\n  const uid = React.useId();\n  const reduce = useReducedMotion();\n  const mouseX = useMotionValue(Infinity);\n  const [inner, setInner] = React.useState(defaultActiveId ?? items[0]?.id);\n  const active = activeId ?? inner;\n  const [focusIndex, setFocusIndex] = React.useState(() => Math.max(0, items.findIndex((i) => i.id === active)));\n  const refs = React.useRef<(HTMLElement | null)[]>([]);\n\n  function activate(item: DockItem) {\n    if (activeId === undefined) setInner(item.id);\n    onActiveChange?.(item.id);\n    item.onClick?.();\n  }\n\n  function onKeyDown(e: React.KeyboardEvent) {\n    const keys = [\"ArrowRight\", \"ArrowLeft\", \"Home\", \"End\"];\n    if (!keys.includes(e.key)) return;\n    e.preventDefault();\n    const n = items.length;\n    const next =\n      e.key === \"Home\" ? 0 : e.key === \"End\" ? n - 1 : (focusIndex + (e.key === \"ArrowRight\" ? 1 : -1) + n) % n;\n    setFocusIndex(next);\n    refs.current[next]?.focus();\n  }\n\n  const mag = reduce ? size : magnification;\n\n  return (\n    <div\n      role=\"toolbar\"\n      aria-label={rest[\"aria-label\"] ?? \"Dock\"}\n      aria-orientation=\"horizontal\"\n      onKeyDown={onKeyDown}\n      onPointerMove={(e) => {\n        if (e.pointerType === \"mouse\") mouseX.set(e.clientX);\n      }}\n      onPointerLeave={() => mouseX.set(Infinity)}\n      style={{ height: size + 22 }}\n      className={cn(\n        \"glass mx-auto flex w-max items-end gap-2 rounded-[22px] border border-border px-2.5 pb-2.5 shadow-lg\",\n        className,\n      )}\n    >\n      {items.map((item, i) => {\n        const sep = i > 0 && item.group !== items[i - 1].group;\n        return (\n          <React.Fragment key={item.id}>\n            {sep && <span aria-hidden className=\"mx-1 w-px self-stretch bg-border-strong/40 my-2.5\" />}\n            <DockIcon\n              item={item}\n              index={i}\n              mouseX={mouseX}\n              size={size}\n              magnification={mag}\n              distance={distance}\n              active={item.id === active}\n              tabbable={i === focusIndex}\n              indicatorId={`${uid}-dot`}\n              reduce={!!reduce}\n              onFocusIndex={setFocusIndex}\n              onActivate={() => activate(item)}\n              setRef={(el) => {\n                refs.current[i] = el;\n              }}\n            />\n          </React.Fragment>\n        );\n      })}\n    </div>\n  );\n}\n\ninterface DockIconProps {\n  item: DockItem;\n  index: number;\n  mouseX: MotionValue<number>;\n  size: number;\n  magnification: number;\n  distance: number;\n  active: boolean;\n  tabbable: boolean;\n  indicatorId: string;\n  reduce: boolean;\n  onFocusIndex: (i: number) => void;\n  onActivate: () => void;\n  setRef: (el: HTMLElement | null) => void;\n}\n\nfunction DockIcon({\n  item,\n  index,\n  mouseX,\n  size,\n  magnification,\n  distance,\n  active,\n  tabbable,\n  indicatorId,\n  reduce,\n  onFocusIndex,\n  onActivate,\n  setRef,\n}: DockIconProps) {\n  const [hover, setHover] = React.useState(false);\n  const [pressed, setPressed] = React.useState(false);\n  const elRef = React.useRef<HTMLElement | null>(null);\n\n  const offset = useTransform(mouseX, (x) => {\n    const r = elRef.current?.getBoundingClientRect();\n    return r ? x - (r.left + r.width / 2) : Infinity;\n  });\n  const target = useTransform(offset, [-distance, 0, distance], [size, magnification, size]);\n  const width = useSpring(target, { mass: 0.12, stiffness: 190, damping: 13 });\n  const iconScale = useTransform(width, (w) => w / size);\n  const lift = useTransform(width, [size, magnification], [0, -(magnification - size) * 0.18]);\n\n  const showLabel = hover;\n  const badge =\n    item.badge === true ? (\n      <span className=\"absolute right-0.5 top-0.5 size-2.5 rounded-full bg-ember ring-2 ring-surface\" aria-hidden />\n    ) : typeof item.badge === \"number\" && item.badge > 0 ? (\n      <span\n        aria-hidden\n        className=\"absolute -right-1 -top-1 inline-flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-ember px-1 text-[10.5px] font-semibold tabular-nums text-on-ember ring-2 ring-surface\"\n      >\n        {item.badge > 99 ? \"99+\" : item.badge}\n      </span>\n    ) : null;\n\n  const label = typeof item.badge === \"number\" && item.badge > 0 ? `${item.label}, ${item.badge} new` : item.label;\n\n  const shared = {\n    ref: (el: HTMLElement | null) => {\n      elRef.current = el;\n      setRef(el);\n    },\n    \"aria-label\": label,\n    \"aria-current\": active ? (\"page\" as const) : undefined,\n    tabIndex: tabbable ? 0 : -1,\n    onPointerEnter: () => setHover(true),\n    onPointerLeave: () => {\n      setHover(false);\n      setPressed(false);\n    },\n    onPointerDown: () => setPressed(true),\n    onPointerUp: () => setPressed(false),\n    onFocus: (e: React.FocusEvent) => {\n      onFocusIndex(index);\n      const el = e.currentTarget as HTMLElement;\n      if (el.matches(\":focus-visible\")) {\n        const r = el.getBoundingClientRect();\n        mouseX.set(r.left + r.width / 2);\n        setHover(true);\n      }\n    },\n    onBlur: () => {\n      setHover(false);\n      mouseX.set(Infinity);\n    },\n    onClick: onActivate,\n    className:\n      \"relative grid size-full place-items-center rounded-[14px] border border-border bg-surface-raised text-ink outline-none transition-colors duration-150 hover:bg-surface-raised focus-visible:shadow-[var(--focus-ring)]\",\n  };\n\n  const body = (\n    <>\n      <motion.span style={{ scale: iconScale }} className=\"grid place-items-center [&>svg]:size-[22px]\">\n        {item.icon}\n      </motion.span>\n      {badge}\n    </>\n  );\n\n  return (\n    <motion.div style={{ width, height: width, y: lift }} className=\"relative shrink-0\">\n      <motion.div\n        className=\"size-full\"\n        animate={{ scale: pressed && !reduce ? 0.9 : 1 }}\n        transition={{ type: \"spring\", stiffness: 520, damping: 26 }}\n      >\n        {item.href ? (\n          <a href={item.href} {...shared}>\n            {body}\n          </a>\n        ) : (\n          <button type=\"button\" {...shared}>\n            {body}\n          </button>\n        )}\n      </motion.div>\n      <AnimatePresence>\n        {showLabel && (\n          <motion.span\n            role=\"tooltip\"\n            aria-hidden\n            initial={{ opacity: 0, y: 6, x: \"-50%\", scale: 0.92, filter: \"blur(4px)\" }}\n            animate={{ opacity: 1, y: 0, x: \"-50%\", scale: 1, filter: \"blur(0px)\" }}\n            exit={{ opacity: 0, y: 4, x: \"-50%\", scale: 0.96, filter: \"blur(4px)\", transition: { duration: 0.1 } }}\n            transition={{ type: \"spring\", stiffness: 500, damping: 30 }}\n            className=\"pointer-events-none absolute bottom-[calc(100%+10px)] left-1/2 z-10 origin-bottom whitespace-nowrap rounded-[10px] bg-surface-raised px-2.5 py-1.5 text-xs font-medium text-ink shadow-md\"\n          >\n            {item.label}\n          </motion.span>\n        )}\n      </AnimatePresence>\n      <span className=\"absolute -bottom-[9px] left-1/2 flex h-1 w-1 -translate-x-1/2\">\n        {active && (\n          <motion.span\n            layoutId={indicatorId}\n            transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 30 }}\n            className=\"size-1 rounded-full bg-ink\"\n          />\n        )}\n      </span>\n    </motion.div>\n  );\n}\n"},{"path":"LICENSE-geturui.md","type":"registry:file","target":"LICENSE-geturui.md","content":"MIT License\n\nCopyright (c) 2026 geturui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"}],"categories":["components","dock","navigation","toolbar","magnify","macos","springs","motion values"],"meta":{"tier":"free","license":"MIT","docs":"https://geturui.com/docs/dock"}}