asafefe.dev
Lab

Lab/02

Confetti Burst

Ninety particles with velocity, gravity, and spin, removed once they fall out of frame.

  • Canvas
  • Physics
Click anywhere to fire

Installation

Add Confetti to your project with the shadcn CLI. The files land in components/lab, ready to edit.

$ pnpm dlx shadcn@latest add @soultel/lab-confetti

Or by URL: https://asafefe.dev/r/lab-confetti.json

Brings along

  • utils
  • @soultel/lab-canvas

Usage

example.tsx12 lines
import { useRef } from "react"
import { Confetti, type ConfettiHandle } from "@/components/lab/confetti"

export function Example() {
  const confetti = useRef<ConfettiHandle>(null)
  return (
    <div className="relative h-80">
      <Confetti ref={confetti} />
      <button onClick={() => confetti.current?.fire()}>Celebrate</button>
    </div>
  )
}

Props

PropTypeDefaultDescription
refRef<ConfettiHandle>-Call ref.current.fire({ x, y, count, colors }) to burst. Defaults to the center.
colorsstring[]-Particle colors. Repeat one to make it more common.
countnumber90Particles per burst.
gravitynumber0.16Downward pull per frame.
roundRationumber0.2Share of dots instead of strips.