# Confetti

- Page: https://jiguang132.com/resources/magic-ui/docs/confetti
- Resource: Magic UI (https://jiguang132.com/resources/magic-ui.md)
- All guides: https://jiguang132.com/resources/magic-ui/docs.md

Install: `npx shadcn@latest add https://jiguang132.com/r/magic-ui/confetti.json`

## Use case

Launch Canvas confetti through a ref or button.

## Native props used by the examples

Extracted from all local examples for this entry, grouped by imported module and native owner, including other Magic components used by compound demos. This is not an exhaustive API or a universal host variant. Inspect spread object declarations and the source types/defaults below.

| Owning component prop | Explanation | Example source |
| --- | --- | --- |
| `Confetti.ref` (confetti) | React reference to the native imperative API or DOM target; not a business value. | `examples/confetti-demo.tsx` |
| `Confetti.className` (confetti) | Classes on this native component; initialize Tailwind and its required CSS first. | `examples/confetti-demo.tsx` |
| `Confetti.onMouseEnter` (confetti) | Native hover handler in the example, often calling its confetti ref. | `examples/confetti-demo.tsx` |
| `ConfettiButton.children` (confetti) | Native child content; keep the owning component's text/element constraints. | `examples/confetti-basic-cannon.tsx`、`examples/confetti-random-direction.tsx` |
| `ConfettiButton.options` (confetti) | Native canvas-confetti options/global options. | `examples/confetti-random-direction.tsx` |

## Interaction and state checks

- Confetti Demo — `confetti-demo`
- Confetti Basic Cannon — `confetti-basic-cannon`
- Confetti Random Direction — `confetti-random-direction`
- Confetti Fireworks — `confetti-fireworks`
- Confetti Stars — `confetti-stars`
- Confetti Side Cannons — `confetti-side-cannons`
- Confetti Custom Shapes — `confetti-custom-shapes`
- Confetti Emoji — `confetti-emoji`

These names identify real example entries, not new component props or extra components. Check pointer/keyboard behavior, themes, small screens and failures for the selected example. Decorative effects must not invent disabled/error/submission states. Complete example installation includes the actual dependency closure.

## Business integration boundary

Confetti and ConfettiButton have different APIs; respect reduced motion and reset/destroy resources on exit. Celebration is not evidence of transaction success.

## Host and motion setup

Initialize Tailwind CSS v4, semantic CSS variables and the dark variant; import the independent local Registry namespace. Reuse an existing next-themes Provider without substituting JGuang UI/Base UI/HeroUI APIs. Mount effects in view and unmount offscreen; provide static alternatives for unavailable Canvas/WebGL or failed remote media. Respect prefers-reduced-motion and verify timer/RAF/observer/listener cleanup: stopping CSS alone does not prove the engine stopped. Examples provide no backend, login, payment or real AI stream. This practical guide is bilingual; detailed upstream references and demo text retain their original language.


## Available examples

confetti-demo, confetti-basic-cannon, confetti-random-direction, confetti-fireworks, confetti-stars, confetti-side-cannons, confetti-custom-shapes, confetti-emoji

Demo state and mock data do not provide a backend service. Inspect the component props before wiring real data.




## Installation

<Tabs defaultValue="cli">

<TabsList>
  <TabsTrigger value="cli">CLI</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">

```bash
npx shadcn@latest add @magicui/confetti
```

</TabsContent>

<TabsContent value="manual">

<Steps>

<Step>Install the following dependencies:</Step>

```bash
npm install canvas-confetti
```

<Step>Copy and paste the following code into your project.</Step>



<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</Tabs>

## Examples

### Basic



### Random Direction



### Fireworks



### Side Cannons



### Stars



### Custom Shapes



### Emoji



### Usage

```tsx showLineNumbers
import { useRef } from "react"

import { Confetti, type ConfettiRef } from "@/components/ui/confetti"

export function ConfettiDemo() {
  const confettiRef = useRef<ConfettiRef>(null)

  return (
    <div>
      <Confetti ref={confettiRef} manualstart />
      <button onClick={() => confettiRef.current?.fire()}>
        Trigger Confetti
      </button>
    </div>
  )
}
```

## Props

### Confetti

| Prop            | Type                     | Default                             | Description                                                      |
| --------------- | ------------------------ | ----------------------------------- | ---------------------------------------------------------------- |
| `ref`           | `React.Ref<ConfettiRef>` | `null`                              | Ref exposing imperative `fire(options?: ConfettiOptions)` method |
| `options`       | `ConfettiOptions`        | `{}`                                | Default options for automatic or imperative confetti triggers    |
| `globalOptions` | `ConfettiGlobalOptions`  | `{ resize: true, useWorker: true }` | Global options passed to `canvas-confetti.create()`              |
| `manualstart`   | `Boolean`                | `false`                             | Prevents automatic confetti firing on component mount            |
| `className`     | `String`                 | `undefined`                         | Custom CSS classes applied to the canvas element                 |

### ConfettiRef

| Method | Parameters                  | Return Type             | Description                                                   |
| ------ | --------------------------- | ----------------------- | ------------------------------------------------------------- |
| `fire` | `options?: ConfettiOptions` | `Promise<void> \| void` | Imperatively triggers a confetti burst on the canvas instance |

### ConfettiOptions

| Field           | Type                       | Default                        | Description                                             |
| --------------- | -------------------------- | ------------------------------ | ------------------------------------------------------- |
| `particleCount` | `Integer`                  | `50`                           | Number of confetti particles to launch                  |
| `angle`         | `Number`                   | `90`                           | Launch angle in degrees                                 |
| `spread`        | `Number`                   | `45`                           | Spread angle in degrees                                 |
| `startVelocity` | `Number`                   | `45`                           | Initial particle velocity                               |
| `decay`         | `Number`                   | `0.9`                          | Velocity decay rate                                     |
| `gravity`       | `Number`                   | `1`                            | Gravity applied to particles                            |
| `drift`         | `Number`                   | `0`                            | Horizontal drift factor                                 |
| `flat`          | `Boolean`                  | `false`                        | Renders flat 2D shapes                                  |
| `ticks`         | `Number`                   | `200`                          | Number of animation frames confetti lasts               |
| `origin`        | `{ x: number, y: number }` | `{ x: 0.5, y: 0.5 }`           | Normalized viewport origin coordinates (`0.0` to `1.0`) |
| `colors`        | `Array of Strings`         | `HEX array`                    | Custom HEX color palette                                |
| `shapes`        | `Array of Strings`         | `['square', 'circle', 'star']` | Particle shapes or custom text shapes                   |
| `zIndex`        | `Integer`                  | `9999`                         | Z-index of the confetti burst                           |
| `scalar`        | `Number`                   | `1`                            | Scaling factor for particle dimensions                  |

### ConfettiButton

| Prop       | Type                                      | Default | Description                                       |
| ---------- | ----------------------------------------- | ------- | ------------------------------------------------- |
| `options`  | `ConfettiOptions & ConfettiGlobalOptions` | `{}`    | Options for the confetti launched on button click |
| `children` | `React.ReactNode`                         | `null`  | Button label and child elements                   |
| `ref`      | `React.Ref<HTMLButtonElement>`            | `null`  | Forwarded DOM reference to the underlying button  |

## Credits

- Credit to [Bankk](https://www.x.com/bankkroll_eth)
- Inspired by [canvas-confetti](https://www.npmjs.com/package/canvas-confetti)




## Complete example installation

The component command installs the component. Each example command also includes its actual imported components, native support UI, utilities and pinned dependencies. Helpers are not additional catalog components.

### Confetti Demo

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/confetti/confetti-demo.json
```

Default import: `@/components/magicui/examples/confetti-demo`

Dependencies: `@radix-ui/react-slot@1.3.0`, `@types/canvas-confetti@1.9.0`, `canvas-confetti@1.9.3`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `tailwind-merge@3.6.0`

### Confetti Basic Cannon

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/confetti/confetti-basic-cannon.json
```

Default import: `@/components/magicui/examples/confetti-basic-cannon`

Dependencies: `@radix-ui/react-slot@1.3.0`, `@types/canvas-confetti@1.9.0`, `canvas-confetti@1.9.3`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `tailwind-merge@3.6.0`

### Confetti Random Direction

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/confetti/confetti-random-direction.json
```

Default import: `@/components/magicui/examples/confetti-random-direction`

Dependencies: `@radix-ui/react-slot@1.3.0`, `@types/canvas-confetti@1.9.0`, `canvas-confetti@1.9.3`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `tailwind-merge@3.6.0`

### Confetti Fireworks

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/confetti/confetti-fireworks.json
```

Default import: `@/components/magicui/examples/confetti-fireworks`

Dependencies: `@radix-ui/react-slot@1.3.0`, `@types/canvas-confetti@1.9.0`, `canvas-confetti@1.9.3`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `tailwind-merge@3.6.0`

### Confetti Stars

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/confetti/confetti-stars.json
```

Default import: `@/components/magicui/examples/confetti-stars`

Dependencies: `@radix-ui/react-slot@1.3.0`, `@types/canvas-confetti@1.9.0`, `canvas-confetti@1.9.3`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `tailwind-merge@3.6.0`

### Confetti Side Cannons

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/confetti/confetti-side-cannons.json
```

Default import: `@/components/magicui/examples/confetti-side-cannons`

Dependencies: `@radix-ui/react-slot@1.3.0`, `@types/canvas-confetti@1.9.0`, `canvas-confetti@1.9.3`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `tailwind-merge@3.6.0`

### Confetti Custom Shapes

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/confetti/confetti-custom-shapes.json
```

Default import: `@/components/magicui/examples/confetti-custom-shapes`

Dependencies: `@radix-ui/react-slot@1.3.0`, `@types/canvas-confetti@1.9.0`, `canvas-confetti@1.9.3`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `tailwind-merge@3.6.0`

### Confetti Emoji

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/confetti/confetti-emoji.json
```

Default import: `@/components/magicui/examples/confetti-emoji`

Dependencies: `@radix-ui/react-slot@1.3.0`, `@types/canvas-confetti@1.9.0`, `canvas-confetti@1.9.3`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `tailwind-merge@3.6.0`

### Minimal usage and theme

```tsx
import Demo from '@/components/magicui/examples/confetti-demo';
import { ThemeProvider } from 'next-themes';
export default function Example() {
  return <ThemeProvider attribute="class" defaultTheme="system" enableSystem><Demo /></ThemeProvider>;
}

```

Initialize Tailwind CSS v4, semantic color variables and the dark variant first. Reuse an existing next-themes provider rather than nesting another. Next Link examples require a Next.js environment; in static Vite projects adapt the demo links to your router without changing the native component API. Some media and tweets require network access. Examples do not supply authentication or backend services.


## Source-backed parameter reference

Implementation signatures and types are generated from the pinned local source. Optional props, native inherited types, union branches and never exclusions are preserved. A forwardRef implementation's ref is a React reference, not an additional business prop.


```ts
ConfettiButton({ options, children, onClick, ...props }, ref)
```



```ts
export interface ConfettiButtonProps extends React.ComponentPropsWithoutRef<
  typeof Button
> {
  options?: ConfettiOptions &
    ConfettiGlobalOptions & { canvas?: HTMLCanvasElement }
}
```


### Native and external types

External types remain defined by React or native dependencies, not manually expanded into guessed props. The installed version's TypeScript definitions are authoritative.


```ts
HTMLButtonElement
React.ComponentPropsWithoutRef<
  typeof Button
>
ConfettiOptions
ConfettiGlobalOptions
HTMLCanvasElement
```

---

Index of all JGuang resources: https://jiguang132.com/llms.txt
