Skip to content
Browse documentation

A dock that makes room for the tool you reach for, then opens it in place.

Used forFloating tool traysPortfolio and personal sitesProduct demo pagesAdmin quick actions

Install with the shadcn CLI

$ npx shadcn@latest add @hairline/magnifying-dock

Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/magnifying-dock.json. More

Templates

Need the whole page?

65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.

Where it’s used

  • Floating tool trays

    A tray of notes, search and settings that opens each tool in place.

  • Portfolio and personal sites

    Navigation between sections that feels like a toolbar.

  • Product demo pages

    A dock of features where each one opens a small preview.

  • Admin quick actions

    The handful of tools people reach for all day, one click away.

What it handles for you

Most docks magnify icons and stop there. This one is a tool tray: it makes room for the tool you reach for, then opens that tool in place.

Instead of wiring updock magnification mathsa toolbara popover per tooltooltipsbadge counts
  1. Icons swell near the pointer

    Tools close to the pointer scale up and the row parts around them. Distances use fixed rest positions, so the target never slides away.

  2. One label that follows

    A single label follows the nearest tool, and its letters morph when the tool changes.

  3. The tray becomes the panel

    A tool with content grows the tray up into its panel. Switching tools slides the new panel in from the side you moved toward.

  4. Badges that roll

    A count on a tool rolls when it changes and folds away at zero.

  5. Keyboard like a toolbar

    One tab stop, arrow keys, Home and End. Keyboard focus magnifies like the pointer.

  6. Light on the page

    One frame loop writes only transforms and sleeps when nothing moves. Touch skips the lens and opens tools directly.

Overview

Most docks magnify and stop there. This one is a single surface that grows into the tool you choose. Sweep across it and nearby tools swell while the row parts around them, one label glides above with its letters morphing, and a soft pad rides under the selected tool. Choose a tool with content and the tray itself rises into its panel; switch tools and the panel slides in from the side you moved toward. Every moving part is a transform eased by one frame loop that sleeps when it settles: no layout and no React renders while you move.

States

lens
Tools within 2.4 tool-widths of the pointer scale up on a cosine falloff and the row parts around them; the tray widens to fit. Distances use fixed rest positions, so growth never moves the target under the pointer.
label
One label follows the nearest tool, lifting above its current height; when the tool changes, its words morph letter by letter.
select
The pad glides to the chosen tool and keeps riding its magnification as you sweep.
open
A tool with content grows the tray up into its panel: width, height and corners ease together, the title morphs, and the content fades in. Switching tools slides the new panel in from the side you moved toward while its height eases.
close
Choosing the open tool again, Escape or a click outside folds the panel back into the tray. Escape returns focus to the tool.
badge
A count on a tool rolls when it changes and folds away at zero.

Usage

usage.tsx
import { Inbox, CalendarDays, NotebookPen } from "lucide-react";import { MagnifyingDock } from "@/components/magnifying-dock";<MagnifyingDock  items={[    { id: "inbox", label: "Inbox", icon: <Inbox />, badge: 3, content: <InboxPreview /> },    { id: "calendar", label: "Calendar", title: "Today", icon: <CalendarDays />, content: <Agenda /> },    { id: "notes", label: "Notes", icon: <NotebookPen />, content: <QuickNote /> },  ]}/>

Works with

Open real views from it

Selection and the open panel can both be controlled, so the dock can follow your router or close when work elsewhere starts.

example.tsx
"use client";import { useState } from "react";import { MagnifyingDock, type DockItem } from "@/components/magnifying-dock";export function WorkspaceDock({ tools }: { tools: DockItem[] }) {  const [view, setView] = useState(tools[0]?.id);  const [open, setOpen] = useState(false);  return (    <MagnifyingDock      items={tools}      value={view}      onValueChange={setView}      open={open}      onOpenChange={setOpen}      label="Workspace"    />  );}

Props

items
DockItem[]
Each tool: id, label, icon, and optionally content (what it opens into), title (the panel heading, defaults to label), badge (a count) and disabled.
value / defaultValue
string
Controlled selected tool or the initial one. Defaults to the first enabled tool.
onValueChange
(id: string) => void
Called when a different tool is chosen.
open / defaultOpen
boolean
Whether the selected tool’s panel is open. Tools without content never open.
onOpenChange
(open: boolean) => void
Called when the panel opens or folds away.
size= 40
number
Rest size of a tool in pixels, 32–56.
magnification= 1.6
number
Peak scale under the pointer, 1–2. It eases down to 1.22 while a panel is open so tools stay clear of it.
panelWidth= 340
number
Width of the open panel; it never exceeds the space available.
label= Tools
string
Accessible name for the toolbar.

Accessibility and motion

  • The tools form a toolbar: one tab stop, Left and Right (and Home, End) move between enabled tools, and keyboard focus magnifies like the pointer.
  • Tools with content are disclosure buttons (aria-expanded, aria-controls) for a labelled panel region that follows them in the tab order; tools without content are toggle buttons.
  • Touch skips the lens and opens tools directly. Reduced motion removes the lens and every eased move; states change in place.
  • One frame loop eases the lens, pad, label and tray, writes only transforms and the tray’s size, and stops when everything settles, so a resting dock costs nothing.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

The CLI also installs Text morph, Number roll.

Source

'use client';/* ───────────────────────────────────────────────────────── * MAGNIFYING DOCK: a dock that opens its tools in place * *   lens     tools near the pointer grow and the row parts around *            them; the tray widens with them. Transforms only, *            eased in one frame loop that sleeps when it settles *   label    one name rides above the tool under the pointer, *            gliding from tool to tool while its letters morph *   select   a soft pad glides to the chosen tool and keeps *            riding its magnification *   open     a tool with content grows the dock itself up into *            its panel: the tray widens and rises, the title *            morphs, and switching tools slides the new panel in *            from the side you moved toward *   close    choose the open tool again, press Escape or click *            away, and the panel folds back into the tray * * Every tool is a real button in a toolbar: arrow keys move * between them, and keyboard focus magnifies like the pointer. * ───────────────────────────────────────────────────────── */import * as React from 'react';import { NumberRoll } from './number-roll';import { TextMorph } from './text-morph';import { EASE_OUT, INTERACTION_FOCUS, useInteractionReducedMotion } from './ui-interaction-motion';import { useDockLens } from './use-dock-lens';export interface DockItem {  id: string;  label: string;  icon: React.ReactNode;  /** What the dock opens into when this tool is chosen. Without it, the tool only selects. */  content?: React.ReactNode;  /** The open panel's heading; defaults to label. */  title?: string;  /** A count on the icon, e.g. unread messages; 0 folds it away. */  badge?: number;  disabled?: boolean;}export interface MagnifyingDockProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {  items: DockItem[];  value?: string;  defaultValue?: string;  onValueChange?: (id: string) => void;  open?: boolean;  defaultOpen?: boolean;  onOpenChange?: (open: boolean) => void;  label?: string;  /** Rest size of a tool in px, 32–56. */  size?: number;  /** Peak scale under the pointer, 1–2. */  magnification?: number;  /** Width of the open panel in px; it never exceeds the space available. */  panelWidth?: number;}const GAP = 6;const INSET = 8;const LABEL_ROOM = 34;const clamp = (n: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, Number.isFinite(n) ? n : lo));function Pane({ dir, reduced, leaving, onDone, children }: { dir: number; reduced: boolean; leaving?: boolean; onDone?: () => void; children: React.ReactNode }) {  const ref = React.useRef<HTMLDivElement>(null);  React.useLayoutEffect(() => {    const el = ref.current;    if (!el || reduced || !dir) {      if (leaving) onDone?.();      return;    }    const frames = leaving      ? [{ opacity: 1, transform: 'none', filter: 'blur(0px)' }, { opacity: 0, transform: `translateX(${-dir * 24}px)`, filter: 'blur(4px)' }]      : [{ opacity: 0, transform: `translateX(${dir * 24}px)`, filter: 'blur(4px)' }, { opacity: 1, transform: 'none', filter: 'blur(0px)' }];    const animation = el.animate(frames, { duration: leaving ? 220 : 360, delay: leaving ? 0 : 40, easing: EASE_OUT, fill: leaving ? 'forwards' : 'backwards' });    if (leaving) animation.onfinish = () => onDone?.();    return () => animation.cancel();    // Runs once per pane: each pane is keyed by its tool.    // eslint-disable-next-line react-hooks/exhaustive-deps  }, []);  return (    <div ref={ref} inert={leaving} aria-hidden={leaving || undefined} className={leaving ? 'pointer-events-none absolute inset-x-0 top-0' : 'relative'}>      {children}    </div>  );}export function MagnifyingDock({  items,  value,  defaultValue,  onValueChange,  open: openProp,  defaultOpen = false,  onOpenChange,  label = 'Tools',  size = 40,  magnification = 1.6,  panelWidth = 340,  className = '',  ...props}: MagnifyingDockProps) {  const reduced = useInteractionReducedMotion();  const S = clamp(size, 32, 56);  const M = clamp(magnification, 1, 2);  const id = React.useId();  const [ownValue, setOwnValue] = React.useState(defaultValue ?? items.find((item) => !item.disabled)?.id);  const selectedId = value ?? ownValue;  const selected = Math.max(0, items.findIndex((item) => item.id === selectedId));  const [ownOpen, setOwnOpen] = React.useState(defaultOpen);  const open = (openProp ?? ownOpen) && Boolean(items[selected]?.content);  const [hovered, setHovered] = React.useState<number | null>(null);  const lens = useDockLens({ count: items.length, size: S, gap: GAP, inset: INSET, magnification: M, reduced, onHover: setHovered });  const root = React.useRef<HTMLDivElement>(null);  const content = React.useRef<HTMLDivElement>(null);  const [rootWidth, setRootWidth] = React.useState(0);  const panelW = Math.max(200, Math.min(panelWidth, rootWidth ? rootWidth - 16 : panelWidth));  // The panel shows the open tool; while folding away it keeps the last one.  const [shown, setShown] = React.useState(selected);  const [leaving, setLeaving] = React.useState<{ key: number; index: number; dir: number }[]>([]);  const [slideDir, setSlideDir] = React.useState(0);  const [wasOpen, setWasOpen] = React.useState(open);  if (open !== wasOpen) setWasOpen(open);  if (open && shown !== selected) {    // Switching inside an open panel slides; opening on a different tool just shows it.    const nextDir = wasOpen ? Math.sign(selected - shown) : 0;    setSlideDir(nextDir);    if (wasOpen && !reduced) {      setLeaving((l) => [...l, { key: (l.length ? l[l.length - 1].key : 0) + 1, index: shown, dir: nextDir }]);    }    setShown(selected);  }  const setOpen = (next: boolean) => {    if (openProp === undefined) setOwnOpen(next);    onOpenChange?.(next);  };  const choose = (index: number) => {    const item = items[index];    if (!item || item.disabled) return;    if (item.id !== selectedId) {      if (value === undefined) setOwnValue(item.id);      onValueChange?.(item.id);    }    if (!item.content) {      if (open) setOpen(false);      return;    }    if (!open) setSlideDir(0);    setOpen(!(open && item.id === selectedId));  };  React.useLayoutEffect(() => {    lens.set({ selected, open, panelWidth: panelW });  });  // Sizes the open panel from its content, and the panel width from the space the dock has.  React.useLayoutEffect(() => {    const el = content.current;    const box = root.current;    if (!el || !box) return;    const measure = () => {      lens.set({ panelHeight: el.offsetHeight });      setRootWidth((w) => (w === box.clientWidth ? w : box.clientWidth));    };    measure();    const observer = new ResizeObserver(measure);    observer.observe(el);    observer.observe(box);    return () => observer.disconnect();    // eslint-disable-next-line react-hooks/exhaustive-deps  }, []);  // Click away to fold the panel.  React.useEffect(() => {    if (!open) return;    const away = (event: PointerEvent) => {      if (!root.current?.contains(event.target as Node)) setOpen(false);    };    document.addEventListener('pointerdown', away);    return () => document.removeEventListener('pointerdown', away);    // eslint-disable-next-line react-hooks/exhaustive-deps  }, [open]);  const enabled = items.map((item, index) => ({ item, index })).filter(({ item }) => !item.disabled);  const onToolKey = (event: React.KeyboardEvent, index: number) => {    if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;    event.preventDefault();    const at = enabled.findIndex((entry) => entry.index === index);    const next = event.key === 'Home' ? enabled[0] : event.key === 'End' ? enabled.at(-1) : enabled[(at + (event.key === 'ArrowRight' ? 1 : -1) + enabled.length) % enabled.length];    if (next) lens.focusIcon(next.index);  };  const band = S + 2 * INSET;  const headroom = Math.ceil(S * (M - 1)) + LABEL_ROOM;  const restWidth = items.length * S + Math.max(0, items.length - 1) * GAP + 2 * INSET;  const shownItem = items[shown] ?? items[selected];  const hoverItem = hovered !== null ? items[hovered] : undefined;  return (    <div      ref={root}      {...props}      onKeyDown={(event) => {        props.onKeyDown?.(event);        if (event.key === 'Escape' && open) {          event.preventDefault();          setOpen(false);          lens.focusIcon(selected);        }      }}      className={`relative w-full text-foreground ${className}`}      style={{ height: band + headroom, ...props.style }}    >      {/* The tray: one surface that widens with the lens and rises into the panel. */}      <div        ref={(el) => { lens.attachSurface(el); }}        aria-hidden="true"        className="absolute bottom-0 left-1/2 -translate-x-1/2 border border-border bg-background"        style={{ width: restWidth, height: band, borderRadius: band / 2 }}      />      <div        ref={(el) => { lens.attachRow(el); }}        role="toolbar"        aria-label={label}        onPointerMove={(e) => lens.pointer(e)}        onPointerLeave={() => lens.leave()}        className="absolute bottom-0 left-1/2 z-10 flex -translate-x-1/2 items-end"        style={{ padding: INSET, paddingTop: INSET + (open ? 0 : Math.ceil(S * (M - 1))), gap: GAP }}      >        <div ref={(el) => { lens.attachPad(el); }} aria-hidden="true" className="absolute left-0 origin-bottom rounded-[12px] bg-muted" style={{ bottom: INSET, width: S, height: S }} />        {items.map((item, index) => {          const isSelected = index === selected;          const badge = Math.max(0, Math.round(item.badge ?? 0));          return (            <div key={item.id} className="relative shrink-0" style={{ width: S, height: S }}>              <button                ref={(el) => {                  lens.attachIcon(index, el);                }}                type="button"                aria-label={item.label}                {...(item.content ? { 'aria-expanded': open && isSelected, 'aria-controls': `${id}-panel` } : { 'aria-pressed': isSelected })}                disabled={item.disabled}                tabIndex={isSelected ? 0 : -1}                onClick={() => choose(index)}                onFocus={() => lens.set({ focus: index })}                onBlur={() => lens.set({ focus: null })}                onKeyDown={(event) => onToolKey(event, index)}                className={`cursor-pointer disabled:cursor-default absolute inset-0 flex origin-bottom items-center justify-center rounded-[12px] transition-colors duration-200 disabled:opacity-35 ${                  isSelected ? 'text-foreground' : 'text-muted-foreground hover:text-foreground'                } ${INTERACTION_FOCUS}`}              >                <span aria-hidden="true" className="flex size-[50%] items-center justify-center [&>svg]:size-full [&>svg]:stroke-[1.75]">                  {item.icon}                </span>                {item.badge !== undefined && (                  <span                    aria-hidden="true"                    className="absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[9.5px] font-medium tabular-nums text-primary-foreground"                    style={{                      opacity: badge ? 1 : 0,                      transform: badge ? 'none' : 'scale(0.4)',                      transition: reduced ? 'none' : `opacity 220ms ${EASE_OUT}, transform 380ms ${EASE_OUT}`,                    }}                  >                    <NumberRoll value={badge} duration={700} />                  </span>                )}              </button>            </div>          );        })}        {/* One label, gliding between tools; its words morph as it moves. */}        <div          ref={(el) => { lens.attachLabel(el); }}          aria-hidden="true"          className="pointer-events-none absolute left-0 whitespace-nowrap rounded-full border border-border bg-background px-2.5 py-1 text-[11.5px] font-medium text-foreground"          style={{ bottom: band + 6, opacity: 0 }}        >          <TextMorph>{hoverItem?.label ?? ''}</TextMorph>        </div>      </div>      <div        ref={(el) => { lens.attachPanel(el); }}        id={`${id}-panel`}        role="region"        aria-label={shownItem?.title ?? shownItem?.label}        inert={!open}        className="absolute left-1/2 -translate-x-1/2 overflow-hidden"        style={{ bottom: band - 1, width: panelW, height: 0, opacity: 0, visibility: 'hidden' }}      >        <div ref={content} className="absolute bottom-0 left-1/2 -translate-x-1/2 px-4 pb-3.5 pt-4" style={{ width: panelW }}>          <p className="text-[13px] font-medium text-foreground">            <TextMorph>{shownItem?.title ?? shownItem?.label ?? ''}</TextMorph>          </p>          <div className="relative mt-3">            {leaving.map((l) => (              <Pane key={`out-${l.key}`} dir={l.dir} reduced={reduced} leaving onDone={() => setLeaving((all) => all.filter((x) => x.key !== l.key))}>                {items[l.index]?.content}              </Pane>            ))}            <Pane key={shownItem?.id} dir={slideDir} reduced={reduced}>              {shownItem?.content}            </Pane>          </div>        </div>      </div>    </div>  );}

Registry item: /r/magnifying-dock.json