Confetti for React
Confetti is a React effect that fires a one-shot burst of paper on demand with useConfetti().fire(), for success moments. It idles at zero cost and shows a still badge instead under reduced motion.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/confetti.jsonStudio plan
$48Annual, three seats, billed today.
Ready to order.
ConfettiuseConfetti
Fire from a button
origin takes an element (the burst starts at its centre) or a point of the viewport. Never let confetti be the only sign of success: the text below changes too. With reduced motion the badge appears at the top of the screen instead.
Nothing placed yet.
import { useState } from "react";
import { Button } from "@/components/sheenui/button/button";
import { Confetti, useConfetti } from "@/components/sheenui/confetti/confetti";
// Package build (after the first npm release, or a packed tarball): import { Button, Confetti, useConfetti } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
const { ref, fire } = useConfetti();
const [done, setDone] = useState(0);
return (
<>
<Button
onClick={(event) => {
setDone((n) => n + 1);
fire({ origin: event.currentTarget, count: 140, spread: 100 });
}}
>
Place order
</Button>
<p className="text-sm text-sheen-fg-muted">{done === 0 ? "Nothing placed yet." : "Orders placed: " + done}</p>
<Confetti ref={ref} badge="Order placed" />
</>
);
}Files to copy
4 folders · 4 files · 4 packages
- From
theme/src/ components/confetti/lib/{canvas-effects.ts, cn.ts}hooks/{use-media-query.ts, use-preferences.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/confetti.jsonRegistry item: confetti. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/button/components/spinner/hooks/{use-latest.ts, use-magnetic.ts}motion/{gate.ts, tokens.ts}lib/{form.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Props
Keyboard
Accessibility
- The canvas is decorative and aria-hidden. Always show text or a toast too; confetti is never the only sign of success.
- Reduced motion: fire() draws nothing. With the badge prop, a still message appears for badgeDuration seconds in a polite live region (role=status), so the moment is marked and announced.
- Nothing runs while idle. The loop exists only while pieces are in flight, then the canvas hides itself; a hidden tab ends the burst. Count is capped at 220 and halved on devices with little memory, few cores or Save-Data.
- The canvas lives in a portal on body, never inside a glass surface, so it cannot flatten any glass.
When to use the confetti effect
- Use it for success moments: an order placed, a goal reached, an upload finished, fired from the handler that knows it worked.
- Fire from a button with origin set to that element so the burst starts where the user acted, or from a point of the viewport.
- Always show text or a toast as well; confetti is decoration and never the only sign of success.
- Skip it for routine actions, errors and anything repeated often; it should feel like an occasion.
- Pair it with Button, Toast and the badge prop, which shows a still message instead under reduced motion.
Frequently asked questions
Related pages
19 effects pages in all: browse them on All effects.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .