JGuang

Confetti

Confetti · Magic UI

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

Some upstream demos use online images, videos or tweets. That content depends on network access and third-party services.

Confetti

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 propExplanationExample 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">
npx shadcn@latest add @magicui/confetti
</TabsContent> <TabsContent value="manual"> <Steps>

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

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

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

PropTypeDefaultDescription
refReact.Ref<ConfettiRef>nullRef exposing imperative fire(options?: ConfettiOptions) method
optionsConfettiOptions{}Default options for automatic or imperative confetti triggers
globalOptionsConfettiGlobalOptions{ resize: true, useWorker: true }Global options passed to canvas-confetti.create()
manualstartBooleanfalsePrevents automatic confetti firing on component mount
classNameStringundefinedCustom CSS classes applied to the canvas element

ConfettiRef

MethodParametersReturn TypeDescription
fireoptions?: ConfettiOptionsPromise<void> | voidImperatively triggers a confetti burst on the canvas instance

ConfettiOptions

FieldTypeDefaultDescription
particleCountInteger50Number of confetti particles to launch
angleNumber90Launch angle in degrees
spreadNumber45Spread angle in degrees
startVelocityNumber45Initial particle velocity
decayNumber0.9Velocity decay rate
gravityNumber1Gravity applied to particles
driftNumber0Horizontal drift factor
flatBooleanfalseRenders flat 2D shapes
ticksNumber200Number 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)
colorsArray of StringsHEX arrayCustom HEX color palette
shapesArray of Strings['square', 'circle', 'star']Particle shapes or custom text shapes
zIndexInteger9999Z-index of the confetti burst
scalarNumber1Scaling factor for particle dimensions

ConfettiButton

PropTypeDefaultDescription
optionsConfettiOptions & ConfettiGlobalOptions{}Options for the confetti launched on button click
childrenReact.ReactNodenullButton label and child elements
refReact.Ref<HTMLButtonElement>nullForwarded DOM reference to the underlying button

Credits

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

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

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

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

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

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

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

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

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

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.

ConfettiButton({ options, children, onClick, ...props }, ref)
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.

HTMLButtonElement
React.ComponentPropsWithoutRef<
  typeof Button
>
ConfettiOptions
ConfettiGlobalOptions
HTMLCanvasElement