UI / Decor
Fireworks
Shells that climb and go off as a ball, a hoop or a willow, bursts with a shock ring, and sparklers along the bottom edge.
Press the sky to send one up
Installation
npx shadcn@latest add https://jiaweing.com/r/fireworks.jsonWith the @jiaweing namespace set up, use @jiaweing/fireworks in place of the URL.
Usage
tsx
import { Fireworks } from "@/components/room/fireworks";tsx
const [shows, setShows] = useState(0);
<div className="relative h-96 bg-slate-950">
<button onClick={() => setShows((n) => n + 1)}>Launch</button>
<Fireworks trigger={shows} sparklers={2} />
</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 goes up.
Props
Fireworks
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<{ fire, burst, show }> | - | fire(shell?) sends one shell up, burst(at?) goes off on the spot with a shock ring, show(shells?) sends a volley. |
| 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. |
| shells | number | 6 | Shells in a volley. The last is a big willow. |
| sparklers | number | 0 | Sparklers fizzing along the bottom edge. |
| colors | string[] | the inks, in pairs | 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. |
FireworkShell
| Prop | Type | Default | Description |
|---|---|---|---|
| x, y | number | - | Where it bursts, each 0 to 1. Left out, a spot in the top half. |
| kind | "ball" | "ring" | "willow" | - | A ball with a smaller one inside, a ring, or a willow with tails. |
| big | boolean | - | Twice the scraps, and a shock ring. |
MIT licensed. Copy it, change it, ship it.