{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"dot-nav-dock","type":"registry:component","title":"Dot Nav Dock","description":"A floating navigation dock of matching rounded buttons with room to breathe between them. The selected button wears a holographic ring of spectrum colours that slowly turns round it, with white glares where the light hits; pick another and the ring moves there.","dependencies":[],"files":[{"path":"registry/dot/dot-nav-dock.tsx","type":"registry:component","target":"components/dot/dot-nav-dock.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState, type CSSProperties, type ReactNode } from \"react\";\n\nexport interface DockItem {\n  id: string;\n  /** Read out by screen readers and shown as the tooltip */\n  label: string;\n  /** The icon, drawn in `currentColor`; leave it out on the first item to show your logo there */\n  icon?: ReactNode;\n  /** An image (SVG or transparent PNG) shown instead of the icon */\n  image?: string;\n}\n\nexport interface DotNavDockProps {\n  /** The buttons, in order; the first one without an icon shows your logo */\n  items?: DockItem[];\n  /** Your logo (SVG or transparent PNG) for the first button; leave empty for the Dot mark */\n  logo?: string;\n  /** Logo size as a share of the button (0.1–0.8) */\n  logoSize?: number;\n  /** Icon size as a share of the button (0.1–0.8) */\n  iconSize?: number;\n  /** The button that starts selected */\n  defaultActive?: string;\n  /** Called with the button's id when one is picked */\n  onChange?: (id: string) => void;\n  /** White glares on the ring where the light hits */\n  glare?: boolean;\n  /** Seconds for the ring to turn once round the button */\n  speed?: number;\n  /** Button size in px */\n  size?: number;\n  /** The dock's colour */\n  dockColor?: string;\n  /** The buttons' colour */\n  buttonColor?: string;\n  /** The selected button's colour */\n  activeButtonColor?: string;\n  /** The icons' colour */\n  iconColor?: string;\n  /** The selected button's icon colour */\n  activeIconColor?: string;\n  /** Behind the dock; \"transparent\" for none */\n  background?: string;\n  className?: string;\n  style?: CSSProperties;\n}\n\nconst icon = (children: ReactNode) => (\n  <svg aria-hidden width=\"100%\" height=\"100%\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.6} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n    {children}\n  </svg>\n);\n\n/** The Dot mark */\nfunction DotMark() {\n  return (\n    <svg aria-hidden width=\"100%\" height=\"100%\" viewBox=\"0 0 24 28\" fill=\"currentColor\" style={{ display: \"block\" }}>\n      <path d=\"M17.4545 0H13.0908V25.5769H17.4545V0Z\" />\n      <path d=\"M0 23.6923L0 28H17.4545V23.6923H0Z\" />\n      <path d=\"M4.36364 21.5385H0V16.1539C0 13.1801 2.44208 10.7693 5.45455 10.7693H21.8182V15.077H5.45455C4.85206 15.077 4.36364 15.5591 4.36364 16.1539V21.5385Z\" />\n      <path d=\"M23.9999 25.8462C23.9999 24.6567 23.023 23.6924 21.818 23.6924C20.6131 23.6924 19.6362 24.6567 19.6362 25.8462C19.6362 27.0358 20.6131 28.0001 21.818 28.0001C23.023 28.0001 23.9999 27.0358 23.9999 25.8462Z\" />\n    </svg>\n  );\n}\n\nexport const DEFAULT_DOCK_ITEMS: DockItem[] = [\n  { id: \"home\", label: \"Home\" },\n  {\n    id: \"components\",\n    label: \"Components\",\n    icon: icon(\n      <>\n        <rect x=\"4\" y=\"4\" width=\"7\" height=\"7\" rx=\"2\" />\n        <rect x=\"13\" y=\"4\" width=\"7\" height=\"5\" rx=\"2\" />\n        <rect x=\"4\" y=\"13\" width=\"7\" height=\"7\" rx=\"2\" />\n        <rect x=\"13\" y=\"11\" width=\"7\" height=\"9\" rx=\"2\" />\n      </>\n    ),\n  },\n  { id: \"ask-ai\", label: \"Ask AI\", icon: icon(<path d=\"M12 3c0 5 4 9 9 9-5 0-9 4-9 9 0-5-4-9-9-9 5 0 9-4 9-9z\" />) },\n];\n\n/**\n * The selected button's ring: bands of spectrum colour (blue, cyan, red, magenta, green, gold) with\n * dark gaps between them, turning slowly round the button; two white glares flare where the light\n * hits.\n */\nfunction HoloRing({ glare, speed, width, radius }: { glare: boolean; speed: number; width: number; radius: number }) {\n  const dark = \"#0B0B0E\";\n  const hot = (at: number) => (glare ? `#FFFFFF ${at - 3}deg, #FFFFFF ${at + 3}deg` : `#9FD8FF ${at}deg`);\n  const sweep = `conic-gradient(from 0deg,\n    ${dark} 0deg, #2B3BFF 16deg, #29C8FF 26deg, ${hot(36)}, #FFA24A 44deg, #FF3B30 52deg, #C23BFF 62deg, ${dark} 76deg,\n    ${dark} 98deg, #2EE59D 110deg, #2F6BFF 122deg, ${dark} 138deg,\n    ${dark} 170deg, #B23BFF 188deg, #2F6BFF 198deg, #29D3FF 206deg, ${hot(216)}, #FFA24A 224deg, #FF4B2B 232deg, #FFD84A 240deg, #34E07F 248deg, ${dark} 262deg,\n    ${dark} 290deg, #FF3B6B 304deg, #3B5BFF 316deg, ${dark} 332deg, ${dark} 360deg)`;\n  const cutOut = \"linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)\";\n  return (\n    <span\n      aria-hidden\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        borderRadius: radius,\n        padding: width,\n        overflow: \"hidden\",\n        pointerEvents: \"none\",\n        // Only the ring shows: the inside of the button is cut out\n        WebkitMask: cutOut,\n        mask: cutOut,\n      }}\n    >\n      <span\n        style={{\n          position: \"absolute\",\n          left: \"50%\",\n          top: \"50%\",\n          width: \"170%\",\n          aspectRatio: \"1\",\n          translate: \"-50% -50%\",\n          background: sweep,\n          animation: `dot-dock-spin ${Math.max(1, speed)}s linear infinite`,\n        }}\n      />\n    </span>\n  );\n}\n\nconst CSS = `\n@keyframes dot-dock-spin { to { rotate: 360deg; } }\n.dot-dock-tile {\n  background: var(--dot-dock-button);\n  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.045);\n  color: var(--dot-dock-icon);\n  transition: color .15s ease, background-color .2s ease, transform .12s ease;\n}\n.dot-dock-tile:hover {\n  background: color-mix(in srgb, var(--dot-dock-button), #FFFFFF 4%);\n  color: color-mix(in srgb, var(--dot-dock-icon), var(--dot-dock-icon-active) 65%);\n}\n.dot-dock-tile:active { transform: scale(0.96); }\n.dot-dock-tile[aria-current] {\n  background: linear-gradient(180deg, color-mix(in srgb, var(--dot-dock-button-active), #FFFFFF 6%), var(--dot-dock-button-active) 65%);\n  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);\n  color: var(--dot-dock-icon-active);\n}\n.dot-dock-tile:focus-visible { outline: 2px solid #8A8A8A; outline-offset: 3px; }\n@media (prefers-reduced-motion: reduce) {\n  [data-dot-dock] * { animation: none !important; }\n  .dot-dock-tile { transition: none; }\n  .dot-dock-tile:active { transform: none; }\n}\n`;\n\n/**\n * A floating navigation dock: a row of matching rounded buttons with room to breathe between them,\n * in a dock whose corners follow theirs. The selected button wears a holographic ring of spectrum colours that\n * slowly turns round it, with white glares where the light hits; pick another and the ring moves\n * there.\n */\nexport function DotNavDock({\n  items = DEFAULT_DOCK_ITEMS,\n  logo,\n  logoSize = 0.36,\n  iconSize = 0.375,\n  defaultActive,\n  onChange,\n  glare = true,\n  speed = 10,\n  size = 64,\n  dockColor = \"#0F0F11\",\n  buttonColor = \"#161618\",\n  activeButtonColor = \"#1C1C1F\",\n  iconColor = \"#7C7C80\",\n  activeIconColor = \"#F4F4F5\",\n  background = \"#0B0B0C\",\n  className,\n  style,\n}: DotNavDockProps) {\n  const [picked, setActive] = useState(defaultActive ?? items[0]?.id ?? \"\");\n  // If the selected button is no longer in the items (or defaultActive doesn't match one), the first is selected\n  const active = items.some((item) => item.id === picked) ? picked : (items[0]?.id ?? \"\");\n  const rootRef = useRef<HTMLDivElement | null>(null);\n  const dockRef = useRef<HTMLElement | null>(null);\n  const [fit, setFit] = useState(1);\n\n  // Shrinks the dock to fit narrow containers instead of overflowing them\n  useEffect(() => {\n    const root = rootRef.current;\n    const dock = dockRef.current;\n    if (!root || !dock) return;\n    const measure = () => setFit(Math.min(1, (root.clientWidth - 24) / dock.offsetWidth));\n    const observer = new ResizeObserver(measure);\n    observer.observe(root);\n    observer.observe(dock);\n    return () => observer.disconnect();\n  }, []);\n\n  const S = Math.max(40, size);\n  // A snug padding round the buttons and a wider gap between them, so each button has room to\n  // breathe; the dock's corners are the buttons' corners plus the padding, so the curves run parallel\n  const pad = Math.round(S * 0.15);\n  const gap = Math.round(S * 0.25);\n  const radius = Math.round(S * 0.3);\n  const ring = Math.max(1.5, S * 0.034);\n  const share = (n: number) => S * Math.min(0.8, Math.max(0.1, n));\n  const logoPx = share(logoSize);\n  const iconPx = share(iconSize);\n  const pick = (id: string) => {\n    setActive(id);\n    onChange?.(id);\n  };\n\n  return (\n    <div\n      ref={rootRef}\n      className={className}\n      style={{ position: \"relative\", width: \"100%\", height: \"100%\", display: \"flex\", alignItems: \"center\", justifyContent: \"center\", background, ...style }}\n    >\n      <style>{CSS}</style>\n      <nav\n        ref={dockRef}\n        data-dot-dock=\"\"\n        aria-label=\"Main navigation\"\n        style={{\n          display: \"flex\",\n          alignItems: \"center\",\n          gap,\n          padding: pad,\n          borderRadius: radius + pad,\n          background: `linear-gradient(180deg, color-mix(in srgb, ${dockColor}, #FFFFFF 3%), ${dockColor})`,\n          [\"--dot-dock-button\" as string]: buttonColor,\n          [\"--dot-dock-button-active\" as string]: activeButtonColor,\n          [\"--dot-dock-icon\" as string]: iconColor,\n          [\"--dot-dock-icon-active\" as string]: activeIconColor,\n          border: \"1px solid rgba(255,255,255,0.07)\",\n          boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.05), 0 1px 2px rgba(0,0,0,0.6), 0 20px 44px -10px rgba(0,0,0,0.7)\",\n          transform: fit < 1 ? `scale(${fit})` : undefined,\n          flexShrink: 0,\n        }}\n      >\n        {items.map((item, i) => {\n          const on = item.id === active;\n          return (\n            <button\n              key={item.id}\n              type=\"button\"\n              aria-label={item.label}\n              aria-current={on ? \"page\" : undefined}\n              title={item.label}\n              onClick={() => pick(item.id)}\n              className=\"dot-dock-tile\"\n              style={{\n                position: \"relative\",\n                width: S,\n                height: S,\n                flexShrink: 0,\n                boxSizing: \"border-box\",\n                borderRadius: radius,\n                border: 0,\n                padding: 0,\n                display: \"flex\",\n                alignItems: \"center\",\n                justifyContent: \"center\",\n                cursor: \"pointer\",\n              }}\n            >\n              {on && <HoloRing glare={glare} speed={speed} width={ring} radius={radius} />}\n              {item.image ? (\n                // eslint-disable-next-line @next/next/no-img-element -- any image the user passes\n                <img src={item.image} alt=\"\" style={{ position: \"relative\", width: i === 0 && !item.icon ? logoPx : iconPx, height: i === 0 && !item.icon ? logoPx : iconPx, display: \"block\", objectFit: \"contain\" }} />\n              ) : i === 0 && !item.icon ? (\n                logo ? (\n                  // eslint-disable-next-line @next/next/no-img-element -- any logo the user passes\n                  <img src={logo} alt=\"\" style={{ position: \"relative\", width: logoPx, height: \"auto\", display: \"block\", objectFit: \"contain\" }} />\n                ) : (\n                  <span style={{ position: \"relative\", width: logoPx * 0.86, display: \"block\" }}>\n                    <DotMark />\n                  </span>\n                )\n              ) : (\n                <span style={{ position: \"relative\", width: iconPx, height: iconPx, display: \"block\" }}>{item.icon}</span>\n              )}\n            </button>\n          );\n        })}\n      </nav>\n    </div>\n  );\n}\n"}],"docs":"Dot Nav Dock is ready. Props and a live canvas: https://bydot.co/component/dot-nav-dock","meta":{"tier":"free","category":"UI Elements","version":"1.0.0"}}