Components

Confetti

Dependency-free canvas confetti for React: an imperative confetti() helper with origin, angle, spread, gravity, colors and shapes, plus a ConfettiButton that bursts from itself on click. Every burst shares one full-viewport canvas that is created on demand and removed the moment the last piece lands.

  • Zero dependencies
  • Canvas, DPR aware
  • Created on demand
  • Promise per burst
  • prefers-reduced-motion

The burst starts from the button itself.

Installation

$ npx shadcn@latest add https://duskui.com/r/confetti.json

The CLI also installs the DuskUI Button for ConfettiButton. The confetti() helper itself has no dependencies and can be called from any client-side code.

Usage

checkout-success.tsx
"use client"

import { ConfettiButton, confetti } from "@/components/dusk/confetti/confetti"

export function Success() {
  return <ConfettiButton>Celebrate</ConfettiButton>
}

// Or fire it from anywhere, e.g. after a save resolves:
async function onSaved() {
  await confetti({ particleCount: 120, spread: 80, origin: { y: 0.7 } })
}

Examples

Side cannons

Call confetti() twice with mirrored angles and origins at the screen edges. origin is a fraction of the viewport.

Two cannons from the bottom corners of the screen.

Fireworks

A spread of 360 makes a ring; a handful fired on an interval with low gravity reads as fireworks. The interval is cleared on unmount.

Six 360° bursts at random spots, fired from a click handler.

Shapes, colors & physics

Pick from square, circle, star and ribbon, pass any CSS colors (theme variables included), and tune gravity, drift and scalar. ConfettiButton takes them through options.

API Reference

confetti(options) returns a promise that resolves when that burst has settled; confetti.reset() clears the screen. ConfettiButton accepts every DuskUI Button prop plus options; calling event.preventDefault() in its onClick skips the burst. originFromElement(el) turns an element into an origin.

PropTypeDefaultDescription
origin{ x?: number; y?: number }{ x: 0.5, y: 0.6 }Start point as fractions of the viewport. ConfettiButton defaults it to its own centre.
anglenumber90Launch direction in degrees. 90 is up, 0 is right, 270 is down.
spreadnumber60Width of the fan in degrees. 360 is a full ring.
particleCountnumber80Pieces in the burst.
startVelocitynumber22Launch speed in px per 60 fps frame.
gravitynumber0.55Downward pull per frame.
decaynumber0.93Share of velocity kept each frame (air resistance).
driftnumber0Constant sideways push, like wind.
ticksnumber200Lifetime in frames. Pieces fade over the last third.
colorsstring[]primary plus muted zinc, blue, sand and lilacAny CSS colors, including var(--…).
shapes("square" | "circle" | "star" | "ribbon")[]["square", "circle", "ribbon"]Shapes picked at random.
scalarnumber1Size multiplier.
zIndexnumber100z-index of the shared canvas.
disableForReducedMotionbooleantrueSkip the burst when the user prefers reduced motion.

Accessibility

  • The canvas is aria-hidden, ignores the pointer and is removed from the DOM as soon as the last piece settles, so it never blocks clicks or lingers in the accessibility tree.
  • With prefers-reduced-motion nothing is drawn at all. The button and your click handler work exactly the same.
  • Confetti is decoration: pair it with a visible or announced success message rather than relying on it to communicate the result.
  • Physics is time-based, so it runs at the same speed on 60 Hz and 120 Hz screens, and the canvas is sharp on high-DPI displays.