Skip to content
Calm motion: animations on this site only fade, with no movement

Confetti ​

A burst of paper for the moment something goes right

A short celebration for a finished task, a sent message, or a first sale. You fire it from code, and there is nothing on the page until you call fire(). Use it for one moment that the reader earned, not as decoration. For a message that has to be read, use Toaster or Alert. Confetti carries no words.

Fire from a button
  • Put one <BlessConfetti ref="confetti" /> in the page and call confetti.fire(from?, angle?). from is an element to burst out of, a { x, y } point in viewport pixels, or nothing for the lower middle of the window. angle points the cone (default 270°, straight up). Fire several times and the bursts overlap.
  • It draws on one canvas over the page. The canvas lets every click through. It removes the pieces after duration, or when they leave the bottom of the window. finish fires when the last piece is gone.
  • With prefers-reduced-motion nothing is drawn and finish fires at once. The canvas is hidden from screen readers, so say what happened in words too (an aria-live line, a toast). The burst is only the cheer.
  • colors takes token names (chart-2, warning…) or CSS colors. count, spread (360 = all around), power and gravity shape the burst.

Usage ​

ts
import { BlessConfetti } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
countnumber90pieces per burst
colorsstring[]["chart-1", "chart-2", "chart-3", "chart-4", "chart-5", "warning"]token names (`chart-2`, `accent`…) or CSS colours
durationnumber2200milliseconds until the last piece has faded
spreadnumber80width of the cone the pieces leave in, degrees; 360 is all around
powernumber900launch strength, px per second
gravitynumber1400

Events

NamePayloadDescription
finish[]

Exposed

NameTypeDescription
fire(from?: HTMLElement | { x: number; y: number; } | undefined, angle?: number) => undefined
stop() => void

Released under the MIT License. Character names and artwork belong to their owners.