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-mergeThen copy 2 files into your project:
- components/registry/magnetic-dock/magnetic-dock.tsx
- lib/utils.ts
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| magnification | number | 2 | How 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. |
| falloff | number | 140 | Distance 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. |
| baseSize | number | 44 | Resting edge length of an item. The icon is sized in `em` off this, so any node scales with it without knowing the dock exists. |
| gap | number | 10 | Space 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. |
| stiffness | number | 320 | How 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. |
| damping | number | 24 | How fast that spring settles. Under about 15 the icons keep bobbing after the pointer has left, which is charming once and irritating thereafter. |
| labels | boolean | true | Fade 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. |
| accent | string (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
Unfold
A row of slats that open on approach while their neighbours give up the room on a spring.
Shadow Cursor
A custom cursor with a shadow at its heel. A precise dot leads while a lagging blade trails on a spring, and when it crosses an interactive element the trail pools and swells around it, inverting whatever lies beneath. Scoped entirely to its own stage, so the page cursor is never touched.
Dial
A machined rotary knob: angular drag with detents you can feel on the way past, inertia on a flick, and a spring that settles into the nearest stop. The angle lives in a motion value rather than in React state, because a drag writes it sixty times a second and a spring more often than that, so the only thing React holds is the detent index, and only when that integer actually changes. Arrow keys step through the same spring the hand does, so the keyboard is not a second, worse path to the same control.
Lever
An industrial breaker lever with a real over-centre mechanism. Displayed travel lags the raw pointer travel by a bump curve peaked at the threshold, so approaching it the handle drags heavier, and crossing it the lag collapses and the handle races ahead of the finger. That is why a half-hearted push falls back the way a real breaker does. Release projects the flick's velocity past the threshold before choosing a side, so momentum can finish a throw the finger only started, and the keyboard commits through exactly the same spring the hand uses. The throw is a motion value. React holds only the committed side.
Focus Grid
A five-tile bento where any tile you pick takes the large slot and the rest slide back into order around it.
Hover List
A display-type list where a shared accent block springs between rows on hover while the text indents and inverts.