Micro-interactions
Lens
A glass lens you drag across live content, bending it through an SVG displacement field with a real bevel and three-channel dispersion. It refracts a live duplicate of its own children rather than the page backdrop, which is the only version of this effect that works in Chrome, Safari and Firefox alike.
Install
# Lens needs no npm packagesThen copy 2 files into your project:
- components/registry/lens/lens.tsx
- hooks/use-animation-loop.ts
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| size | number | 45 | Diameter of the disc, measured against the shorter side of whatever it is dropped into rather than in pixels — so the glass keeps its proportion in a wide hero and in a narrow column alike, and can never outgrow the box on either axis. The displacement map is rasterised once at a fixed resolution and stretched to fit, so dragging this is cheap; regenerating a bitmap per frame would cost far more than the pixels are worth. |
| refraction | number | 0.55 | How far the map pushes the content, and the one number this component is about. It runs through the filter property on a live duplicate rather than through backdrop-filter, because backdrop-filter with an SVG reference is Chromium-only — and CSS.supports reports true in WebKit and Gecko too, so the capability cannot even be detected honestly. |
| edgeThickness | number | 0.3 | How much of the radius is bevel. Real glass does nearly all of its bending in the last fifth, which is why displacing evenly across the whole disc gives a soap bubble rather than a lens. |
| blur | number | 0 | Softening behind the glass, and it ships at zero on purpose. Blur is the fastest way to make a lens look like a smudge — real glass is sharpest dead centre, so anything past about three stops being an optic and becomes a frosted coaster you cannot read through. At zero the blur is dropped from the filter list rather than written as blur(0px), which would still buy a render surface for no visible effect. |
| chromatic | number | 0.22 | Separation between the three channels' displacement — three real passes, isolated by colour matrices and recombined additively. Scaled by the disc rather than fixed in pixels, so the same setting is the same optic at any size. Glass disperses; a single pass with a tinted edge is a smear pretending to be physics. |
| magnify | number | 1.6 | Scale applied to the content inside the disc. It is a real transform rather than a displacement, because displacement can only resample pixels that are already there — faking magnification with it softens the entire window, which is exactly what makes most browser lenses read as a smear. Below one it is a fisheye pushed the wrong way: a real optic, and one that looks broken to everyone who is not an optician. |
| shimmer | number | 0.35 | Speed of the specular travelling the rim. It is the only thing here that moves on its own, and it is what stops a parked lens looking like a screenshot. |
| friction | number | 0.9 | How much of a throw survives, applied per second rather than per frame so the same flick coasts the same distance on a 60Hz and a 120Hz display. |
| bounded | boolean | true | Which box holds the lens in, and what it is looking at. On, it stays inside its container and magnifies a live duplicate of the children you handed it. Off, it is portalled to the body and bound to the viewport instead — dropping the container's own clip is not enough, because any ancestor that clips wins and on a real page there is always one — and what it magnifies becomes the whole page. Either boundary resists and reverses rather than stopping dead; a thrown object that halts against an invisible wall reads as a bug rather than as a boundary. The page is duplicated for real, because no browser API lets an element read arbitrary rendered content: backdrop-filter cannot magnify and is Chromium-only. That copy is a snapshot rather than a live tree, re-taken on every grab, so it cannot carry a running animation, canvas pixels or component state. |
| rimColor | string (hex) | "#e9e6ff" | The colour of the rim highlight, masked to the outermost two pixels so it reads as the lit edge of the glass instead of a ring drawn on top of it. |
What It Demonstrates
- Drag
- Moving an element by grabbing it, often with momentum when released.
- Momentum
- Motion that carries velocity, especially after a drag or interruption.
- Rubber-banding
- Resistance and snap-back when you drag past a boundary (the iOS overscroll feel).
- Damping
- How quickly a spring settles. Lower damping means more bounce and oscillation.
- Blur
- A blur filter used to soften an element or mask tiny imperfections.
- Mask
- Hiding or revealing parts of an element using a shape or gradient — like clip-path, but with soft, fadeable edges.
- Hardware acceleration
- Animating transform and opacity lets the GPU keep motion smooth.
Related Components
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.
Refract
A frosted-glass slab you drag across a live scene, refracting it through a real shader optic. A rounded-rect height field bends three separately-sampled color channels along its gradient, with a Fresnel-bright rim, a travelling specular streak, and a frost that is a genuine multi-tap blur of what sits beneath the pane. Where Lens bends its DOM children through an SVG displacement map and magnifies, Refract is a flat pane over a scene texture with true angle-of-incidence refraction, dispersion and glare, and the scene it bends is drawn in the same shader, because no browser lets WebGL read the rendered page. Throw it and it glides on momentum, rubber-banding off the container walls.
Dismiss
Throw the top card away and the stack closes up behind it. Distance commits, but so does speed — a fast flick from barely anywhere counts, and anything short of both rubber-bands home carrying the velocity you let go at.
Sheet
A bottom sheet with three heights: peek, half and full. Drag the header and let go. The sheet carries the speed of your hand forward and snaps to the height it was heading for, so a short flick from the bottom can reach the top. Pull it past either end and it stretches like a rubber band. Above peek the page behind dims and steps back. A pull or a flick past the bottom closes it. Arrow keys on the handle step between heights, and Escape closes.
Rift
A draggable tear between two overlaid scenes. Push past an edge and it resists, then snaps back.
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.