Lab/02
Confetti Burst
Ninety particles with velocity, gravity, and spin, removed once they fall out of frame.
- Canvas
- Physics
Click anywhere to fire
lab/confettiInstallation
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-confettiOr by URL: https://asafefe.dev/r/lab-confetti.json
Brings along
- utils
- @soultel/lab-canvas
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<ConfettiHandle> | - | Call ref.current.fire({ x, y, count, colors }) to burst. Defaults to the center. |
| colors | string[] | - | Particle colors. Repeat one to make it more common. |
| count | number | 90 | Particles per burst. |
| gravity | number | 0.16 | Downward pull per frame. |
| roundRatio | number | 0.2 | Share of dots instead of strips. |
