Motion
confetti
A short burst of flat paper pieces in the chart colours from a point, falling and fading on a canvas over the page, started from code (the handle's fire) and never under reduced motion; it says nothing and takes no clicks.
When to use it
Marking a rare success the person worked for: a first project published, a goal reached. Never for routine actions, never on page load. Say the success in words as well (a toast, a heading): the burst is decoration.
See it working
The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Effects and 3D data page.
Word rotate and pattern
Maps for teams, schools, or newsrooms
Animated beam
A map becomes a film.
Orbit
- Maps
- Charts
- Films
- Motion
Confetti
Not yet published.
Point cloud
- Clay
- Stone
- Glass
| # | width | height | kind |
|---|---|---|---|
| 1 | 0.2 | 1.2 | Clay |
| 2 | 0.2 | 2.1 | Clay |
| 3 | 0.2 | 2.5 | Clay |
| 4 | 0.3 | 0.6 | Clay |
| 5 | 0.3 | 2.2 | Clay |
| 6 | 0.3 | 2.5 | Clay |
| 7 | 0.4 | 0.5 | Clay |
| 8 | 0.5 | 0.6 | Clay |
| 9 | 0.5 | 2.1 | Clay |
| 10 | 0.6 | 1.4 | Clay |
| 11 | 0.7 | 0.7 | Clay |
| 12 | 0.8 | 1.4 | Clay |
| 13 | 0.9 | 0.6 | Clay |
| 14 | 1 | 0.5 | Clay |
| 15 | 1.1 | 2.2 | Clay |
| 16 | 1.2 | 0.6 | Clay |
| 17 | 1.2 | 1.1 | Stone |
| 18 | 1.2 | 1.2 | Stone |
| 19 | 1.2 | 1.2 | Stone |
| 20 | 1.2 | 2.5 | Clay |
| 21 | 1.3 | 1.1 | Clay |
| 22 | 1.3 | 1.3 | Stone |
| 23 | 1.3 | 1.7 | Stone |
| 24 | 1.3 | 2 | Stone |
| 25 | 1.5 | 2.5 | Clay |
| 26 | 1.5 | 2.6 | Stone |
| 27 | 1.5 | 2.8 | Stone |
| 28 | 1.6 | 1.3 | Clay |
| 29 | 1.6 | 2.1 | Clay |
| 30 | 1.6 | 3.1 | Stone |
| 31 | 1.7 | 2 | Clay |
| 32 | 1.7 | 3.1 | Stone |
| 33 | 1.8 | 2 | Clay |
| 34 | 1.8 | 2.9 | Stone |
| 35 | 1.8 | 3.1 | Stone |
| 36 | 1.9 | 1.2 | Clay |
| 37 | 1.9 | 2.7 | Stone |
| 38 | 2 | 2.5 | Clay |
| 39 | 2.1 | 0.6 | Clay |
| 40 | 2.1 | 2.2 | Clay |
| 41 | 2.1 | 2.7 | Stone |
| 42 | 2.2 | 0.7 | Clay |
| 43 | 2.2 | 1.3 | Clay |
| 44 | 2.2 | 1.5 | Clay |
| 45 | 2.2 | 2 | Stone |
| 46 | 2.2 | 2.6 | Glass |
| 47 | 2.2 | 2.6 | Stone |
| 48 | 2.2 | 3.4 | Glass |
| 49 | 2.2 | 3.7 | Glass |
| 50 | 2.3 | 1.8 | Stone |
| 51 | 2.3 | 3.7 | Glass |
| 52 | 2.4 | 1.7 | Glass |
| 53 | 2.4 | 1.8 | Glass |
| 54 | 2.4 | 3.3 | Glass |
| 55 | 2.5 | 1.3 | Stone |
| 56 | 2.6 | 1.2 | Stone |
| 57 | 2.6 | 1.8 | Glass |
| 58 | 2.6 | 2.4 | Glass |
| 59 | 2.7 | 1.2 | Stone |
| 60 | 2.7 | 2.3 | Glass |
| 61 | 2.8 | 1.2 | Stone |
| 62 | 2.9 | 1.3 | Stone |
| 63 | 2.9 | 1.7 | Stone |
| 64 | 2.9 | 2.5 | Glass |
| 65 | 3 | 1.7 | Glass |
| 66 | 3 | 1.9 | Stone |
| 67 | 3 | 3.2 | Glass |
| 68 | 3.1 | 1.8 | Glass |
| 69 | 3.1 | 1.8 | Stone |
| 70 | 3.1 | 2.1 | Stone |
| 71 | 3.1 | 2.6 | Stone |
| 72 | 3.1 | 2.8 | Stone |
| 73 | 3.2 | 2.7 | Stone |
| 74 | 3.2 | 3.1 | Stone |
| 75 | 3.3 | 1.9 | Glass |
| 76 | 3.4 | 2.5 | Glass |
| 77 | 3.4 | 3.7 | Glass |
| 78 | 3.5 | 3.5 | Glass |
| 79 | 3.7 | 2.7 | Glass |
| 80 | 3.7 | 3.4 | Glass |
| 81 | 3.8 | 2.6 | Glass |
| 82 | 3.8 | 3.4 | Glass |
| 83 | 4 | 1.9 | Glass |
| 84 | 4 | 2.5 | Glass |
| 85 | 4 | 3.7 | Glass |
| 86 | 4.1 | 3.3 | Glass |
| 87 | 4.2 | 1.8 | Glass |
| 88 | 4.2 | 2.3 | Glass |
| 89 | 4.2 | 2.4 | Glass |
| 90 | 4.2 | 3.2 | Glass |
| # | width | height | depth | kind |
|---|---|---|---|---|
| 1 | 1.2 | 2.5 | 2.5 | Clay |
| 2 | 3.2 | 2.7 | 3.2 | Stone |
| 3 | 2.9 | 2.5 | 3.8 | Glass |
| 4 | 0.3 | 0.6 | 4.3 | Clay |
| 5 | 2.7 | 1.2 | 4.5 | Stone |
| 6 | 4 | 2.5 | 4.4 | Glass |
| 7 | 0.5 | 2.1 | 4.1 | Clay |
| 8 | 1.6 | 3.1 | 3.5 | Stone |
| 9 | 4.1 | 3.3 | 2.9 | Glass |
| 10 | 1.6 | 1.3 | 2.1 | Clay |
| 11 | 1.2 | 1.2 | 1.4 | Stone |
| 12 | 3.1 | 1.8 | 0.9 | Glass |
| 13 | 2.2 | 1.3 | 0.6 | Clay |
| 14 | 2.1 | 2.7 | 0.5 | Stone |
| 15 | 2.2 | 3.7 | 0.7 | Glass |
| 16 | 1.6 | 2.1 | 1.2 | Clay |
| 17 | 3.1 | 1.8 | 1.8 | Stone |
| 18 | 2.6 | 1.8 | 2.5 | Glass |
| 19 | 0.5 | 0.6 | 3.2 | Clay |
| 20 | 3 | 1.9 | 3.9 | Stone |
| 21 | 3.7 | 3.4 | 4.3 | Glass |
| 22 | 0.3 | 2.5 | 4.5 | Clay |
| 23 | 1.9 | 2.7 | 4.4 | Stone |
| 24 | 4.2 | 2.4 | 4.1 | Glass |
| 25 | 1.2 | 0.6 | 3.5 | Clay |
| 26 | 1.2 | 1.2 | 2.8 | Stone |
| 27 | 3.4 | 2.5 | 2.1 | Glass |
| 28 | 2.1 | 2.2 | 1.4 | Clay |
| 29 | 1.7 | 3.1 | 0.9 | Stone |
| 30 | 2.4 | 3.3 | 0.6 | Glass |
| 31 | 1.9 | 1.2 | 0.5 | Clay |
| 32 | 2.8 | 1.2 | 0.7 | Stone |
| 33 | 2.4 | 1.8 | 1.2 | Glass |
| 34 | 0.8 | 1.4 | 1.8 | Clay |
| 35 | 3.1 | 2.8 | 2.5 | Stone |
| 36 | 3.4 | 3.7 | 3.2 | Glass |
| 37 | 0.2 | 2.1 | 3.9 | Clay |
| 38 | 2.3 | 1.8 | 4.3 | Stone |
| 39 | 4.2 | 1.8 | 4.5 | Glass |
| 40 | 0.9 | 0.6 | 4.4 | Clay |
| 41 | 1.3 | 2 | 4.1 | Stone |
| 42 | 3.8 | 3.4 | 3.5 | Glass |
| 43 | 2 | 2.5 | 2.8 | Clay |
| 44 | 1.5 | 2.6 | 2.1 | Stone |
| 45 | 2.6 | 2.4 | 1.4 | Glass |
| 46 | 2.1 | 0.6 | 0.9 | Clay |
| 47 | 2.5 | 1.3 | 0.6 | Stone |
| 48 | 2.2 | 2.6 | 0.5 | Glass |
| 49 | 1.1 | 2.2 | 0.7 | Clay |
| 50 | 3.2 | 3.1 | 1.2 | Stone |
| 51 | 3 | 3.2 | 1.8 | Glass |
| 52 | 0.2 | 1.2 | 2.5 | Clay |
| 53 | 2.6 | 1.2 | 3.3 | Stone |
| 54 | 4 | 1.9 | 3.9 | Glass |
| 55 | 0.6 | 1.4 | 4.3 | Clay |
| 56 | 1.5 | 2.8 | 4.5 | Stone |
| 57 | 4 | 3.7 | 4.4 | Glass |
| 58 | 1.7 | 2 | 4.1 | Clay |
| 59 | 1.3 | 1.7 | 3.5 | Stone |
| 60 | 3 | 1.7 | 2.8 | Glass |
| 61 | 2.2 | 0.7 | 2.1 | Clay |
| 62 | 2.2 | 2 | 1.4 | Stone |
| 63 | 2.2 | 3.4 | 0.9 | Glass |
| 64 | 1.5 | 2.5 | 0.6 | Clay |
| 65 | 3.1 | 2.6 | 0.5 | Stone |
| 66 | 2.7 | 2.3 | 0.7 | Glass |
| 67 | 0.4 | 0.5 | 1.2 | Clay |
| 68 | 2.9 | 1.3 | 1.8 | Stone |
| 69 | 3.8 | 2.6 | 2.6 | Glass |
| 70 | 0.3 | 2.2 | 3.3 | Clay |
| 71 | 1.8 | 3.1 | 3.9 | Stone |
| 72 | 4.2 | 3.2 | 4.3 | Glass |
| 73 | 1.3 | 1.1 | 4.5 | Clay |
| 74 | 1.2 | 1.1 | 4.4 | Stone |
| 75 | 3.3 | 1.9 | 4.1 | Glass |
| 76 | 2.2 | 1.5 | 3.5 | Clay |
| 77 | 1.8 | 2.9 | 2.8 | Stone |
| 78 | 2.3 | 3.7 | 2.1 | Glass |
| 79 | 1.8 | 2 | 1.4 | Clay |
| 80 | 2.9 | 1.7 | 0.9 | Stone |
| 81 | 2.4 | 1.7 | 0.6 | Glass |
| 82 | 0.7 | 0.7 | 0.5 | Clay |
| 83 | 3.1 | 2.1 | 0.7 | Stone |
| 84 | 3.5 | 3.5 | 1.2 | Glass |
| 85 | 0.2 | 2.5 | 1.8 | Clay |
| 86 | 2.2 | 2.6 | 2.6 | Stone |
| 87 | 4.2 | 2.3 | 3.3 | Glass |
| 88 | 1 | 0.5 | 3.9 | Clay |
| 89 | 1.3 | 1.3 | 4.3 | Stone |
| 90 | 3.7 | 2.7 | 4.5 | Glass |
Model annotations
- Lid — Hinged at the back.
- Side — A handle was here.
- Front — The maker's mark.
Add it
npx shadcn@latest add @rivier-ui/confetti
The registry is named once in components.json: see Installation.
Example
Import it from @/components/motion/confetti.
const confetti = useRef<ConfettiHandle>(null);
<Confetti handleRef={confetti} />
<Button onClick={(e) => confetti.current?.fire({ x: e.clientX, y: e.clientY })}>Publish</Button>
What it needs
A client component: it uses state, effects or browser behaviour. No packages beyond React.
It imports
Source
The whole file. Once copied it is yours: the registry item holds the same text.
"use client";
/**
* @name confetti
* @category motion
* @description A short burst of flat paper pieces in the chart colours from a point, falling and fading on a canvas over the page, started from code (the handle's `fire`) and never under reduced motion; it says nothing and takes no clicks.
* @when Marking a rare success the person worked for: a first project published, a goal reached. Never for routine actions, never on page load. Say the success in words as well (a toast, a heading): the burst is decoration.
* @example
* const confetti = useRef<ConfettiHandle>(null);
* <Confetti handleRef={confetti} />
* <Button onClick={(e) => confetti.current?.fire({ x: e.clientX, y: e.clientY })}>Publish</Button>
*/
import { useEffect, useImperativeHandle, useRef, type ComponentProps, type Ref } from "react";
import { cn } from "@/lib/cn";
import { useMotionSafe } from "@/lib/motion";
import { readThemeColor } from "@/lib/theme-color";
export type ConfettiHandle = {
/** A burst from a point in the window (clientX, clientY); the middle of the window when left out. */
fire: (from?: { x: number; y: number }) => void;
};
export type ConfettiProps = Omit<ComponentProps<"canvas">, "children"> & {
handleRef?: Ref<ConfettiHandle>;
/** Pieces in one burst. Default 120. */
count?: number;
/** Seconds a burst lasts. Default 1.8. */
duration?: number;
};
type Piece = { x: number; y: number; vx: number; vy: number; turn: number; spin: number; w: number; h: number; color: string };
export function Confetti({ handleRef, count = 120, duration = 1.8, className, ...props }: ConfettiProps) {
const canvas = useRef<HTMLCanvasElement>(null);
const pieces = useRef<Piece[]>([]);
const frame = useRef(0);
const started = useRef(0);
const safe = useMotionSafe();
useEffect(() => () => cancelAnimationFrame(frame.current), []);
useImperativeHandle(
handleRef,
() => ({
fire(from) {
const node = canvas.current;
if (!safe || !node) return;
const ratio = Math.min(2, window.devicePixelRatio || 1);
node.width = window.innerWidth * ratio;
node.height = window.innerHeight * ratio;
const context = node.getContext("2d");
if (!context) return;
context.setTransform(ratio, 0, 0, ratio, 0, 0);
const colors = ["--chart-1", "--chart-2", "--chart-3", "--chart-4", "--chart-5"].map((name) => readThemeColor(name, node));
const x = from?.x ?? window.innerWidth / 2;
const y = from?.y ?? window.innerHeight / 2;
pieces.current = Array.from({ length: count }, (_, i) => {
const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI * 0.9;
const speed = 6 + Math.random() * 8;
return { x, y, vx: Math.cos(angle) * speed, vy: Math.sin(angle) * speed, turn: Math.random() * Math.PI, spin: (Math.random() - 0.5) * 0.4, w: 6 + Math.random() * 4, h: 3 + Math.random() * 3, color: colors[i % colors.length] ?? "currentColor" };
});
started.current = performance.now();
cancelAnimationFrame(frame.current);
const step = (now: number): void => {
const age = (now - started.current) / 1000;
context.clearRect(0, 0, window.innerWidth, window.innerHeight);
if (age > duration) return;
const fade = Math.max(0, 1 - age / duration);
for (const p of pieces.current) {
p.vy += 0.35;
p.vx *= 0.985;
p.x += p.vx;
p.y += p.vy;
p.turn += p.spin;
context.save();
context.globalAlpha = fade;
context.translate(p.x, p.y);
context.rotate(p.turn);
context.fillStyle = p.color;
context.fillRect(-p.w / 2, -p.h / 2, p.w, p.h);
context.restore();
}
frame.current = requestAnimationFrame(step);
};
frame.current = requestAnimationFrame(step);
},
}),
[safe, count, duration],
);
return <canvas ref={canvas} data-slot="confetti" aria-hidden="true" className={cn("pointer-events-none fixed inset-0 z-[70] size-full", className)} {...props} />;
}