Micro-interactions
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.
Install
bun add motion clsx tailwind-mergeThen copy 2 files into your project:
- components/registry/dismiss/dismiss.tsx
- lib/utils.ts
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| axis | "x" | "y" | "both" | "x" | Which way a card can leave. Sideways is the toast convention; downward reads as filing something away rather than discarding it. |
| threshold | number | 32 | How far across its own width a card must travel to commit. Distance is only half the test — a flick past the speed threshold commits from anywhere. |
| velocityThreshold | number | 520 | Release speed that commits regardless of how far the card actually moved. Without this a quick flick just springs back and the gesture feels deaf. |
| rubberBand | number | 0.35 | Give past the drag bounds. 0 is a hard wall; 1 follows the finger exactly and loses the sense that the card is resisting you. |
| stackDepth | number | 3 | How many cards are visible at once. Past four the ones at the back stop being legible and start being texture. |
| stackOffset | number | 14 | Vertical step between one card and the next down the stack. |
| stackScale | number | 0.05 | Scale lost per card down the stack. This is what sells depth — offset alone reads as a list. |
| rotateOnDrag | number | 8 | Degrees the card leans at the far edge of the throw. Derived from displacement, not animated separately, so an interrupted throw can never desync it. |
| stiffness | number | 420 | How hard the stack springs into its new slot after a card leaves. |
| damping | number | 32 | How fast that spring settles. Low values let the stack overshoot and bounce, which reads as lightweight. |
What It Demonstrates
- Swipe to dismiss
- Dragging an element off-screen to close it, like a drawer or toast.
- Rubber-banding
- Resistance and snap-back when you drag past a boundary (the iOS overscroll feel).
- Velocity
- How fast and in which direction an element is moving. A spring carries it into the next animation when interrupted, so a flicked element keeps its speed.
- Momentum
- Motion that carries velocity, especially after a drag or interruption.
- Interruptible animation
- An animation that can be smoothly redirected mid-flight instead of finishing first.
- Drag
- Moving an element by grabbing it, often with momentum when released.
- Spring
- Motion driven by physics (tension, mass, damping) rather than a set duration.
Related Components
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.
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.
Swipe Actions
List rows you swipe to show actions, like in iOS Mail. Drag a row and its buttons slide in from the side. Swipe all the way and the outer action fills the row and runs. An action like Archive then folds the row away. A quick flick works too. With full swipe off, the row pushes back when you pull past the last button. With a keyboard, the arrow keys show the actions and Enter runs one.
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.
Tear
A ticket with a perforated stub you tear off for real. The ticket is drawn twice and cut from one seeded jag polygon: an attached layer holds everything still connected, the body plus the stub below the tear front, and a flap layer holds only the freed part, rotated about the frontmost attached point, so the torn edges mate tooth for tooth and the swing can never overlap the body. The seam fights back through a resistance curve, a failed tear springs shut, and a completed one lets the stub fall under gravity carrying the release velocity. The jag array comes from a seeded PRNG so the edge never boils between renders.
Magnetic Button
A button that leans into your cursor. Caught in a magnetic field it slides toward the pointer while an amethyst aura swells with proximity, then snaps home on a spring and answers every click with a dark ripple bursting outward from the point of contact.