Press & Microinteractions
The 11 effects P01–P11: purpose, API, options, examples, reduced motion and cost.
Experimental and not on npm
Press effects respond to real activation, pointer or keyboard, and never change what the control does. <Press> accepts one preset or a list. Triggered effects (burst, shake, nudge) play when their trigger value changes after mounting; the initial value never plays. ToggleMorph and CheckboxDraw are decorative visuals for inside your own labelled control. Disabled elements never react.
P01 · Press scale
pressScale shrinks the control while it is held: scale (0.96, between 0.5 and 1) and spring. Under reduced motion half of the amplitude remains, without the spring, because it confirms the press.
- Import
@neshel-ui/animations/press- API
pressScale, Press- Stylesheet
- none needed
- 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.
"use client";
import { Press, pressScale } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
export default function P01Example() {
return (
<Press preset={pressScale} options={{ scale: 0.92 }} asChild>
<Button>Press me</Button>
</Press>
);
}Options: PressScaleOptions
PressScaleOptions
P01 — Press scale: shrink while pressed, spring back on release (pointer, Space/Enter).
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | — | Turn the effect off. Disabled elements (:disabled, aria-disabled="true") never react. |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"). |
| scale | number | — | Scale while pressed (0.5–1, default 0.96). Reduced motion keeps half the amplitude, without spring. |
| spring | SpringOptions | SpringPreset | — | — |
P02 · Ripple
ripple expands a circle from the point of contact, or from the centre with the keyboard: color, opacity (0.22) and duration (550 ms). It draws on a child layer owned by the package.
- Import
@neshel-ui/animations/press- API
ripple, Press- Stylesheet
@neshel-ui/animations/press.css- Reduced motion
fade— opacity only, no travel- Performance
- Web Animations on a layer owned by the package; nothing runs per frame in JavaScript.
"use client";
import "@neshel-ui/animations/press.css";
import { Press, ripple } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
export default function P02Example() {
return (
<Press preset={ripple} asChild>
<Button size="lg">Ripple from the pointer</Button>
</Press>
);
}Options: RippleOptions
RippleOptions
P02 — Ripple: an expanding circle from the press point on a clipped, owned layer.
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | currentColor | Ripple colour (default currentColor). |
| disabled | boolean | — | Turn the effect off. Disabled elements (:disabled, aria-disabled="true") never react. |
| duration | number | — | Expansion duration in ms (100–3000, default 550). |
| opacity | number | — | Ripple opacity (0–1, default 0.22). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"). |
P03 · Tap bounce
tapBounce answers a completed tap with a spring bounce: strength (0.3) and spring. It plays after the activation, so it never delays the action.
- Import
@neshel-ui/animations/press- API
tapBounce, Press- 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 { Press, tapBounce } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
export default function P03Example() {
return (
<Press preset={tapBounce} options={{ strength: 0.5 }} asChild>
<Button variant="outline">Tap me</Button>
</Press>
);
}Options: TapBounceOptions
TapBounceOptions
P03 — Tap bounce: a springy squash after each activation (click, including keyboard).
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | — | Turn the effect off. Disabled elements (:disabled, aria-disabled="true") never react. |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"). |
| spring | SpringOptions | SpringPreset | "bouncy" | Spring (default "bouncy"). |
| strength | number | — | Impulse strength (0–1, default 0.3). |
P04 · Toggle morph
<ToggleMorph> draws the track and thumb of a switch and stretches the thumb as checked changes (stretch 0.3). It has no semantics: put it inside a role="switch" button with a name. For a complete control use the Components Switch.
- Import
@neshel-ui/animations/press- API
ToggleMorph, toggleMorph- Stylesheet
@neshel-ui/animations/press.css- Reduced motion
instant— the end state appears at once- Performance
- The package stylesheet renders it on layers owned by the package; your element gets no transition or animation.
"use client";
import "@neshel-ui/animations/press.css";
import { ToggleMorph } from "@neshel-ui/animations/press";
import { useState } from "react";
export default function P04Example() {
const [on, setOn] = useState(false);
return (
<button
type="button"
role="switch"
aria-checked={on}
aria-label="Notifications"
onClick={() => setOn(!on)}
className="rounded-full p-1"
>
<ToggleMorph checked={on} />
</button>
);
}Options: ToggleMorphOptions
ToggleMorphOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| checked(required) | boolean | — | Current state (mirror your switch's checked / aria-checked). |
| reducedMotion | ReducedMotion | — | — |
| spring | SpringOptions | SpringPreset | "snappy" | Thumb spring (default "snappy"). |
| stretch | number | — | Peak stretch of the thumb mid-travel (0–0.6, default 0.3). |
P05 · Checkbox draw
<CheckboxDraw> draws the mark of a checkbox with checked and indeterminate (duration 240 ms). The native input keeps the semantics and the keyboard; hide it visually, not from assistive technology.
- Import
@neshel-ui/animations/press- API
CheckboxDraw, checkboxDraw- Stylesheet
@neshel-ui/animations/press.css- Reduced motion
instant— the end state appears at once- Performance
- The package stylesheet renders it on layers owned by the package; your element gets no transition or animation.
"use client";
import "@neshel-ui/animations/press.css";
import { CheckboxDraw } from "@neshel-ui/animations/press";
import { useState } from "react";
export default function P05Example() {
const [done, setDone] = useState(false);
return (
<label className="flex w-fit items-center gap-2 rounded p-1 has-focus-visible:outline-2">
<input
type="checkbox"
className="sr-only"
checked={done}
onChange={(event) => setDone(event.currentTarget.checked)}
/>
<CheckboxDraw checked={done} /> Send me the summary
</label>
);
}Options: CheckboxDrawOptions
CheckboxDrawOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| checked(required) | boolean | "indeterminate" | — | Current state (mirror your checkbox). |
| duration | number | "fast" | "normal" | "slow" | "deliberate" | 240 | Draw duration in ms or preset (default 240). |
| easing | Easing | EasingPreset | — | — |
| reducedMotion | ReducedMotion | — | — |
P06 · Burst
burst throws particles from the element when trigger changes: count (10), distance (34 px), size and colors. Celebrate rarely; announce the result with text.
- Import
@neshel-ui/animations/press- API
burst, Press- Stylesheet
@neshel-ui/animations/press.css- Reduced motion
static— the decoration or content stays still- Performance
- Web Animations on a layer owned by the package; nothing runs per frame in JavaScript.
"use client";
import "@neshel-ui/animations/press.css";
import { burst, Press } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function P06Example() {
const [likes, setLikes] = useState(0);
return (
<Press preset={burst} options={{ trigger: likes, count: 14 }} asChild>
<Button variant="outline" onClick={() => setLikes(likes + 1)}>
Like ({likes})
</Button>
</Press>
);
}Options: BurstOptions
BurstOptions
P06 — Burst: particles radiate from the centre on an owned layer when trigger changes.
| Prop | Type | Default | Description |
|---|---|---|---|
| colors | readonly string[] | — | Particle colours, cycled (default theme-friendly warm colours). |
| count | number | — | Number of particles (3–24, default 10). |
| disabled | boolean | — | Turn the effect off. Disabled elements (:disabled, aria-disabled="true") never react. |
| distance | number | — | Travel distance in px (8–160, default 34). |
| duration | number | — | Duration in ms (200–3000, default 650). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"). |
| size | number | — | Particle size in px (2–16, default 6). |
| trigger | string | number | boolean | — | Change this value (a counter, a timestamp) to play the effect. The initial value never plays. |
P07 · Shake
shake moves the element sideways when trigger changes: distance (8 px), cycles (4) and duration (420 ms). The error must also be text with role="alert" or aria-describedby; the shake is never the only signal.
- Import
@neshel-ui/animations/press- API
shake, Press- Stylesheet
- none needed
- 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.
Enter your code
"use client";
import { Press, shake } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function P07Example() {
const [errors, setErrors] = useState(0);
return (
<div className="grid justify-items-start gap-3">
<Press
preset={shake}
options={{ trigger: errors }}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
<p role="alert">{errors ? `Wrong code (attempt ${errors})` : "Enter your code"}</p>
</Press>
<Button onClick={() => setErrors(errors + 1)}>Submit a wrong code</Button>
</div>
);
}Options: ShakeOptions
ShakeOptions
P07 — Shake (error): a short damped horizontal shake. Never the only error signal.
| Prop | Type | Default | Description |
|---|---|---|---|
| cycles | number | — | Oscillations (1–8, default 4). |
| disabled | boolean | — | Turn the effect off. Disabled elements (:disabled, aria-disabled="true") never react. |
| distance | number | — | Amplitude in px (1–30, default 8). Reduced motion: a third, fewer cycles. |
| duration | number | — | Duration in ms (100–2000, default 420). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"). |
| trigger | string | number | boolean | — | Change this value (a counter, a timestamp) to play the effect. The initial value never plays. |
P08 · Nudge
nudge rotates the element briefly to attract attention: angle (6°), cycles (3) and at most three repeats separated by interval. It plays on trigger changes, never in an endless loop.
- Import
@neshel-ui/animations/press- API
nudge, Press- 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 { nudge, Press } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function P08Example() {
const [count, setCount] = useState(0);
return (
<div className="flex items-center gap-4">
<Press
preset={nudge}
options={{ trigger: count, angle: 10 }}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
Inbox ({count})
</Press>
<Button variant="outline" onClick={() => setCount(count + 1)}>
New message
</Button>
</div>
);
}Options: NudgeOptions
NudgeOptions
P08 — Nudge / attention jiggle: a short rotation wiggle, optionally repeated a few times.
| Prop | Type | Default | Description |
|---|---|---|---|
| angle | number | — | Amplitude in degrees (1–20, default 6). |
| cycles | number | — | Oscillations (1–6, default 3). |
| disabled | boolean | — | Turn the effect off. Disabled elements (:disabled, aria-disabled="true") never react. |
| duration | number | — | Duration in ms (100–2000, default 600). |
| interval | number | — | Pause between plays in ms (1000–10000, default 2500). |
| reducedMotion | ReducedMotion | "user" | Reduced-motion policy (default "user"). |
| repeat | number | — | Extra plays after the first (0–3, default 0); never more than 4 plays in total (WCAG 2.2.2). |
| trigger | string | number | boolean | — | Change this value (a counter, a timestamp) to play the effect. The initial value never plays. |
P09 · Number tick
<NumberTick> counts from the previous value to the new one. locale, formatOptions or your own format produce the text; the accessible value does not change on every frame, and live opts into an announcement.
- Import
@neshel-ui/animations/press- API
NumberTick, numberTick- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Updates the text of one decorative node per frame; the accessible value is not updated per frame.
"use client";
import { NumberTick } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function P09Example() {
const [value, setValue] = useState(1280);
return (
<div className="flex items-center gap-4">
<NumberTick value={value} locale="en-US" className="text-3xl font-semibold" />
<Button variant="outline" onClick={() => setValue(value + 1375)}>
Add sales
</Button>
</div>
);
}Options: NumberTickOptions
NumberTickOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | "fast" | "normal" | "slow" | "deliberate" | 600 | Count duration in ms or preset (default 600). |
| easing | Easing | EasingPreset | — | — |
| format | (value: number) => string | Intl.NumberFormat(locale, formatOptions) | Formats the displayed number (default Intl.NumberFormat(locale, formatOptions)). |
| formatOptions | Intl.NumberFormatOptions | — | — |
| locale | string | "en-US" | Locale of the default formatter (default "en-US", explicit so server and client agree). |
| reducedMotion | ReducedMotion | — | — |
| value(required) | number | — | — |
P10 · Content swap
<ContentSwap> swaps its children for confirm while active is true — "Copy link" and "Copied" — in one stacked cell, so the width does not jump. live announces the confirmation.
- Import
@neshel-ui/animations/press- API
ContentSwap, contentSwap- Stylesheet
@neshel-ui/animations/press.css- Reduced motion
fade— opacity only, no travel- Performance
- The package stylesheet renders it on layers owned by the package; your element gets no transition or animation.
"use client";
import "@neshel-ui/animations/press.css";
import { ContentSwap } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function P10Example() {
const [copied, setCopied] = useState(false);
return (
<Button variant="outline" onClick={() => setCopied(!copied)}>
<ContentSwap active={copied} confirm="Copied">
Copy link
</ContentSwap>
</Button>
);
}Options: ContentSwapOptions
ContentSwapOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| reducedMotion | ReducedMotion | — | — |
P11 · Long press
<LongPress> calls onLongPress once after holding for duration (600 ms), with a progress fill; releasing early cancels it. Holding Space or Enter works too, or a single press with keyboard: "press". Offer another path for destructive actions.
- Import
@neshel-ui/animations/press- API
LongPress, longPress- Stylesheet
@neshel-ui/animations/press.css- Reduced motion
reduced— a smaller signal remains because it conveys state- Performance
- Web Animations on a layer owned by the package; nothing runs per frame in JavaScript.
"use client";
import "@neshel-ui/animations/press.css";
import { LongPress } from "@neshel-ui/animations/press";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function P11Example() {
const [archived, setArchived] = useState(false);
return (
<div className="flex items-center gap-4">
<LongPress onLongPress={() => setArchived(true)} duration={800} asChild>
<Button variant="outline">Hold to archive</Button>
</LongPress>
<output>{archived ? "Archived" : "Not archived"}</output>
</div>
);
}Options: LongPressOptions
LongPressOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | — | — |
| duration | number | — | Hold time in ms (200–5000, default 600). |
| keyboard | "hold" | "press" | — | Keyboard: hold Space/Enter for the duration ("hold", default) or activate on one press ("press"). |
| moveTolerance | number | — | px of pointer movement that cancels (2–50, default 10). |
| onCancel | () => void | — | Called when a started press ends without completing. |
| onLongPress | (source: "pointer" | "keyboard") => void | — | Called once per completed long press. |
| pointerTypes | readonly ("mouse" | "pen" | "touch")[] | — | Pointer types that may long-press (default mouse, pen and touch). |
| reducedMotion | ReducedMotion | "user" | Reduced motion keeps a linear, non-vestibular fill (the progress conveys state). Default "user". |