Confetti Button
MotionA React button that bursts confetti from itself on click, with gravity, drag and spin on a temporary canvas. No library, and skipped for reduced motion.
Installation
npx shadcn@latest add @minidev/confetti-button
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/confetti-button.json
Usage
import { ConfettiButton } from "@/components/ui/confetti-button"
export function Example() {
return (
<ConfettiButton />
)
}
API reference
When to use
A few dozen paper pieces with gravity, drag and spin are drawn on a throwaway canvas and cleaned up when they land; physics are time based, so 60 and 120Hz screens fall at the same speed. No library. Reduced motion skips the burst and keeps the click. It takes every native button prop. Use it for "you did it" moments (first invoice sent, plan upgraded), not for routine saves; for a normal action use Button.
Accessibility
- A native
<button>with afocus-visibleaccent ring, so it behaves like any other button. - The confetti is drawn on a temporary full-screen
<canvas>withpointer-events: none, removed when the pieces land. - Under reduced motion the burst is skipped and
onClickstill runs.
Frequently asked questions
Can I fire the confetti only after a request succeeds?
Not with this component. It bursts on every click, right after your onClick runs, and does not wait for a promise. Use it for actions that finish on click, or show a success state with Toast instead.
Can ConfettiButton submit a form?
Yes. It defaults to type="button", and your props are spread after it, so type="submit" works. The burst still fires on click even if form validation then blocks the submit.
How do I change the confetti colours?
Pass colors as CSS colours. Without it the colours are read from --accent, --accent-2, --success, --warning and --info at click time, so they follow the current theme. count sets pieces per burst (default 70).
Dependencies
npm
Built from
Examples
With a handler
It is a plain button, so onClick runs first and the burst follows; count sets the pieces per click.
Custom colours
colors is the paper palette; pass resolved colours, since the canvas cannot read CSS variables.
Outline style
className restyles the face; token classes keep it on theme while the burst stays the same.