UI / Decor
Confetti
The 3D room's confetti over any box: paper scraps in seven inks that fall, spin and sway, thrown by a ref or a trigger.
Done
That deserves confetti
Scraps of paper fall from the top edge of whatever box it is in, spinning and swaying on the way down.
Go on
Installation
npx shadcn@latest add https://jiaweing.com/r/confetti.jsonWith the @jiaweing namespace set up, use @jiaweing/confetti in place of the URL.
Usage
tsx
import { Confetti } from "@/components/room/confetti";tsx
const [count, setCount] = useState(0);
<div className="relative h-80">
<button onClick={() => setCount((n) => n + 1)}>Celebrate</button>
<Confetti trigger={count} />
</div>- It draws on a see-through canvas over its parent and takes no clicks.
- three.js is only fetched in the browser, the first time it is needed.
- With reduced motion, nothing is thrown.
Props
Confetti
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<{ fire: () => void }> | - | fire() throws a handful. |
| trigger | unknown | - | Sets it off each time it becomes a new value that is not false, 0 or empty: a flag going true, or a count going up. |
| count | number | 110 | Scraps a throw. |
| colors | string[] | the seven inks | Any CSS colours, oklch() and color-mix() included. |
| className | string | - | Classes on the layer. It lies over its parent, so give the parent a position. |
MIT licensed. Copy it, change it, ship it.