SVG & Paths
The 10 effects S01–S10: purpose, API, options, examples, reduced motion and cost.
Experimental and not on npm
SVG effects work on your own elements and restore them exactly: dash styles, d attributes and gradient stops come back on destroy. Most are hooks that take a ref and return a ref to a control with play, pause, seek, track and drive. Path maths is exported as pure functions (parsePathData, measurePath, interpolatePath). One writer owns an attribute at a time; a second one waits.
S01 · Path draw
usePathDraw draws a path from its start, or from its end with reverse. With release (the default) your own dash pattern returns when it completes. <PathDraw> wraps one shape, and several paths can use stagger.
- Import
@neshel-ui/animations/svg- API
PathDraw, usePathDraw, createPathDraw- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Repaints the element (colour, gradient, clip, mask, blur or stroke) while it runs; keep the area small.
"use client";
import { usePathDraw } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
export default function S01Example() {
const path = useRef<SVGPathElement>(null);
const draw = usePathDraw(path, { trigger: "mount" });
return (
<div className="grid justify-items-start gap-3">
<svg viewBox="0 0 100 60" width={240} aria-hidden="true">
<path
ref={path}
d="M5 50 Q25 0 50 30 T95 10"
fill="none"
stroke="currentColor"
strokeWidth={3}
/>
</svg>
<Button
variant="outline"
onClick={() => {
draw.current?.seek(0);
draw.current?.play();
}}
>
Draw again
</Button>
</div>
);
}Options: PathDrawOptions
PathDrawOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | — | ms (0–10000; default per effect). |
| easing | Easing | EasingPreset | — | — |
| onComplete | (result: MotionResult) => void | — | — |
| progress | ProgressSource | — | Drive from a 0–1 source instead of the own clock. |
| reducedMotion | ReducedMotion | — | — |
| release | boolean | true | Restore the consumer's dash styles when the draw completes forwards (default true). |
| reverse | boolean | false | Draw from the end towards the start (default false). |
| stagger | number | — | ms between consecutive paths (0–5000; default 0). |
| trigger | ProgressTrigger | "visible" | Default "visible" (once); ignored with progress. |
S02 · Path morph
usePathMorph moves between shapes whose commands are compatible; to(index) continues from the rendered shape if it is interrupted. incompatible decides between an error and a swap; paths are never resampled.
- Import
@neshel-ui/animations/svg- API
usePathMorph, createPathMorph- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Writes one SVG path attribute per frame; the cost grows with the number of path segments.
"use client";
import { usePathMorph } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useRef, useState } from "react";
const shapes = ["M10 50 C30 10 70 10 90 50", "M10 50 C30 90 70 90 90 50"];
export default function S02Example() {
const path = useRef<SVGPathElement>(null);
const morph = usePathMorph(path, { shapes });
const [index, setIndex] = useState(0);
return (
<div className="grid justify-items-start gap-3">
<svg viewBox="0 0 100 100" width={180} aria-hidden="true">
<path
ref={path}
d="M10 50 C30 10 70 10 90 50"
fill="none"
stroke="currentColor"
strokeWidth={4}
/>
</svg>
<Button
variant="outline"
onClick={() => {
setIndex(1 - index);
void morph.current?.to(1 - index);
}}
>
Morph
</Button>
</div>
);
}Options: PathMorphOptions
PathMorphOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | — | ms (0–10000; default per effect). |
| easing | Easing | EasingPreset | — | — |
| incompatible | "error" | "swap" | — | "error" (default) or "swap". |
| initial | number | — | Index shown at creation (default 0; the path's d is not changed until a morph starts). |
| normalize | "exact" | "cubic" | — | "exact" (default) or "cubic" (lines and quadratics promoted to cubics). |
| onComplete | (result: MotionResult) => void | — | — |
| precision | number | 3 | Output decimals 0–6 (default 3). |
| reducedMotion | ReducedMotion | — | — |
| shapes(required) | readonly string[] | — | The shapes (path data), all compatible with each other. |
S03 · Motion path
useMotionPath moves an element along path, in CSS pixels relative to the element, with rotate, repeat and yoyo. It uses offset-path natively and falls back to JavaScript geometry.
- Import
@neshel-ui/animations/svg- API
useMotionPath, createMotionPath- Stylesheet
- none needed
- Reduced motion
static— the decoration or content stays still- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
"use client";
import { useMotionPath } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
export default function S03Example() {
const dot = useRef<HTMLDivElement>(null);
const motion = useMotionPath(dot, { path: "M0 0 C80 -60 160 60 240 0", trigger: "manual" });
return (
<div className="grid justify-items-start gap-3">
<div className="relative h-24 w-72">
<div ref={dot} className="absolute left-2 top-12 size-4 rounded-full bg-neshel-primary" />
</div>
<Button
variant="outline"
onClick={() => {
motion.current?.seek(0);
motion.current?.play();
}}
>
Travel
</Button>
</div>
);
}Options: MotionPathOptions
MotionPathOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | — | ms (0–10000; default per effect). |
| easing | Easing | EasingPreset | — | — |
| mode | "auto" | "native" | "js" | — | "auto" (native when supported; default), "native" or "js". |
| onComplete | (result: MotionResult) => void | — | — |
| path(required) | string | Element | — | Path data in CSS px (element-relative), or a <path> whose d is used as is. |
| progress | ProgressSource | — | Drive from a 0–1 source instead of the own clock. |
| reducedMotion | ReducedMotion | — | — |
| repeat | number | — | Extra runs (0–1000 or Infinity, explicit). |
| rotate | "auto" | "reverse" | number | — | "auto" (tangent; default), "reverse", or a fixed angle in degrees. |
| trigger | ProgressTrigger | "visible" | Default "visible" (once); ignored with progress. |
| yoyo | boolean | — | Alternate direction on repeats. |
S04 · Icon morph
<MorphIcon> changes a decorative icon between named shapes; menuCloseShapes is included. The button around it owns the accessible name and aria-expanded.
- Import
@neshel-ui/animations/svg- API
MorphIcon, createIconMorph, menuCloseShapes- Stylesheet
@neshel-ui/animations/svg.css- Reduced motion
instant— the end state appears at once- Performance
- Writes one SVG path attribute per frame; the cost grows with the number of path segments.
"use client";
import "@neshel-ui/animations/svg.css";
import { MorphIcon, menuCloseShapes } from "@neshel-ui/animations/svg";
import { useState } from "react";
export default function S04Example() {
const [open, setOpen] = useState(false);
return (
<button
type="button"
aria-label="Menu"
aria-expanded={open}
onClick={() => setOpen(!open)}
className="grid size-12 place-items-center rounded-lg border border-neshel-border"
>
<MorphIcon shapes={menuCloseShapes} state={open ? "close" : "menu"} />
</button>
);
}Options: IconMorphOptions
IconMorphOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | — | ms (0–10000; default per effect). |
| easing | Easing | EasingPreset | — | — |
| incompatible | "error" | "swap" | — | "error" (default) or "swap". |
| normalize | "exact" | "cubic" | — | "exact" (default) or "cubic" (lines and quadratics promoted to cubics). |
| onComplete | (result: MotionResult) => void | — | — |
| precision | number | 3 | Output decimals 0–6 (default 3). |
| reducedMotion | ReducedMotion | — | — |
| shapes(required) | Readonly<Record<string, string>> | — | Named compatible shapes (e.g. menuCloseShapes). |
| state | string | — | Initial state name (default: the first key). |
S05 · Gradient stops
useGradientStops animates color, opacity and offset of the stops you list, by index. It is finite by default (repeat: 0) and goes back and forth with yoyo.
- Import
@neshel-ui/animations/svg- API
useGradientStops, createGradientStops- Stylesheet
- none needed
- Reduced motion
static— the decoration or content stays still- Performance
- Repaints the element (colour, gradient, clip, mask, blur or stroke) while it runs; keep the area small.
"use client";
import { useGradientStops } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
export default function S05Example() {
const gradient = useRef<SVGLinearGradientElement>(null);
const stops = useGradientStops(gradient, {
stops: [{ color: ["#193767", "#7c2d12"] }, { color: ["#b45309", "#0f766e"] }],
repeat: 1,
});
return (
<div className="grid justify-items-start gap-3">
<svg viewBox="0 0 100 30" width={260} aria-hidden="true">
<defs>
<linearGradient id="docs-s05" ref={gradient}>
<stop offset="0" stopColor="#193767" />
<stop offset="1" stopColor="#b45309" />
</linearGradient>
</defs>
<rect width="100" height="30" rx="6" fill="url(#docs-s05)" />
</svg>
<Button
variant="outline"
onClick={() => {
stops.current?.stop();
stops.current?.play();
}}
>
Play
</Button>
</div>
);
}Options: GradientStopsOptions
GradientStopsOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | — | One cycle, ms. |
| onComplete | () => void | — | — |
| reducedMotion | ReducedMotion | — | — |
| repeat | number | — | Extra cycles (0–1000 or Infinity, explicit). |
| stops(required) | readonly (GradientStop | undefined)[] | — | Per stop (by index among the gradient's <stop> children). |
| trigger | "visible" | "mount" | "manual" | — | visible/mount start on creation (default); manual waits for play(). |
| yoyo | boolean | true | Alternate back and forth inside a cycle (default true). |
S06 · Chart draw
useChartDraw draws the lines of a chart and shows each of its points as the line reaches it. The animation is not the data: give the SVG a text alternative.
- Import
@neshel-ui/animations/svg- API
useChartDraw, createChartDraw- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Repaints the element (colour, gradient, clip, mask, blur or stroke) while it runs; keep the area small.
Loading the example…
"use client";
import { useChartDraw } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
const data = [
[5, 50],
[30, 30],
[55, 38],
[80, 12],
[95, 18],
] as const;
export default function S06Example() {
const chart = useRef<SVGSVGElement>(null);
const draw = useChartDraw(chart, { lines: "path", points: "circle", trigger: "mount" });
return (
<div className="grid justify-items-start gap-3">
<svg
ref={chart}
viewBox="0 0 100 60"
width={260}
role="img"
aria-label="Sales rise from 10 to 42 in five weeks"
>
<path
d={`M${data.map((point) => point.join(" ")).join("L")}`}
fill="none"
stroke="currentColor"
strokeWidth={2}
/>
{data.map(([x, y]) => (
<circle key={x} cx={x} cy={y} r={2.5} fill="currentColor" />
))}
</svg>
<Button
variant="outline"
onClick={() => {
draw.current?.seek(0);
draw.current?.play();
}}
>
Draw again
</Button>
</div>
);
}Options: ChartDrawOptions
ChartDrawOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | — | ms (0–10000; default per effect). |
| easing | Easing | EasingPreset | — | — |
| lines(required) | string | Element | Iterable<Element> | — | Line elements (or a selector inside the svg). |
| onComplete | (result: MotionResult) => void | — | — |
| points | string | Element | Iterable<Element> | — | Point markers revealed when the line passes them (selector or elements). |
| progress | ProgressSource | — | Drive from a 0–1 source instead of the own clock. |
| reducedMotion | ReducedMotion | — | — |
| stagger | number | 150 | ms between lines (default 150). |
| trigger | ProgressTrigger | "visible" | Default "visible" (once); ignored with progress. |
S07 · Turbulence
useTurbulence wobbles an element with an SVG filter: amplitude (6 px, up to 24), frequency, octaves and an update rate of at most 30 per second. It is off under reduced motion and paused off screen.
- Import
@neshel-ui/animations/svg- API
useTurbulence, createTurbulence- Stylesheet
@neshel-ui/animations/svg.css- Reduced motion
off— no motion at all- Performance
- Uses a filter over the whole area, which is expensive on large surfaces; use it on small or static regions.
"use client";
import "@neshel-ui/animations/svg.css";
import { useTurbulence } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
export default function S07Example() {
const badge = useRef<SVGGElement>(null);
const wobble = useTurbulence(badge, { amplitude: 8, trigger: "manual" });
return (
<div className="grid justify-items-start gap-3">
<svg viewBox="0 0 100 50" width={240} aria-hidden="true">
<g ref={badge}>
<rect x="20" y="10" width="60" height="30" rx="6" fill="currentColor" />
</g>
</svg>
<Button
variant="outline"
onClick={() => {
wobble.current?.stop();
wobble.current?.play();
}}
>
Wobble
</Button>
</div>
);
}Options: TurbulenceOptions
TurbulenceOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| amplitude | number | 6 | Displacement in px 0–24 (default 6). |
| duration | number | — | One cycle, ms. |
| frequency | number | 0.02 | Base frequency 0.001–0.2 (default 0.02). |
| octaves | number | 1 | Octaves 1–3 (default 1). |
| onComplete | () => void | — | — |
| rate | number | 20 | Filter updates per second 1–30 (default 20). |
| reducedMotion | ReducedMotion | — | — |
| region | number | 0.1 | Filter region padding 0–0.25 (default 0.1). |
| repeat | number | — | Extra cycles (0–1000 or Infinity, explicit). |
| speed | number | 0.5 | Frequency oscillation, cycles per second 0–2 (default 0.5). |
| trigger | "visible" | "mount" | "manual" | — | visible/mount start on creation (default); manual waits for play(). |
S08 · Logo reveal
useLogoReveal uncovers a logo with a mask pattern (four wipes or a circle), optionally after drawing outline paths. Without mask support the logo is fully visible; its name is never touched.
- Import
@neshel-ui/animations/svg- API
useLogoReveal, createLogoReveal- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Repaints the element (colour, gradient, clip, mask, blur or stroke) while it runs; keep the area small.
"use client";
import { useLogoReveal } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
export default function S08Example() {
const logo = useRef<SVGSVGElement>(null);
const reveal = useLogoReveal(logo, { pattern: "circle", trigger: "mount" });
return (
<div className="grid justify-items-start gap-3">
<svg ref={logo} viewBox="0 0 90 50" width={200} role="img" aria-label="Example mark">
<path
d="M10 40L30 10L50 40Z M60 40V10L80 40V10"
fill="none"
stroke="currentColor"
strokeWidth={3}
/>
</svg>
<Button
variant="outline"
onClick={() => {
reveal.current?.seek(0);
reveal.current?.play();
}}
>
Reveal again
</Button>
</div>
);
}Options: LogoRevealOptions
LogoRevealOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | — | ms (0–10000; default per effect). |
| easing | Easing | EasingPreset | — | — |
| onComplete | (result: MotionResult) => void | — | — |
| outline | Element | Iterable<Element> | — | Decorative outline paths drawn before the mask opens. |
| pattern | LogoRevealPattern | — | — |
| progress | ProgressSource | — | Drive from a 0–1 source instead of the own clock. |
| reducedMotion | ReducedMotion | — | — |
| softness | number | 0.15 | Edge softness 0–0.5 (default 0.15). |
| trigger | ProgressTrigger | "visible" | Default "visible" (once); ignored with progress. |
S09 · Dash flow
useDashFlow makes the dashes of a path travel: dash, gap and speed (negative reverses). It is finite by default and has play() and pause(); an infinite repeat needs a pause control.
- Import
@neshel-ui/animations/svg- API
useDashFlow, createDashFlow- Stylesheet
- none needed
- Reduced motion
static— the decoration or content stays still- Performance
- Repaints the element (colour, gradient, clip, mask, blur or stroke) while it runs; keep the area small.
"use client";
import { useDashFlow } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
export default function S09Example() {
const path = useRef<SVGPathElement>(null);
const flow = useDashFlow(path, { trigger: "manual" });
return (
<div className="grid justify-items-start gap-3">
<svg viewBox="0 0 120 40" width={260} aria-hidden="true">
<path
ref={path}
d="M5 20H115"
fill="none"
stroke="currentColor"
strokeWidth={3}
strokeDasharray="6 4"
/>
</svg>
<div className="flex gap-2">
<Button variant="outline" onClick={() => flow.current?.play()}>
Flow
</Button>
<Button variant="outline" onClick={() => flow.current?.pause()}>
Pause
</Button>
</div>
</div>
);
}Options: DashFlowOptions
DashFlowOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| dash | number | — | Dash length (user units, default 6). |
| duration | number | — | One cycle, ms. |
| gap | number | — | Gap length (user units, default 4). |
| onComplete | () => void | — | — |
| reducedMotion | ReducedMotion | — | — |
| repeat | number | — | Extra cycles (0–1000 or Infinity, explicit). |
| speed | number | — | Units per second, negative reverses (−400–400; default 40). |
| trigger | "visible" | "mount" | "manual" | — | visible/mount start on creation (default); manual waits for play(). |
S10 · Success checkmark
<SuccessCheck> draws a circle and then a check. It is decorative unless you give it a title; announce success with your own status message, only when it really happened.
- Import
@neshel-ui/animations/svg- API
SuccessCheck, createCheckmark- Stylesheet
@neshel-ui/animations/svg.css- Reduced motion
instant— the end state appears at once- Performance
- Repaints the element (colour, gradient, clip, mask, blur or stroke) while it runs; keep the area small.
Loading the example…
"use client";
import "@neshel-ui/animations/svg.css";
import { SuccessCheck } from "@neshel-ui/animations/svg";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function S10Example() {
const [run, setRun] = useState(0);
return (
<div className="grid justify-items-start gap-3">
<div className="flex items-center gap-2">
<SuccessCheck key={run} trigger="mount" />
<span role="status">Payment received</span>
</div>
<Button variant="outline" onClick={() => setRun(run + 1)}>
Replay
</Button>
</div>
);
}Options: CheckmarkOptions
CheckmarkOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| checkElement | Element | — | Check element (default: the last path/polyline in the svg). |
| circle | boolean | true | Draw the circle first (default true). |
| circleElement | Element | — | Circle element (default: the first circle/path in the svg when circle is true). |
| duration | number | — | ms (0–10000; default per effect). |
| easing | Easing | EasingPreset | — | — |
| onComplete | (result: MotionResult) => void | — | — |
| progress | ProgressSource | — | Drive from a 0–1 source instead of the own clock. |
| reducedMotion | ReducedMotion | — | — |
| trigger | ProgressTrigger | "visible" | Default "visible" (once); ignored with progress. |