Skip to Content
Neshel-UI
Animations (experimental)Effects

SVG & Paths

The 10 effects S01–S10: 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.

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.
Preview: S01
Preview theme: S01
s01.tsx
"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

PathDrawOptions
PropTypeDefaultDescription
durationnumber—ms (0–10000; default per effect).
easingEasing | EasingPreset——
onComplete(result: MotionResult) => void——
progressProgressSource—Drive from a 0–1 source instead of the own clock.
reducedMotionReducedMotion——
releasebooleantrueRestore the consumer's dash styles when the draw completes forwards (default true).
reversebooleanfalseDraw from the end towards the start (default false).
staggernumber—ms between consecutive paths (0–5000; default 0).
triggerProgressTrigger"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.
Preview: S02
Preview theme: S02
s02.tsx
"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

PathMorphOptions
PropTypeDefaultDescription
durationnumber—ms (0–10000; default per effect).
easingEasing | EasingPreset——
incompatible"error" | "swap"—"error" (default) or "swap".
initialnumber—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——
precisionnumber3Output decimals 0–6 (default 3).
reducedMotionReducedMotion——
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.
Preview: S03
Preview theme: S03
s03.tsx
"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

MotionPathOptions
PropTypeDefaultDescription
durationnumber—ms (0–10000; default per effect).
easingEasing | 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.
progressProgressSource—Drive from a 0–1 source instead of the own clock.
reducedMotionReducedMotion——
repeatnumber—Extra runs (0–1000 or Infinity, explicit).
rotate"auto" | "reverse" | number—"auto" (tangent; default), "reverse", or a fixed angle in degrees.
triggerProgressTrigger"visible"Default "visible" (once); ignored with progress.
yoyoboolean—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.
Preview: S04
Preview theme: S04
s04.tsx
"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

IconMorphOptions
PropTypeDefaultDescription
durationnumber—ms (0–10000; default per effect).
easingEasing | 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——
precisionnumber3Output decimals 0–6 (default 3).
reducedMotionReducedMotion——
shapes(required)Readonly<Record<string, string>>—Named compatible shapes (e.g. menuCloseShapes).
statestring—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.
Preview: S05
Preview theme: S05
s05.tsx
"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

GradientStopsOptions
PropTypeDefaultDescription
durationnumber—One cycle, ms.
onComplete() => void——
reducedMotionReducedMotion——
repeatnumber—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().
yoyobooleantrueAlternate 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.
Preview: S06
Preview theme: S06

Loading the example…

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

ChartDrawOptions
PropTypeDefaultDescription
durationnumber—ms (0–10000; default per effect).
easingEasing | EasingPreset——
lines(required)string | Element | Iterable<Element>—Line elements (or a selector inside the svg).
onComplete(result: MotionResult) => void——
pointsstring | Element | Iterable<Element>—Point markers revealed when the line passes them (selector or elements).
progressProgressSource—Drive from a 0–1 source instead of the own clock.
reducedMotionReducedMotion——
staggernumber150ms between lines (default 150).
triggerProgressTrigger"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.
Preview: S07
Preview theme: S07
s07.tsx
"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

TurbulenceOptions
PropTypeDefaultDescription
amplitudenumber6Displacement in px 0–24 (default 6).
durationnumber—One cycle, ms.
frequencynumber0.02Base frequency 0.001–0.2 (default 0.02).
octavesnumber1Octaves 1–3 (default 1).
onComplete() => void——
ratenumber20Filter updates per second 1–30 (default 20).
reducedMotionReducedMotion——
regionnumber0.1Filter region padding 0–0.25 (default 0.1).
repeatnumber—Extra cycles (0–1000 or Infinity, explicit).
speednumber0.5Frequency 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.
Preview: S08
Preview theme: S08
s08.tsx
"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

LogoRevealOptions
PropTypeDefaultDescription
durationnumber—ms (0–10000; default per effect).
easingEasing | EasingPreset——
onComplete(result: MotionResult) => void——
outlineElement | Iterable<Element>—Decorative outline paths drawn before the mask opens.
patternLogoRevealPattern——
progressProgressSource—Drive from a 0–1 source instead of the own clock.
reducedMotionReducedMotion——
softnessnumber0.15Edge softness 0–0.5 (default 0.15).
triggerProgressTrigger"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.
Preview: S09
Preview theme: S09
s09.tsx
"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

DashFlowOptions
PropTypeDefaultDescription
dashnumber—Dash length (user units, default 6).
durationnumber—One cycle, ms.
gapnumber—Gap length (user units, default 4).
onComplete() => void——
reducedMotionReducedMotion——
repeatnumber—Extra cycles (0–1000 or Infinity, explicit).
speednumber—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.
Preview: S10
Preview theme: S10

Loading the example…

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

CheckmarkOptions
PropTypeDefaultDescription
checkElementElement—Check element (default: the last path/polyline in the svg).
circlebooleantrueDraw the circle first (default true).
circleElementElement—Circle element (default: the first circle/path in the svg when circle is true).
durationnumber—ms (0–10000; default per effect).
easingEasing | EasingPreset——
onComplete(result: MotionResult) => void——
progressProgressSource—Drive from a 0–1 source instead of the own clock.
reducedMotionReducedMotion——
triggerProgressTrigger"visible"Default "visible" (once); ignored with progress.
Edit on GitHub

On this page