# Confetti Button

> A 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.

- Kind: Motion component (Motion)
- Docs: https://ui.minidev.pro/docs/confetti-button
- Source (registry JSON with the full file): https://ui.minidev.pro/r/confetti-button.json
- License: MIT. One file, yours to edit after install.

## 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.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/confetti-button
```

Writes `components/ui/confetti-button.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/confetti-button.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { ConfettiButton } from "@/components/ui/confetti-button"
```

From the npm package:

```tsx
import { ConfettiButton } from "minidev-ui-kit/premium/confetti-button"
```

## Usage

```tsx
import { ConfettiButton } from "@/components/ui/confetti-button"

export function Example() {
  return (
    <ConfettiButton />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `count` | `number` | `70` | no | Number of pieces per burst. |
| `colors` | `string[]` | - | no | Piece colours, any CSS colour. Defaults to the accent, accent-2, success, warning and info tokens. |

Also accepts every prop of `<button>`, passed through to the root element.

## Examples

### With a handler

It is a plain button, so onClick runs first and the burst follows; count sets the pieces per click.

```tsx
function MarkPaid() {
  const [paid, setPaid] = React.useState(false)
  return (
    <div className="flex flex-col items-center gap-3">
      <ConfettiButton count={110} onClick={() => setPaid(true)}>
        <CheckIcon className="size-4" /> {paid ? "Paid" : "Mark INV-2041 as paid"}
      </ConfettiButton>
      <p className="text-xs text-fg-muted">{paid ? "Receipt sent to Maya Chen." : "Fires the burst and records the payment."}</p>
    </div>
  )
}
```

### Custom colours

colors is the paper palette; pass resolved colours, since the canvas cannot read CSS variables.

```tsx
<ConfettiButton colors={["#f5b301", "#ff7a59", "#ff4f8b", "#ffffff"]}>
  <RocketIcon className="size-4" /> Ship Lumen 3.0
</ConfettiButton>
```

### Outline style

className restyles the face; token classes keep it on theme while the burst stays the same.

```tsx
<ConfettiButton count={40} className="border border-border bg-surface text-fg shadow-key">
  Celebrate quietly
</ConfettiButton>
```

## Accessibility

- A native `<button>` with a `focus-visible` accent ring, so it behaves like any other button.
- The confetti is drawn on a temporary full-screen `<canvas>` with `pointer-events: none`, removed when the pieces land.
- Under reduced motion the burst is skipped and `onClick` still runs.

## FAQ

### 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`](https://ui.minidev.pro/docs/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).

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`, `motion`

## Related

- [Button](https://ui.minidev.pro/docs/button/md): Shadcn compatible React button on Base UI with eight variants, nine sizes including icon sizes, a pressed state and render prop support for links.
- [Sparkles Text](https://ui.minidev.pro/docs/sparkles-text/md): Headline text with four point stars that twinkle around it in your accent colors. The sparkles are decorative and hidden; the text stays plain and readable.
- [Animated Feature Row](https://ui.minidev.pro/docs/animated-feature-row/md): A row of feature cards that slide up with a staggered delay when scrolled into view. Pass title and description pairs; reduced motion keeps them still.
- [Card Tilt](https://ui.minidev.pro/docs/card-tilt/md): A card that tilts in 3D toward the pointer on springs, with an accent glare that follows the cursor. It stays flat when reduced motion is preferred.
- [Cursor Spotlight Panel](https://ui.minidev.pro/docs/cursor-spotlight-panel/md): A panel whose accent radial spotlight follows the cursor, driven by Framer Motion values without re-renders. It shows a still surface for reduced motion.
- [Device Frame Stack](https://ui.minidev.pro/docs/device-frame-stack/md): Three device frames labelled mobile, app and docs that spring into a fanned, rotated stack when scrolled into view. Works as a hero or feature visual.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
