Skip to Content
Neshel-UI
Animations (experimental)Effects

Physics & Gestures

The 11 effects G01–G11: purpose, API, options, examples, reduced motion and cost.

Experimental and not on npm

@neshel-ui/animations is a private package (0.0.0). It cannot be installed, and its API may change before a first publication. These pages document what exists in the repository.

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.
Preview: G01
Preview theme: G01

Loading the example…

g01.tsx
"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.

DragOptions
PropTypeDefaultDescription
axisGestureAxis"both"Movement axis (default "both").
constraintsConstraints—Limits of the movement: "parent", an element, or px from the rest position.
controlsGestureControls—Non-gesture alternatives (createGestureControls() / useGestureControls()).
decayDecayOptions—Decay of the inertia (power 0–1, timeConstant 50–2000 ms).
disabledboolean—Turn the gesture off (disabled elements never react either).
elasticnumber—Rubber band beyond the constraints while dragging (0 hard … 1, default 0.35).
inertiabooleantrueKeep moving after release with exponential decay (default true).
keyboardStepnumber—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——
pointerTypesreadonly PointerKind[]—Pointer kinds that may start the gesture (default mouse, pen and touch).
reducedMotionReducedMotion"user"Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays.
springSpringOptions | SpringPreset"snappy"Spring used for bounces and keyboard moves (default "snappy"-like 300/30).
thresholdnumber—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.
Preview: G02
Preview theme: G02

Loading the example…

g02.tsx
"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.

DragSnapOptions
PropTypeDefaultDescription
axisGestureAxis"both"Movement axis (default "both").
constraintsConstraints—Limits of the movement: "parent", an element, or px from the rest position.
controlsGestureControls—Non-gesture alternatives (createGestureControls() / useGestureControls()).
decayDecayOptions—Decay of the inertia (power 0–1, timeConstant 50–2000 ms).
disabledboolean—Turn the gesture off (disabled elements never react either).
elasticnumber—Rubber band beyond the constraints while dragging (0 hard … 1, default 0.35).
keyboardStepnumber—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——
pointerTypesreadonly PointerKind[]—Pointer kinds that may start the gesture (default mouse, pen and touch).
reducedMotionReducedMotion"user"Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays.
snapreadonly Partial<Point>[] | { grid: Partial<Point>; }—Snap points (px from the rest position) or a grid (default: the rest position only).
springSpringOptions | SpringPreset"snappy"Spring used for bounces and keyboard moves (default "snappy"-like 300/30).
thresholdnumber—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.
Preview: G03
Preview theme: G03

Loading the example…

g03.tsx
"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

SwipeDismissOptions
PropTypeDefaultDescription
controlsGestureControls—Non-gesture alternatives (createGestureControls() / useGestureControls()).
directionSwipeDirection"x"Allowed direction(s) (default "x": left or right).
disabledboolean—Turn the gesture off (disabled elements never react either).
distancenumber—Fraction of the element's size that dismisses on release (0.1–1, default 0.5).
keyboardbooleantrueDelete / 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.
pointerTypesreadonly PointerKind[]—Pointer kinds that may start the gesture (default mouse, pen and touch).
reducedMotionReducedMotion"user"Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays.
thresholdnumber—px of movement before the gesture starts (0–40, default 3).
velocitynumber—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.
Preview: G04
Preview theme: G04

Loading the example…

g04.tsx
"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.

PullToRefreshOptions
PropTypeDefaultDescription
controlsGestureControls—Non-gesture alternatives (createGestureControls() / useGestureControls()).
disabledboolean—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).
pointerTypesreadonly PointerKind[]—Pointer kinds that may start the gesture (default mouse, pen and touch).
reducedMotionReducedMotion"user"Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays.
thresholdnumber—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.
Preview: G05
Preview theme: G05
g05.tsx
"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).

SpringFollowOptions
PropTypeDefaultDescription
reducedMotionReducedMotion"user"Reduced motion jumps to the value (default "user").
rotateMotionValue—Rotation to chase (degrees).
scaleMotionValue—Scale factor to chase.
springSpringOptions | SpringPreset"gentle"Spring (default "gentle"-like 120/18).
xMotionValue—Horizontal translation to chase (px).
yMotionValue—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.
Preview: G06
Preview theme: G06

Loading the example…

g06.tsx
"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).

ElasticEdgeOptions
PropTypeDefaultDescription
axis"x" | "y""y"Scroll axis of the container (default "y").
disabledboolean——
maxnumber—Maximum visual stretch in px (8–200, default 64).
reducedMotionReducedMotion"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.
Preview: G07
Preview theme: G07
g07.tsx
"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.

FlingOptions
PropTypeDefaultDescription
axisGestureAxis"both"Movement axis (default "both").
bouncenumber—Energy kept when bouncing off a constraint (0–1, default 0.5).
constraintsConstraints—Limits of the movement: "parent", an element, or px from the rest position.
controlsGestureControls—Non-gesture alternatives (createGestureControls() / useGestureControls()).
decayDecayOptions—Decay of the inertia (power 0–1, timeConstant 50–2000 ms).
disabledboolean—Turn the gesture off (disabled elements never react either).
elasticnumber—Rubber band beyond the constraints while dragging (0 hard … 1, default 0.35).
keyboardStepnumber—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——
pointerTypesreadonly PointerKind[]—Pointer kinds that may start the gesture (default mouse, pen and touch).
reducedMotionReducedMotion"user"Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays.
springSpringOptions | SpringPreset"snappy"Spring used for bounces and keyboard moves (default "snappy"-like 300/30).
thresholdnumber—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.
Preview: G08
Preview theme: G08

Loading the example…

g08.tsx
"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.

PinchZoomOptions
PropTypeDefaultDescription
controlsGestureControls—Non-gesture alternatives (createGestureControls() / useGestureControls()).
disabledboolean—Turn the gesture off (disabled elements never react either).
doubleTapScalenumber—Scale of a double tap / double click (1–10, default 2; 1 disables).
maxScalenumber—Maximum scale (1–10, default 4).
minScalenumber—Minimum scale (0.5–1, default 1).
onZoomChange(scale: number) => void—Called with the scale after a gesture, a key or a command.
pointerTypesreadonly PointerKind[]—Pointer kinds that may start the gesture (default mouse, pen and touch).
reducedMotionReducedMotion"user"Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays.
springSpringOptions | SpringPreset——
stepnumber—Factor of the zoom keys and buttons (1.1–4, default 1.5).
thresholdnumber—px of movement before the gesture starts (0–40, default 3).
wheelboolean—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.
Preview: G09
Preview theme: G09

Loading the example…

g09.tsx
"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.

RotateGestureOptions
PropTypeDefaultDescription
controlsGestureControls—Non-gesture alternatives (createGestureControls() / useGestureControls()).
disabledboolean—Turn the gesture off (disabled elements never react either).
keyStepnumberrotateByDegrees 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.
pointerTypesreadonly PointerKind[]—Pointer kinds that may start the gesture (default mouse, pen and touch).
reducedMotionReducedMotion"user"Reduced-motion policy (default "user"): automatic motion jumps to its end; direct manipulation stays.
springSpringOptions | SpringPreset——
stepnumber—Snap the rotation to multiples of step degrees on release (0 = free, default 0).
thresholdnumber—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.
Preview: G10
Preview theme: G10

Loading the example…

g10.tsx
"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

ReorderOptions
PropTypeDefaultDescription
announce(message: string) => void—Announce a message (default: a shared polite live region; <Reorder> passes its own).
announcementsPartial<ReorderAnnouncements>—Override the English announcements.
axis"x" | "y""y"List direction (default "y").
disabledboolean——
onReorder(from: number, to: number) => void—Move the item at from to to in the consumer's order (required for the list to change).
pointerTypesreadonly PointerKind[]—Pointer kinds that may drag (default mouse, pen and touch; touch always needs a handle).
reducedMotionReducedMotion"user"Reduced motion: shifts and settling jump (default "user").
springSpringOptions | 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.
Preview: G11
Preview theme: G11
g11.tsx
"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).

SquashStretchOptions
PropTypeDefaultDescription
intensitynumber—Strength (0–1, default 0.25); the deformation never exceeds 25 %.
reducedMotionReducedMotion"user"Decorative: reduced motion turns it off (default "user").
springSpringOptions | SpringPreset—Spring of the deformation (default 400/24).
Edit on GitHub

On this page