Confetti
Fire a burst of confetti from a button, an element, or any point, drawn on a temporary canvas overlay.
Overview
Confetti marks a real accomplishment: a project shipped, a first payment received, a long task finished. Call confetti() from any event handler, use the useConfetti hook to burst from an element you hold a ref to, or drop in ConfettiButton, which bursts from its own center when clicked.
Pieces are drawn on one shared canvas that covers the viewport. The canvas is created on the first burst and removed as soon as the last piece has fallen, so nothing stays on the page between celebrations. The motion is measured in 60fps frames, so it looks the same on high refresh rate screens. confetti() returns a promise that resolves when the pieces are gone.
Installation
Usage
import { confetti, ConfettiButton, useConfetti } from "@/components/animated/confetti"
// A button that bursts from itself
<ConfettiButton>Celebrate</ConfettiButton>
// Any element
const [ref, fire] = useConfetti<HTMLDivElement>({ particleCount: 60 })
<div ref={ref} onClick={() => fire()}>Done</div>
// Any point, for example both sides of the screen
confetti({ origin: { x: 0, y: window.innerHeight * 0.7 }, angle: 60 })
confetti({ origin: { x: window.innerWidth, y: window.innerHeight * 0.7 }, angle: 120 })Colors accept any canvas color string. A CSS variable such as var(--primary) is resolved against the document when the burst fires.
Accessibility
The canvas is hidden from assistive technology and never receives pointer events, so it cannot block the interface. Pair a burst with a visible message, because the confetti itself says nothing. When the user prefers reduced motion, bursts are skipped by default; set disableForReducedMotion to false only when the celebration carries meaning that is not shown elsewhere.
Use confetti rarely. A burst on every save turns into noise and slows the page.
API Reference
confetti(options) and the function returned by useConfetti accept:
useConfetti(defaults) returns [ref, fire]. ConfettiButton accepts every button prop plus options.