Confetti
godui/confettiFreeComponent
A physics-based confetti burst with an imperative fire API for celebratory moments.
Install it
npx shadcn@latest add https://godui.design/r/confetti.jsonSource
1"use client";23import canvasConfetti, {4 type Options as ConfettiOptions,5} from "canvas-confetti";6import * as React from "react";78export type { ConfettiOptions };910export type ConfettiHandle = {11 /** Fire a burst. Options override the component defaults. */12 fire: (options?: ConfettiOptions) => void;13};1415export type ConfettiButtonProps =16 React.ButtonHTMLAttributes<HTMLButtonElement> & {17 /** Confetti options applied to the burst on click. */18 options?: ConfettiOptions;19 };2021const DEFAULTS: ConfettiOptions = {22 spread: 70,23 startVelocity: 45,24 particleCount: 120,25 origin: { y: 0.7 },26 // Honor the Accessibility principle — canvas-confetti suppresses the burst27 // when the user prefers reduced motion.28 disableForReducedMotion: true,29};3031/**32 * Imperative confetti. Hold a ref and call `ref.current.fire()` — mirrors the33 * `toast()` ergonomics already used across GodUI.34 */35const Confetti = React.forwardRef<36 ConfettiHandle,37 { options?: ConfettiOptions }38>(({ options }, ref) => {39 React.useImperativeHandle(40 ref,41 () => ({42 fire: (override?: ConfettiOptions) => {43 canvasConfetti({ ...DEFAULTS, ...options, ...override });44 },45 }),46 [options],47 );48 return null;49});50Confetti.displayName = "Confetti";5152/** Convenience trigger: bursts from the button's position on click. */53const ConfettiButton = React.forwardRef<HTMLButtonElement, ConfettiButtonProps>(54 ({ options, onClick, children, ...props }, ref) => {55 const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {56 const rect = e.currentTarget.getBoundingClientRect();57 const x = (rect.left + rect.width / 2) / window.innerWidth;58 const y = (rect.top + rect.height / 2) / window.innerHeight;59 canvasConfetti({ ...DEFAULTS, origin: { x, y }, ...options });60 onClick?.(e);61 };6263 return (64 <button65 ref={ref}66 type="button"67 data-slot="confetti-button"68 onClick={handleClick}69 {...props}70 >71 {children}72 </button>73 );74 },75);76ConfettiButton.displayName = "ConfettiButton";7778/** Direct imperative API for non-React call sites. */79function confetti(options?: ConfettiOptions) {80 canvasConfetti({ ...DEFAULTS, ...options });81}8283export { Confetti, ConfettiButton, confetti };
What it pulls in
npm packages
Other registry items
Files it writes
More from godui
All 105 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | godui | Components | Free | 1 dep | |
| Agent Flowagent-flow | godui | Components | Free | 1 dep | |
| Agent Timelineagent-timeline | godui | Components | Free | 1 dep | |
| Animated Beamanimated-beam | godui | Components | Free | 1 dep | |
| Animated Testimonialsanimated-testimonials | godui | Components | Free | 1 dep | |
| Animated Tooltipanimated-tooltip | godui | Components | Free | 1 dep | |
| App Showcaseapp-showcase | godui | Components | Free | 1 dep | |
| Aurora Textaurora-text | godui | Components | Free | no deps |
