Micro-interactions

Magnetic Dock

A dock whose items swell under the pointer and carry their neighbours part of the way with them. One shared value drives the whole row, so nothing re-renders while you sweep across it — and focusing an item writes the same value, which is why the keyboard gets the identical effect rather than a substitute for it.

Install

bun add motion clsx tailwind-merge

Then copy 2 files into your project:

  • components/registry/magnetic-dock/magnetic-dock.tsx
  • lib/utils.ts

Props

PropTypeDefaultDescription
magnificationnumber2How far the item directly under the pointer grows past its resting size. Past about 2.5 the peak stops looking like the row lifting and starts looking like one icon detaching from it.
falloffnumber140Distance at which an item stops responding at all. This is the real character knob: a narrow falloff magnifies one item and reads as a hover state, while a wide one pulls four or five along and reads as a surface being pushed from underneath.
baseSizenumber44Resting edge length of an item. The icon is sized in `em` off this, so any node scales with it without knowing the dock exists.
gapnumber10Space between items at rest. Items grow into this gap rather than pushing each other along, so a tight dock has the peak crowding its neighbours and a loose one lets each swell finish.
stiffnessnumber320How hard an item springs toward its target size. Low values put the largest item visibly behind the pointer on a fast sweep, which breaks the illusion that you are pushing the surface yourself.
dampingnumber24How fast that spring settles. Under about 15 the icons keep bobbing after the pointer has left, which is charming once and irritating thereafter.
labelsbooleantrueFade the item's label in over the magnified item. Its opacity is driven by the same distance the size is, so it arrives with the swell instead of on a separate hover timer.
orientation"horizontal" | "vertical""horizontal"Which axis the dock runs along, and therefore which pointer coordinate drives it. Items always grow away from the dock's own edge, so a vertical rail expands sideways rather than upward.
accentstring (hex)"#a855f7"Running indicator and focus ring. The ring is a shadow rather than an outline — an outline paints outside the border box and visibly lags the spring while the button is still resizing.

What It Demonstrates

Hover effect
Visual change when the cursor moves over an element.
Spring
Motion driven by physics (tension, mass, damping) rather than a set duration.
Stiffness / Tension
How strongly the spring pulls toward its target. Higher feels snappier.
Damping
How quickly a spring settles. Lower damping means more bounce and oscillation.
Spatial consistency
Animating so an element keeps its identity and position across states, so users never lose track of where things went.
Follow-through
Parts of an element keep moving and settle slightly after the main motion stops, adding weight.
Purposeful animation
Motion should serve a function — orient, give feedback, show relationships — not just decorate.

Related Components

Appears In