A wrapper that throws short spark strokes out of every click point. The sparks are drawn on a canvas on top of the content with pointer-events: none, so clicks still reach buttons and links. The animation loop only runs while sparks are alive.
Preview
Click anywhere in this area
Installation
Usage
Wrap any content. The color follows the text color by default, so set it with a text class.
import { Button } from "@/components/ui/button"
import { ClickSparks } from "@/components/ui/click-sparks"
export default function Example() {
return (
<ClickSparks className="text-primary">
<Button type="button">Click me</Button>
</ClickSparks>
)
}Examples
Around buttons
One wrapper covers a group of buttons. Their own click handlers keep working, and keyboard presses burst from the button center.
<ClickSparks count={10} radius={36} color="var(--primary)" className="flex gap-3">
<Button variant="outline" onClick={like}>Like</Button>
<Button variant="outline" onClick={star}>Star</Button>
</ClickSparks>Color, size and easing
Tune the count, distance, stroke and timing. The easing accepts a preset or your own function.
Burst
Custom easing
<ClickSparks
color="var(--chart-1)"
count={16}
radius={56}
length={18}
lineWidth={1.5}
duration={650}
>
...
</ClickSparks>
const backOut = (t: number) => 1 + 2.70158 * (t - 1) ** 3 + 1.70158 * (t - 1) ** 2
<ClickSparks color="var(--chart-2)" count={6} lineWidth={3} easing={backOut}>
...
</ClickSparks>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | "currentColor" | Stroke color, any CSS color or var() |
| count | number | 8 | Sparks per click |
| radius | number | 24 | Distance the sparks travel, in pixels |
| length | number | 10 | Initial stroke length, in pixels |
| lineWidth | number | 2 | Stroke width, in pixels |
| duration | number | 400 | Lifetime of a burst, in milliseconds |
| easing | "linear" | "ease-in" | "ease-out" | "ease-in-out" | (t: number) => number | "ease-out" | Easing preset or a function from [0, 1] to [0, 1] |
| disabled | boolean | false | Turns the effect off |
| className | string | - | Additional CSS classes for the wrapper |
Features
- Does not block clicks: the canvas ignores the pointer
- Idle when quiet: requestAnimationFrame stops once the last spark fades
- Keyboard friendly: Enter and Space on a button burst from its center
- Reduced motion: with prefers-reduced-motion nothing is drawn