components / feedback
Confetti
A burst of confetti from a function call or from any element, with no dependencies.
confetti-default.tsx
"use client";
import { Button } from "@/components/ui/button";
import { Confetti } from "@/components/ui/confetti";
export default function ConfettiDefault() {
return (
<Confetti>
<Button variant="brand">Celebrate</Button>
</Confetti>
);
}Installation
$ npx shadcn@latest add https://cd-ui.vercel.app/r/confetti.jsonfirst time? set up components.json and the theme first: see installation.
Usage
import { Confetti, confetti } from "@/components/ui/confetti"
// around any element
<Confetti>
<Button>Celebrate</Button>
</Confetti>
// or from a function
confetti({ origin: { x: 200, y: 300 }, count: 80, spread: 360, shapes: ["star"] })Examples
From a function
Call confetti() from any handler. origin takes an element or viewport pixels.
confetti-imperative.tsx
"use client";
import { Button } from "@/components/ui/button";
import { confetti } from "@/components/ui/confetti";
export default function ConfettiImperative() {
return (
<div className="flex flex-wrap justify-center gap-3">
<Button onClick={() => confetti()} variant="outline">
From the center
</Button>
<Button onClick={(e) => confetti({ origin: e.currentTarget, count: 90, spread: 360, shapes: ["star", "circle"] })} variant="outline">
Stars all around
</Button>
<Button onClick={(e) => confetti({ origin: e.currentTarget, spread: 40, power: 1300, colors: ["#e11d48", "#f59e0b"] })} variant="outline">
Narrow and fast
</Button>
</div>
);
}API
Confetti
Wraps one element and fires a burst from its center on an event. It adds no markup and keeps the child's own handlers.
| prop | type | default |
|---|---|---|
onEvent of the child that fires the burst. | "click" | "pointerdown" | "pointerenter" | "click" |
disabledTurns the burst off without removing the wrapper. | boolean | false |
count · spread · angle · colors · shapes · powerEvery option of | ConfettiOptions | - |
confetti
Fires a burst and returns a function that cancels it. Pieces are DOM nodes animated with the Web Animations API (transform and opacity) and removed at the end.
| prop | type | default |
|---|---|---|
originElement (its center) or | Element | { x: number; y: number } | screen center |
countNumber of pieces. Max 200. | number | 60 |
spreadWidth of the cone in degrees. 360 goes in every direction. | number | 70 |
angleDirection of the cone in degrees: 0 right, 90 down, 270 up. | number | 270 |
colorsAny CSS colors, | string[] | - |
shapesMix of | ("square" | "circle" | "strip" | "star")[] | - |
powerLaunch speed in px per second. | number | 900 |
Accessibility
- The layer is
aria-hiddenand ignores the pointer, so it never gets in the way. Say what happened in text too (a toast, a label), because confetti carries no information by itself. - With
prefers-reduced-motionnothing flies:confetti()does nothing and<Confetti>only pulses the child's opacity for 200ms.