GooseUI

Components

Confetti

New

Confetti on canvas without dependencies. useConfetti returns fire(), which launches a burst from a point or an element. The canvas is created on demand on top of the page with pointer-events: none and removed once the last particle fades. With reduced motion turned on, fire does nothing.

Preview

Press the button. The burst starts from the button itself.

Installation

npx shadcn@latest add @gooseui/confetti
pnpm dlx shadcn@latest add @gooseui/confetti
yarn dlx shadcn@latest add @gooseui/confetti
bunx --bun shadcn@latest add @gooseui/confetti

Usage

import { Button } from "@/components/ui/button"

import { useConfetti } from "@/components/ui/confetti"

export default function Example() {
  const { fire } = useConfetti()

  return (
    <Button onClick={(e) => fire({ origin: e.currentTarget })}>
      Celebrate
    </Button>
  )
}

Examples

Presets

preset sets particle count, spread and speed. Any explicit option overrides the preset.

fire({ preset: "low" })
fire({ preset: "high", origin: buttonRef })
fire({ preset: "burst", particleCount: 300 })

From an element

origin accepts viewport coordinates, a DOM element or a ref. The burst starts from the element center.

Target
const target = useRef<HTMLDivElement>(null)
const { fire } = useConfetti({ origin: target, preset: "burst" })

<Button onClick={() => fire()}>Fire at the target</Button>
<div ref={target}>Target</div>

Side cannons

Two calls with different origin and angle. Bursts share one canvas.

const { fire } = useConfetti({ preset: "high", spread: 55 })

const y = window.innerHeight * 0.7
fire({ origin: { x: 0, y }, angle: 60 })
fire({ origin: { x: window.innerWidth, y }, angle: 120 })

On completion

A small burst from a checkbox when a task is done.

import { Checkbox } from "@/components/ui/checkbox"

const { fire } = useConfetti({ preset: "low", shapes: ["circle", "strip"] })

<Checkbox
  onChange={(e) => {
    if (e.target.checked) fire({ origin: e.currentTarget.parentElement ?? e.currentTarget })
  }}
/>

Options

OptionTypeDefaultDescription
preset"low" | "medium" | "high" | "burst""medium"Intensity preset
origin{ x, y } | Element | RefObject-Launch point: { x, y } in viewport px, an element or a ref
particleCountnumberfrom presetNumber of particles
anglenumber90Launch direction in degrees, 90 is up
spreadnumberfrom presetCone width in degrees
startVelocitynumberfrom presetInitial speed in px per frame at 60 fps
gravitynumber1Downward acceleration
decaynumber0.9Velocity multiplier per frame
driftnumber0Horizontal wind
ticksnumberfrom presetLifetime in frames, 60 per second
scalarnumberfrom presetParticle size multiplier
colorsstring[]-CSS colors, by default a bright palette
shapes("square" | "circle" | "strip")[]allParticle shapes
zIndexnumber100z-index of the canvas
respectReducedMotionbooleantrueSkip the effect for prefers-reduced-motion

Preset values

low:    { particleCount: 30,  spread: 55,  startVelocity: 35, ticks: 160, scalar: 0.9 }
medium: { particleCount: 50,  spread: 45,  startVelocity: 45, ticks: 200 }
high:   { particleCount: 130, spread: 70,  startVelocity: 55, ticks: 240 }
burst:  { particleCount: 100, spread: 360, startVelocity: 30, ticks: 180 }

ConfettiButton

A button that fires from itself on click. Accepts every button prop plus options.

import { ConfettiButton } from "@/components/ui/confetti"

<ConfettiButton options={{ preset: "high" }}>Celebrate</ConfettiButton>

useConfetti

useConfetti(defaults?) returns { fire }. fire(options?) merges options over the defaults and returns a Promise that resolves when the canvas is removed. Outside React use fireConfetti(options) from the same file.

const { fire } = useConfetti({ colors: ["#facc15", "#38bdf8"] })

await fire({ origin: { x: 200, y: 300 } })
// the canvas is gone here

// outside React
import { fireConfetti } from "@/components/ui/confetti"
fireConfetti({ preset: "burst" })

Features

  • No dependencies: own particle physics on canvas 2D in a single file
  • On demand: the canvas appears only for the burst and is removed after it
  • No leaks: requestAnimationFrame stops and the resize listener is removed together with the canvas
  • Reduced motion: fire returns right away when the user asked for less motion