Confetti send button
A send button with a full little story: the label slides, a ring spins while sending, a tick draws itself and paper confetti bursts out, flutters and catches the light.
"use client";
import { useEffect, useRef, useState } from "react";
import "./confetti-button.css";
type Bit = {
x: number;
y: number;
vx: number;
vy: number;
r: number;
vr: number;
phase: number;
size: number;
color: string;
shape: 0 | 1 | 2;
};
const COLORS = [
"#ff5a1f",
"#d7ff3a",
"#2b35ff",
"#f3eee3",
"#ff3d8b",
"#ffb21f",
];
/** Throws paper confetti out of the button, drawn on a canvas that covers the area. */
function burst(cv: HTMLCanvasElement | null, b: HTMLElement | null) {
if (!cv || !b) return;
const ctx = cv.getContext("2d")!;
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const dpr = Math.min(2, window.devicePixelRatio || 1);
const W = cv.offsetWidth;
const H = cv.offsetHeight;
cv.width = W * dpr;
cv.height = H * dpr;
const cx = W / 2;
const cy = H / 2 + 20;
const count = reduce ? 0 : 110;
const bits: Bit[] = Array.from({ length: count }, (_, i) => {
const a = -Math.PI / 2 + (Math.random() - 0.5) * 1.9;
const sp = 7 + Math.random() * 9;
return {
x: cx + (Math.random() - 0.5) * b.offsetWidth * 0.8,
y: cy,
vx: Math.cos(a) * sp,
vy: Math.sin(a) * sp,
r: Math.random() * Math.PI,
vr: (Math.random() - 0.5) * 0.35,
phase: Math.random() * Math.PI * 2,
size: 6 + Math.random() * 6,
color: COLORS[i % COLORS.length],
shape: (i % 3) as 0 | 1 | 2,
};
});
const start = performance.now();
const frame = (now: number) => {
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, W, H);
const age = (now - start) / 1000;
for (const p of bits) {
p.vy += 0.32;
p.vx *= 0.975;
p.vy *= 0.975;
p.x += p.vx + Math.sin(p.phase + age * 6) * 0.6;
p.y += p.vy;
p.r += p.vr;
p.phase += 0.18;
// The flutter: a paper piece turning shows its thin edge, then its face.
const turn = Math.cos(p.phase);
ctx.save();
ctx.translate(p.x, p.y);
ctx.rotate(p.r);
ctx.scale(1, turn);
ctx.globalAlpha = Math.max(0, 1 - Math.max(0, age - 1.6) / 0.8);
ctx.fillStyle = p.color;
ctx.strokeStyle = p.color;
if (p.shape === 0)
ctx.fillRect(-p.size / 2, -p.size / 4, p.size, p.size / 2);
else if (p.shape === 1) {
ctx.beginPath();
ctx.arc(0, 0, p.size / 3, 0, Math.PI * 2);
ctx.fill();
} else {
ctx.lineWidth = 2.4;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(-p.size / 2, 0);
ctx.quadraticCurveTo(0, -p.size / 1.5, p.size / 2, 0);
ctx.stroke();
}
// A glint when the face turns toward you.
if (turn > 0.92) {
ctx.fillStyle = "rgba(255,255,255,0.55)";
ctx.fillRect(-p.size / 4, -1, p.size / 2, 2);
}
ctx.restore();
}
if (age < 2.4) requestAnimationFrame(frame);
else ctx.clearRect(0, 0, W, H);
};
if (count) requestAnimationFrame(frame);
}
/**
* ConfettiButton: a send button that celebrates.
* - Press it: the label slides away, a ring draws while it "sends", then a tick draws itself.
* - At that moment paper confetti bursts out of the button, flutters (each piece turns and catches the light) and falls.
*/
export function ConfettiButton({
label = "Send invites",
busyLabel = "Sending",
doneLabel = "Invites sent",
theme = "dark",
onSend,
}: {
label?: string;
busyLabel?: string;
doneLabel?: string;
theme?: "light" | "dark";
onSend?: () => void;
}) {
const [state, setState] = useState<"idle" | "busy" | "done">("idle");
const canvas = useRef<HTMLCanvasElement>(null);
const btn = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (state === "busy") {
const t = window.setTimeout(() => setState("done"), 1100);
return () => window.clearTimeout(t);
}
if (state === "done") {
burst(canvas.current, btn.current);
const t = window.setTimeout(() => setState("idle"), 3200);
return () => window.clearTimeout(t);
}
}, [state]);
return (
<div className="gu-confetti" data-theme={theme}>
<canvas ref={canvas} className="gu-confetti__canvas" aria-hidden="true" />
<button
ref={btn}
type="button"
className="gu-confetti__btn"
data-state={state}
aria-disabled={state !== "idle"}
onClick={() => {
if (state !== "idle") return;
setState("busy");
onSend?.();
}}
>
<span className="gu-confetti__icon" aria-hidden="true">
<svg viewBox="0 0 24 24">
{state === "idle" && (
<path
className="gu-confetti__plane"
d="M3.5 11.5 20 4l-5.5 16-3.2-6.7Z M11.3 13.3 20 4"
/>
)}
{state === "busy" && (
<circle
className="gu-confetti__ring"
cx="12"
cy="12"
r="8"
pathLength={1}
/>
)}
{state === "done" && (
<path
className="gu-confetti__tick"
d="m5.5 12.5 4.2 4.2 8.8-9.4"
pathLength={1}
/>
)}
</svg>
</span>
<span className="gu-confetti__text" key={state}>
{state === "idle" ? label : state === "busy" ? busyLabel : doneLabel}
</span>
</button>
<span className="gu-confetti__sr" role="status">
{state === "done" ? doneLabel : ""}
</span>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Confetti send button
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A big pill "Send invites" button that tells a small story when pressed: the label slides up and is replaced by "Sending" while a ring spins and a shine sweeps across; after 1.1s it turns lime, pops, draws a tick and bursts paper confetti out of itself. The confetti flutters (pieces turn and catch the light) and falls. After 3.2s it returns to its first state.
## Layout and look
- A 560 × 380 area with the button centred and a full-size canvas over it for the confetti (pointer-events none).
- Button: 64px tall, pill, padding 0 30px 0 22px, orange #ff5a1f, ink text #0e0e10, 18px weight 800, orange glow shadow and a thin inner top highlight. A 34px round icon well holds a paper-plane icon.
- Busy: pale orange #ffb08f with a white shine sweeping across (1.1s loop). Done: lime #d7ff3a with a lime glow.
- Confetti colours: #ff5a1f, #d7ff3a, #2b35ff, #f3eee3, #ff3d8b, #ffb21f. Three shapes: thin rectangles, dots and small curved streamers.
## Behavior and motion
1. Hover: scale 1.04 and the plane wiggles. Press: 0.94. Spring cubic-bezier(0.34,1.56,0.64,1).
2. Each state change re-mounts the label with a 500ms slide-up blur-in.
3. Confetti: 110 pieces launched upward in a 110° cone from across the button width, speed 7–16 px/frame, gravity 0.32, air drag 0.975, a sideways sway, spin. Each frame the piece is scaled vertically by cos(phase) so it looks like paper turning; when the face turns toward you (cos > 0.92) a white glint is drawn. Pieces fade out between 1.6s and 2.4s. Canvas uses devicePixelRatio (max 2).
4. The tick uses stroke-dashoffset 1 → 0 over 500ms.
## Accessibility
- A real button with aria-disabled while busy. A visually hidden role="status" says the done label so screen readers hear it.
- prefers-reduced-motion: no confetti, no spinning or shine; states change instantly.
## Props
label, busyLabel, doneLabel, theme, onSend (called when pressed).
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### ConfettiButton.tsx
```tsx
"use client";
import { useEffect, useRef, useState } from "react";
import "./confetti-button.css";
type Bit = {
x: number;
y: number;
vx: number;
vy: number;
r: number;
vr: number;
phase: number;
size: number;
color: string;
shape: 0 | 1 | 2;
};
const COLORS = [
"#ff5a1f",
"#d7ff3a",
"#2b35ff",
"#f3eee3",
"#ff3d8b",
"#ffb21f",
];
/** Throws paper confetti out of the button, drawn on a canvas that covers the area. */
function burst(cv: HTMLCanvasElement | null, b: HTMLElement | null) {
if (!cv || !b) return;
const ctx = cv.getContext("2d")!;
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const dpr = Math.min(2, window.devicePixelRatio || 1);
const W = cv.offsetWidth;
const H = cv.offsetHeight;
cv.width = W * dpr;
cv.height = H * dpr;
const cx = W / 2;
const cy = H / 2 + 20;
const count = reduce ? 0 : 110;
const bits: Bit[] = Array.from({ length: count }, (_, i) => {
const a = -Math.PI / 2 + (Math.random() - 0.5) * 1.9;
const sp = 7 + Math.random() * 9;
return {
x: cx + (Math.random() - 0.5) * b.offsetWidth * 0.8,
y: cy,
vx: Math.cos(a) * sp,
vy: Math.sin(a) * sp,
r: Math.random() * Math.PI,
vr: (Math.random() - 0.5) * 0.35,
phase: Math.random() * Math.PI * 2,
size: 6 + Math.random() * 6,
color: COLORS[i % COLORS.length],
shape: (i % 3) as 0 | 1 | 2,
};
});
const start = performance.now();
const frame = (now: number) => {
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, W, H);
const age = (now - start) / 1000;
for (const p of bits) {
p.vy += 0.32;
p.vx *= 0.975;
p.vy *= 0.975;
p.x += p.vx + Math.sin(p.phase + age * 6) * 0.6;
p.y += p.vy;
p.r += p.vr;
p.phase += 0.18;
// The flutter: a paper piece turning shows its thin edge, then its face.
const turn = Math.cos(p.phase);
ctx.save();
ctx.translate(p.x, p.y);
ctx.rotate(p.r);
ctx.scale(1, turn);
ctx.globalAlpha = Math.max(0, 1 - Math.max(0, age - 1.6) / 0.8);
ctx.fillStyle = p.color;
ctx.strokeStyle = p.color;
if (p.shape === 0)
ctx.fillRect(-p.size / 2, -p.size / 4, p.size, p.size / 2);
else if (p.shape === 1) {
ctx.beginPath();
ctx.arc(0, 0, p.size / 3, 0, Math.PI * 2);
ctx.fill();
} else {
ctx.lineWidth = 2.4;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(-p.size / 2, 0);
ctx.quadraticCurveTo(0, -p.size / 1.5, p.size / 2, 0);
ctx.stroke();
}
// A glint when the face turns toward you.
if (turn > 0.92) {
ctx.fillStyle = "rgba(255,255,255,0.55)";
ctx.fillRect(-p.size / 4, -1, p.size / 2, 2);
}
ctx.restore();
}
if (age < 2.4) requestAnimationFrame(frame);
else ctx.clearRect(0, 0, W, H);
};
if (count) requestAnimationFrame(frame);
}
/**
* ConfettiButton: a send button that celebrates.
* - Press it: the label slides away, a ring draws while it "sends", then a tick draws itself.
* - At that moment paper confetti bursts out of the button, flutters (each piece turns and catches the light) and falls.
*/
export function ConfettiButton({
label = "Send invites",
busyLabel = "Sending",
doneLabel = "Invites sent",
theme = "dark",
onSend,
}: {
label?: string;
busyLabel?: string;
doneLabel?: string;
theme?: "light" | "dark";
onSend?: () => void;
}) {
const [state, setState] = useState<"idle" | "busy" | "done">("idle");
const canvas = useRef<HTMLCanvasElement>(null);
const btn = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (state === "busy") {
const t = window.setTimeout(() => setState("done"), 1100);
return () => window.clearTimeout(t);
}
if (state === "done") {
burst(canvas.current, btn.current);
const t = window.setTimeout(() => setState("idle"), 3200);
return () => window.clearTimeout(t);
}
}, [state]);
return (
<div className="gu-confetti" data-theme={theme}>
<canvas ref={canvas} className="gu-confetti__canvas" aria-hidden="true" />
<button
ref={btn}
type="button"
className="gu-confetti__btn"
data-state={state}
aria-disabled={state !== "idle"}
onClick={() => {
if (state !== "idle") return;
setState("busy");
onSend?.();
}}
>
<span className="gu-confetti__icon" aria-hidden="true">
<svg viewBox="0 0 24 24">
{state === "idle" && (
<path
className="gu-confetti__plane"
d="M3.5 11.5 20 4l-5.5 16-3.2-6.7Z M11.3 13.3 20 4"
/>
)}
{state === "busy" && (
<circle
className="gu-confetti__ring"
cx="12"
cy="12"
r="8"
pathLength={1}
/>
)}
{state === "done" && (
<path
className="gu-confetti__tick"
d="m5.5 12.5 4.2 4.2 8.8-9.4"
pathLength={1}
/>
)}
</svg>
</span>
<span className="gu-confetti__text" key={state}>
{state === "idle" ? label : state === "busy" ? busyLabel : doneLabel}
</span>
</button>
<span className="gu-confetti__sr" role="status">
{state === "done" ? doneLabel : ""}
</span>
</div>
);
}
```
### confetti-button.css
```css
.gu-confetti {
--spring: cubic-bezier(0.34, 1.56, 0.64, 1);
--ease: cubic-bezier(0.16, 1, 0.3, 1);
--fg: #f3eee3;
position: relative;
display: grid;
place-items: center;
width: min(100%, 560px);
height: 380px;
font-family: ui-sans-serif, system-ui, sans-serif;
}
.gu-confetti[data-theme="light"] {
--fg: #0e0e10;
}
.gu-confetti__canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 2;
}
.gu-confetti__btn {
position: relative;
display: inline-flex;
align-items: center;
gap: 12px;
min-height: 64px;
padding: 0 30px 0 22px;
border: 0;
border-radius: 999px;
background: #ff5a1f;
color: #0e0e10;
font-weight: 800;
font-size: 18px;
line-height: 1;
font-family: inherit;
letter-spacing: -0.01em;
cursor: pointer;
overflow: hidden;
box-shadow:
0 14px 30px -12px rgb(255 90 31 / 0.7),
inset 0 1px 0 rgb(255 255 255 / 0.35);
transition:
background-color 0.5s var(--ease),
scale 0.4s var(--spring),
box-shadow 0.5s var(--ease),
padding 0.5s var(--spring);
}
.gu-confetti__btn:hover {
scale: 1.04;
}
.gu-confetti__btn:active {
scale: 0.94;
}
.gu-confetti__btn:focus-visible {
outline: 3px solid var(--fg);
outline-offset: 4px;
}
.gu-confetti__btn[data-state="busy"] {
background: #ffb08f;
cursor: progress;
}
.gu-confetti__btn[data-state="done"] {
background: #d7ff3a;
box-shadow:
0 14px 30px -12px rgb(215 255 58 / 0.7),
inset 0 1px 0 rgb(255 255 255 / 0.5);
animation: gu-confetti-pop 0.6s var(--spring);
}
@keyframes gu-confetti-pop {
30% {
scale: 1.12;
}
}
/* A shine sweeps across while sending. */
.gu-confetti__btn::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(
100deg,
transparent 30%,
rgb(255 255 255 / 0.55) 50%,
transparent 70%
);
translate: -110% 0;
pointer-events: none;
}
.gu-confetti__btn[data-state="busy"]::after {
animation: gu-confetti-shine 1.1s var(--ease) infinite;
}
@keyframes gu-confetti-shine {
to {
translate: 110% 0;
}
}
.gu-confetti__icon {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border-radius: 50%;
background: rgb(14 14 16 / 0.12);
}
.gu-confetti__icon svg {
width: 20px;
height: 20px;
fill: none;
stroke: currentColor;
stroke-width: 2.2;
stroke-linecap: round;
stroke-linejoin: round;
}
.gu-confetti__btn:hover .gu-confetti__plane {
animation: gu-confetti-wiggle 0.6s var(--spring);
}
@keyframes gu-confetti-wiggle {
40% {
translate: 2px -2px;
rotate: -8deg;
}
}
.gu-confetti__plane {
transform-box: fill-box;
transform-origin: center;
}
.gu-confetti__ring {
stroke-dasharray: 0.3 0.7;
transform-box: fill-box;
transform-origin: center;
animation: gu-confetti-spin 0.8s linear infinite;
}
@keyframes gu-confetti-spin {
to {
rotate: 360deg;
}
}
.gu-confetti__tick {
stroke-dasharray: 1;
stroke-dashoffset: 1;
animation: gu-confetti-draw 0.5s 0.1s var(--ease) forwards;
}
@keyframes gu-confetti-draw {
to {
stroke-dashoffset: 0;
}
}
.gu-confetti__text {
display: inline-block;
animation: gu-confetti-text 0.5s var(--spring);
}
@keyframes gu-confetti-text {
from {
opacity: 0;
translate: 0 18px;
filter: blur(4px);
}
}
.gu-confetti__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
.gu-confetti *,
.gu-confetti *::before,
.gu-confetti *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
.gu-confetti__tick {
stroke-dashoffset: 0;
}
}
```
You might also want
Next piece: Dot ripple fieldDot ripple field
Animations, intermediate
Curtain page loader
Animations, intermediate
Loader set
Animations, beginner