Click Spark

Short strokes burst out from wherever you click, then shrink and fade away.

Preview

Setup

Install with the shadcn CLI

$npx shadcn@latest add https://kinetikui.vercel.app/r/click-spark.json

One command adds every file, the npm packages and any Kinetik components it builds on. Needs a components.json; the CLI offers to create one if your project has none.

Or install manually

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge
  2. 2

    Copy lib/utils.ts from the Code tab. Skip if you already have cn().

  3. 3

    Copy the component from the Code tab and create components/ui/click-spark.tsx in your project.

  4. 4

    Import and render:

    Example
    import { ClickSpark } from "@/components/ui/click-spark"
    
    <ClickSpark>
      <main>…</main>
    </ClickSpark>

No dependencies: it is plain React and Canvas.

Usage

Wrap any area. Every click inside it sends sparks out from the cursor.

import { ClickSpark } from "@/components/ui/click-spark"

export function Page() {
  return (
    <ClickSpark sparkCount={10} sparkRadius={24}>
      <main>…</main>
    </ClickSpark>
  )
}

The sparks use the wrapper's text colour by default, so they follow light and dark mode. Pass sparkColor to pin a colour.

Bursts and triggers

Pick a shape with burst: straight lines, swirling curves, dots, a single expanding ring, or spinning stars. Set trigger="dblclick" to fire only on a double click, so normal clicks stay quiet.

<ClickSpark burst="curves">…</ClickSpark>

<ClickSpark burst="stars" trigger="dblclick">…</ClickSpark>

Sound

Set sound to play a soft synthesised tick on every click, or pass a URL to use your own file. Files are fetched once and decoded, so quick clicks overlap without lag.

<ClickSpark sound volume={0.3}>…</ClickSpark>

<ClickSpark sound="/sounds/pop.mp3">…</ClickSpark>

Props

PropTypeDefaultNotes
burst"lines" | "curves" | "dots" | "ring" | "stars""lines"Shape of the burst. A ring draws one circle per click.
trigger"click" | "dblclick""click"Fire on every click or only on a double click.
sparkColorstringText colourStroke colour.
sparkSizenumber10Length of each stroke at the start, in px.
sparkRadiusnumber18How far the strokes travel, in px.
sparkCountnumber8Strokes per click.
durationnumber400Ms for one burst.
lineWidthnumber2Stroke width in px.
soundboolean | stringfalsetrue for a built-in tick, or a URL to an audio file.
volumenumber0.4Sound volume, 0 to 1.
classNamestring—Applied to the wrapper.

Accessibility

  • The canvas is decorative, hidden from screen readers and ignores pointer events
  • Clicks pass through to the children as normal
  • Sound is off by default, since unexpected audio can be disruptive