Click Burst

A burst of stars and dots from wherever you click.

Preview

"use client";

import { Heart } from "lucide-react";
import { useState } from "react";
import { ClickBurst } from "@/components/motion/click-burst";

export function ClickBurstUsage() {
  const [liked, setLiked] = useState(false);

  return (
    // Bursts from the click point, only when liking.
    <ClickBurst enabled={!liked}>
      <button
        type="button"
        aria-pressed={liked}
        aria-label="Like"
        onClick={() => setLiked((value) => !value)}
        className="grid size-10 place-items-center rounded-full border border-border"
      >
        <Heart className={liked ? "size-4 fill-rose-500 text-rose-500" : "size-4"} />
      </button>
    </ClickBurst>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/click-burst

API Reference

children
ReactNode

The element to burst from: a checkbox, a button, a card. Its own clicks still work.

Default—
enabled?
boolean

Whether a click bursts right now, e.g. only when a task is being checked, not unchecked. Default: true

Defaulttrue
origin?
"center" | "pointer"

Where the burst starts: the click point, or the wrapper's centre. Keyboard clicks always use the centre. Default: "pointer"

Defaultpointer
count?
number

How many pieces fly out. Default: 12

Default12
spread?
number

How far the pieces fly, in px. Default: 34

Default34
colors?
string[]

Piece colours, any CSS colour. Default: green, amber, sky and the theme's primary colour

Default["#10b981", "#f59e0b", "#38bdf8", "var(--primary)"]
className?
string

Classes merged onto the root element.

Default—

Updated