Physics & Gestures
The 11 effects G01–G11: purpose, API, options, examples, reduced motion and cost.
Experimental and not on npm
Gestures follow the finger, mouse or pen directly; only what happens by itself afterwards (inertia, springs) is removed under reduced motion. Every functional gesture has a keyboard path, installed when the element is focusable, and a non-drag alternative: built-in buttons, or commands from useGestureControls(). touch-action is set only on the gesture area, so the page keeps scrolling elsewhere. Callbacks fire on start, end and commits; do not set React state per frame.
G01 · Drag with inertia
drag moves the element with inertia. constraints limits it to the parent, an element or a rectangle, elastic (0.35) is the rubber band at the edges, and arrow keys move by keyboardStep (10 px, five times more with Shift).
- Import
@neshel-ui/animations/gestures- API
drag, Gesture- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import { drag, Gesture, useGestureControls } from "@neshel-ui/animations/gestures";
import { Button } from "@neshel-ui/components";
export default function G01Example() {
const controls = useGestureControls();
return (
<div className="grid gap-3">
<div className="relative h-44 rounded-xl bg-neshel-muted">
<Gesture
preset={drag}
options={{ constraints: "parent", controls }}
tabIndex={0}
role="group"
aria-roledescription="draggable"
aria-label="Draggable card"
className="size-16 cursor-grab rounded-xl bg-neshel-primary"
/>
</div>
<div className="flex gap-2">
<Button variant="outline" onClick={() => controls.moveBy(48, 0)}>
Move right
</Button>
<Button variant="outline" onClick={() => controls.reset()}>
Reset
</Button>
</div>
</div>
);
}Options: DragOptions
DragOptions
G01 — Drag with inertia.
| Prop | Type | Default | Description |
|---|---|---|---|
| axis | GestureAxis | "both" | Movement axis (default "both"). |
| constraints | Constraints | — | Limits of the movement: "parent", an element, or px from the rest position. |
| controls | GestureControls | — | Non-gesture alternatives (createGestureControls() / useGestureControls()). |
| decay | DecayOptions | — | Decay of the inertia (power 0–1, timeConstant 50–2000 ms). |
| disabled | boolean | — | Turn the gesture off (disabled elements never react either). |
| elastic | number | — | Rubber band beyond the constraints while dragging (0 hard … 1, default 0.35). |
| inertia | boolean | true | Keep moving after release with exponential decay (default true). |
| keyboardStep | number | — | px per arrow key (1–200, default 10; Shift × 5). Requires a focusable element. |
| onEnd | (position: Point) => void | — | Called when the element comes to rest after a drag, a key or a command. |
| onStart | () => void | — | — |
| pointerTypes | readonly PointerKind[] | — | Pointer kinds that may start the gesture (default mouse, pen and touch). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays. |
| spring | SpringOptions | SpringPreset | "snappy" | Spring used for bounces and keyboard moves (default "snappy"-like 300/30). |
| threshold | number | — | px of movement before the gesture starts (0–40, default 3). |
G02 · Drag and snap
dragSnap releases to the nearest of snap: points, or { grid }. Arrow keys step through the points, controls.snapTo(index) jumps to one, and onSnap reports where it rested.
- Import
@neshel-ui/animations/gestures- API
dragSnap, Gesture- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import { dragSnap, Gesture, useGestureControls } from "@neshel-ui/animations/gestures";
import { Button } from "@neshel-ui/components";
const stops = [{ x: 0 }, { x: 110 }, { x: 220 }];
export default function G02Example() {
const controls = useGestureControls();
return (
<div className="grid gap-3">
<div className="relative h-20 w-72 rounded-xl bg-neshel-muted">
<Gesture
preset={dragSnap}
options={{ axis: "x", snap: stops, controls }}
tabIndex={0}
role="group"
aria-roledescription="draggable"
aria-label="Three-position card"
className="size-16 cursor-grab rounded-xl bg-neshel-primary"
/>
</div>
<div className="flex gap-2">
{["Low", "Medium", "High"].map((label, index) => (
<Button key={label} variant="outline" onClick={() => controls.snapTo(index)}>
{label}
</Button>
))}
</div>
</div>
);
}Options: DragSnapOptions
DragSnapOptions
G02 — Drag constraints + snap points.
| Prop | Type | Default | Description |
|---|---|---|---|
| axis | GestureAxis | "both" | Movement axis (default "both"). |
| constraints | Constraints | — | Limits of the movement: "parent", an element, or px from the rest position. |
| controls | GestureControls | — | Non-gesture alternatives (createGestureControls() / useGestureControls()). |
| decay | DecayOptions | — | Decay of the inertia (power 0–1, timeConstant 50–2000 ms). |
| disabled | boolean | — | Turn the gesture off (disabled elements never react either). |
| elastic | number | — | Rubber band beyond the constraints while dragging (0 hard … 1, default 0.35). |
| keyboardStep | number | — | px per arrow key (1–200, default 10; Shift × 5). Requires a focusable element. |
| onEnd | (position: Point) => void | — | Called when the element comes to rest after a drag, a key or a command. |
| onSnap | (point: Point, index: number) => void | — | Called at rest with the snap point and its index (-1 for grid points). |
| onStart | () => void | — | — |
| pointerTypes | readonly PointerKind[] | — | Pointer kinds that may start the gesture (default mouse, pen and touch). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays. |
| snap | readonly Partial<Point>[] | { grid: Partial<Point>; } | — | Snap points (px from the rest position) or a grid (default: the rest position only). |
| spring | SpringOptions | SpringPreset | "snappy" | Spring used for bounces and keyboard moves (default "snappy"-like 300/30). |
| threshold | number | — | px of movement before the gesture starts (0–40, default 3). |
G03 · Swipe to dismiss
<SwipeDismiss> flings its content away past distance (half the width) or velocity (800 px/s) and then calls onDismiss; you remove the item. It renders a dismiss button, and Delete or Backspace work on focus.
- Import
@neshel-ui/animations/gestures- API
SwipeDismiss, swipeDismiss- Stylesheet
@neshel-ui/animations/gestures.css- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import "@neshel-ui/animations/gestures.css";
import { SwipeDismiss } from "@neshel-ui/animations/gestures";
import { useState } from "react";
export default function G03Example() {
const [notes, setNotes] = useState(["Build passed", "New comment", "Deploy ready"]);
return (
<div className="grid max-w-sm gap-2">
{notes.map((note) => (
<SwipeDismiss
key={note}
direction="x"
onDismiss={() => setNotes((all) => all.filter((item) => item !== note))}
className="rounded-lg bg-neshel-muted p-4 pe-12"
>
{note}
</SwipeDismiss>
))}
{notes.length === 0 ? <p>Nothing left.</p> : null}
</div>
);
}Options: SwipeDismissOptions
SwipeDismissOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| controls | GestureControls | — | Non-gesture alternatives (createGestureControls() / useGestureControls()). |
| direction | SwipeDirection | "x" | Allowed direction(s) (default "x": left or right). |
| disabled | boolean | — | Turn the gesture off (disabled elements never react either). |
| distance | number | — | Fraction of the element's size that dismisses on release (0.1–1, default 0.5). |
| keyboard | boolean | true | Delete / Backspace dismiss when the element is focused (default true). |
| onDismiss | (direction: "left" | "right" | "up" | "down") => void | — | Called once when the element has left; the consumer removes it. |
| pointerTypes | readonly PointerKind[] | — | Pointer kinds that may start the gesture (default mouse, pen and touch). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays. |
| threshold | number | — | px of movement before the gesture starts (0–40, default 3). |
| velocity | number | — | Release speed that dismisses, px/s (100–5000, default 800). |
G04 · Pull to refresh
<PullToRefresh> renders a scroll container. Pulling at the top beyond threshold (72 px), or pressing its refresh button, calls onRefresh once and marks the region aria-busy until the promise settles.
- Import
@neshel-ui/animations/gestures- API
PullToRefresh, pullToRefresh- Stylesheet
@neshel-ui/animations/gestures.css- Reduced motion
reduced— a smaller signal remains because it conveys state- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import "@neshel-ui/animations/gestures.css";
import { PullToRefresh } from "@neshel-ui/animations/gestures";
import { useState } from "react";
export default function G04Example() {
const [loads, setLoads] = useState(0);
return (
<PullToRefresh
scrollerLabel="Feed"
style={{ height: 220 }}
onRefresh={async () => {
await new Promise((resolve) => setTimeout(resolve, 600));
setLoads((n) => n + 1);
}}
>
<p>Refreshed {loads} times. Pull down at the top or use the button.</p>
{Array.from({ length: 10 }, (_, index) => (
<p key={index}>Entry {index + 1}</p>
))}
</PullToRefresh>
);
}Options: PullToRefreshOptions
PullToRefreshOptions
G04 — Pull-to-refresh indicator.
| Prop | Type | Default | Description |
|---|---|---|---|
| controls | GestureControls | — | Non-gesture alternatives (createGestureControls() / useGestureControls()). |
| disabled | boolean | — | Turn the gesture off (disabled elements never react either). |
| onRefresh | () => unknown | — | The refresh action (provided by the consumer); a returned promise keeps the busy state until it settles. |
| onStatus | (status: "refreshing" | "done") => void | — | Called with "refreshing" and "done" (announcements; <PullToRefresh> announces them). |
| pointerTypes | readonly PointerKind[] | — | Pointer kinds that may start the gesture (default mouse, pen and touch). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays. |
| threshold | number | — | Pull distance (px) that triggers a refresh on release (24–240, default 72). |
G05 · Spring follow
springFollow chases motion values (x, y, scale, rotate) with one spring, without React renders. useSpringFollow returns the following value when you want to bind it yourself.
- Import
@neshel-ui/animations/gestures- API
springFollow, useSpringFollow, Gesture- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
"use client";
import { motionValue } from "@neshel-ui/animations/core";
import { Gesture, springFollow } from "@neshel-ui/animations/gestures";
import { useMemo } from "react";
export default function G05Example() {
const x = useMemo(() => motionValue(0), []);
return (
<div className="grid max-w-sm gap-4">
<label className="grid gap-1">
Target
<input
type="range"
min={0}
max={240}
defaultValue={0}
onChange={(event) => x.set(Number(event.currentTarget.value))}
/>
</label>
<Gesture
preset={springFollow}
options={{ x }}
className="size-12 rounded-full bg-neshel-primary"
/>
</div>
);
}Options: SpringFollowOptions
SpringFollowOptions
G05 — Spring follow (value chasing).
| Prop | Type | Default | Description |
|---|---|---|---|
| reducedMotion | ReducedMotion | "user" | Reduced motion jumps to the value (default "user"). |
| rotate | MotionValue | — | Rotation to chase (degrees). |
| scale | MotionValue | — | Scale factor to chase. |
| spring | SpringOptions | SpringPreset | "gentle" | Spring (default "gentle"-like 120/18). |
| x | MotionValue | — | Horizontal translation to chase (px). |
| y | MotionValue | — | Vertical translation to chase (px). |
G06 · Elastic edge
<ElasticScroll> adds a decorative rubber band at the start and the end of a scroll container, for wheel and touch. Listeners are passive and scrolling is never blocked; give the region a label.
- Import
@neshel-ui/animations/gestures- API
ElasticScroll, elasticEdge- Stylesheet
@neshel-ui/animations/gestures.css- Reduced motion
off— no motion at all- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import "@neshel-ui/animations/gestures.css";
import { ElasticScroll } from "@neshel-ui/animations/gestures";
export default function G06Example() {
return (
<ElasticScroll
label="Release notes"
style={{ height: 180 }}
className="rounded-xl border border-neshel-border"
>
{Array.from({ length: 12 }, (_, index) => (
<p key={index} className="px-4 py-1">
Note {index + 1}
</p>
))}
</ElasticScroll>
);
}Options: ElasticEdgeOptions
ElasticEdgeOptions
G06 — Elastic edge (visual overscroll, decorative).
| Prop | Type | Default | Description |
|---|---|---|---|
| axis | "x" | "y" | "y" | Scroll axis of the container (default "y"). |
| disabled | boolean | — | — |
| max | number | — | Maximum visual stretch in px (8–200, default 64). |
| reducedMotion | ReducedMotion | "user" | Decorative: reduced motion turns it off (default "user"). |
G07 · Fling
fling is a free throw: the release velocity decays and bounces on constraints (the parent by default) with bounce (0.5). onRest reports the final position and controls.reset() brings it back.
- Import
@neshel-ui/animations/gestures- API
fling, Gesture- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
"use client";
import { fling, Gesture, useGestureControls } from "@neshel-ui/animations/gestures";
import { Button } from "@neshel-ui/components";
export default function G07Example() {
const controls = useGestureControls();
return (
<div className="grid gap-3">
<div className="relative h-44 rounded-xl bg-neshel-muted">
<Gesture
preset={fling}
options={{ bounce: 0.6, controls }}
tabIndex={0}
role="group"
aria-roledescription="draggable"
aria-label="Puck"
className="size-14 cursor-grab rounded-full bg-neshel-primary"
/>
</div>
<Button variant="outline" onClick={() => controls.reset()}>
Bring it back
</Button>
</div>
);
}Options: FlingOptions
FlingOptions
G07 — Throw / fling with decay.
| Prop | Type | Default | Description |
|---|---|---|---|
| axis | GestureAxis | "both" | Movement axis (default "both"). |
| bounce | number | — | Energy kept when bouncing off a constraint (0–1, default 0.5). |
| constraints | Constraints | — | Limits of the movement: "parent", an element, or px from the rest position. |
| controls | GestureControls | — | Non-gesture alternatives (createGestureControls() / useGestureControls()). |
| decay | DecayOptions | — | Decay of the inertia (power 0–1, timeConstant 50–2000 ms). |
| disabled | boolean | — | Turn the gesture off (disabled elements never react either). |
| elastic | number | — | Rubber band beyond the constraints while dragging (0 hard … 1, default 0.35). |
| keyboardStep | number | — | px per arrow key (1–200, default 10; Shift × 5). Requires a focusable element. |
| onRest | (position: Point) => void | — | Called when the thrown element comes to rest. |
| onStart | () => void | — | — |
| pointerTypes | readonly PointerKind[] | — | Pointer kinds that may start the gesture (default mouse, pen and touch). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays. |
| spring | SpringOptions | SpringPreset | "snappy" | Spring used for bounces and keyboard moves (default "snappy"-like 300/30). |
| threshold | number | — | px of movement before the gesture starts (0–40, default 3). |
G08 · Pinch zoom
<PinchZoom> zooms an image between minScale and maxScale (1–4) with two fingers, pans while zoomed and toggles with a double tap. Zoom buttons and the keys +, - and 0 do the same; one-finger page scrolling stays available at scale 1.
- Import
@neshel-ui/animations/gestures- API
PinchZoom, pinchZoom- Stylesheet
@neshel-ui/animations/gestures.css- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import "@neshel-ui/animations/gestures.css";
import { PinchZoom } from "@neshel-ui/animations/gestures";
import { picture } from "./picture";
export default function G08Example() {
return (
<PinchZoom maxScale={4} style={{ width: 360, maxWidth: "100%" }}>
<img src={picture("Map", 120, 200)} alt="Green map" width={640} height={400} />
</PinchZoom>
);
}Options: PinchZoomOptions
PinchZoomOptions
G08 — Pinch-zoom media.
| Prop | Type | Default | Description |
|---|---|---|---|
| controls | GestureControls | — | Non-gesture alternatives (createGestureControls() / useGestureControls()). |
| disabled | boolean | — | Turn the gesture off (disabled elements never react either). |
| doubleTapScale | number | — | Scale of a double tap / double click (1–10, default 2; 1 disables). |
| maxScale | number | — | Maximum scale (1–10, default 4). |
| minScale | number | — | Minimum scale (0.5–1, default 1). |
| onZoomChange | (scale: number) => void | — | Called with the scale after a gesture, a key or a command. |
| pointerTypes | readonly PointerKind[] | — | Pointer kinds that may start the gesture (default mouse, pen and touch). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays. |
| spring | SpringOptions | SpringPreset | — | — |
| step | number | — | Factor of the zoom keys and buttons (1.1–4, default 1.5). |
| threshold | number | — | px of movement before the gesture starts (0–40, default 3). |
| wheel | boolean | — | Ctrl/⌘ + wheel and trackpad pinch zoom over the frame (opt-in; prevents the page zoom there). |
G09 · Rotate gesture
rotateGesture rotates with two fingers, optionally in steps of step degrees, and reports onRotateEnd. The keys [ and ] and controls.rotateBy are the single-pointer alternative.
- Import
@neshel-ui/animations/gestures- API
rotateGesture, Gesture- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import { Gesture, rotateGesture, useGestureControls } from "@neshel-ui/animations/gestures";
import { Button } from "@neshel-ui/components";
export default function G09Example() {
const controls = useGestureControls();
return (
<div className="grid justify-items-start gap-4">
<Gesture
preset={rotateGesture}
options={{ step: 15, controls }}
tabIndex={0}
role="group"
aria-label="Rotatable card, use the bracket keys"
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground m-6"
>
Rotate with two fingers, [ and ]
</Gesture>
<div className="flex gap-2">
<Button variant="outline" onClick={() => controls.rotateBy(-15)}>
−15°
</Button>
<Button variant="outline" onClick={() => controls.rotateBy(15)}>
+15°
</Button>
</div>
</div>
);
}Options: RotateGestureOptions
RotateGestureOptions
G09 — Rotate gesture.
| Prop | Type | Default | Description |
|---|---|---|---|
| controls | GestureControls | — | Non-gesture alternatives (createGestureControls() / useGestureControls()). |
| disabled | boolean | — | Turn the gesture off (disabled elements never react either). |
| keyStep | number | rotateBy | Degrees per [ / ] key and default rotateBy button step (1–90, default 15). |
| onRotateEnd | (degrees: number) => void | — | Called with the rotation (degrees) after a gesture, a key or a command. |
| pointerTypes | readonly PointerKind[] | — | Pointer kinds that may start the gesture (default mouse, pen and touch). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays. |
| spring | SpringOptions | SpringPreset | — | — |
| step | number | — | Snap the rotation to multiples of step degrees on release (0 = free, default 0). |
| threshold | number | — | px of movement before the gesture starts (0–40, default 3). |
G10 · Drag to reorder
<Reorder> asks for a new order through onReorder(from, to); you update your state and the items settle. The package never reorders the DOM. On <ReorderHandle>, Space grabs, arrows move, Escape cancels, and each move is announced once.
- Import
@neshel-ui/animations/gestures- API
Reorder, ReorderItem, ReorderHandle, useReorderItem, reorder- Stylesheet
@neshel-ui/animations/gestures.css- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import "@neshel-ui/animations/gestures.css";
import { Reorder, ReorderHandle, ReorderItem } from "@neshel-ui/animations/gestures";
import { useState } from "react";
export default function G10Example() {
const [tasks, setTasks] = useState(["Draft", "Review", "Translate", "Publish"]);
return (
<Reorder
onReorder={(from, to) =>
setTasks((all) => all.toSpliced(from, 1).toSpliced(to, 0, all[from] as string))
}
className="grid max-w-sm gap-2"
>
{tasks.map((task, index) => (
<ReorderItem
key={task}
index={index}
label={task}
className="flex items-center gap-3 rounded-lg bg-neshel-muted p-3"
>
<ReorderHandle /> {task}
</ReorderItem>
))}
</Reorder>
);
}Options: ReorderOptions
ReorderOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| announce | (message: string) => void | — | Announce a message (default: a shared polite live region; <Reorder> passes its own). |
| announcements | Partial<ReorderAnnouncements> | — | Override the English announcements. |
| axis | "x" | "y" | "y" | List direction (default "y"). |
| disabled | boolean | — | — |
| onReorder | (from: number, to: number) => void | — | Move the item at from to to in the consumer's order (required for the list to change). |
| pointerTypes | readonly PointerKind[] | — | Pointer kinds that may drag (default mouse, pen and touch; touch always needs a handle). |
| reducedMotion | ReducedMotion | "user" | Reduced motion: shifts and settling jump (default "user"). |
| spring | SpringOptions | SpringPreset | — | Spring of shifts and settling (default 420/36). |
G11 · Squash and stretch
squashStretch deforms the element along its velocity while another gesture moves it: intensity (0.25). Combine it as [drag, squashStretch] on one <Gesture>; it is decorative and turns off under reduced motion.
- Import
@neshel-ui/animations/gestures- API
squashStretch, Gesture- Stylesheet
- none needed
- Reduced motion
off— no motion at all- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
"use client";
import { drag, Gesture, squashStretch } from "@neshel-ui/animations/gestures";
export default function G11Example() {
return (
<div className="relative h-44 rounded-xl bg-neshel-muted">
<Gesture
preset={[drag, squashStretch]}
tabIndex={0}
role="group"
aria-roledescription="draggable"
aria-label="Elastic ball"
className="size-16 cursor-grab rounded-full bg-neshel-primary"
/>
</div>
);
}Options: SquashStretchOptions
SquashStretchOptions
G11 — Velocity squash & stretch (decorative).
| Prop | Type | Default | Description |
|---|---|---|---|
| intensity | number | — | Strength (0–1, default 0.25); the deformation never exceeds 25 %. |
| reducedMotion | ReducedMotion | "user" | Decorative: reduced motion turns it off (default "user"). |
| spring | SpringOptions | SpringPreset | — | Spring of the deformation (default 400/24). |