GooseUI

Components

Click Sparks

New

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

npx shadcn@latest add @gooseui/click-sparks
pnpm dlx shadcn@latest add @gooseui/click-sparks
yarn dlx shadcn@latest add @gooseui/click-sparks
bunx --bun shadcn@latest add @gooseui/click-sparks

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

PropTypeDefaultDescription
colorstring"currentColor"Stroke color, any CSS color or var()
countnumber8Sparks per click
radiusnumber24Distance the sparks travel, in pixels
lengthnumber10Initial stroke length, in pixels
lineWidthnumber2Stroke width, in pixels
durationnumber400Lifetime 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]
disabledbooleanfalseTurns the effect off
classNamestring-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