Confetti
A short burst of square confetti on a canvas, triggered by a prop or a ref method.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native elements
- The canvas is aria-hidden and ignores the pointer, so it never blocks or announces anything.
- Off under prefers-reduced-motion: no burst is drawn. Announce the event it celebrates in text as well.
- Styles in one file:
confetti.css
Import
import '@monoline/css';
import {Confetti} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add confetti
Usage
import {useRef} from 'react';
import {Button, Confetti, type ConfettiHandle} from '@monoline/react';
function Fire() {
const ref = useRef<ConfettiHandle>(null);
return (
<>
<Confetti ref={ref} />
<Button variant="line" onClick={() => ref.current?.fire()}>Celebrate</Button>
</>
);
}
<Fire />
Examples
Props
ConfettiProps
| Prop | Type | Default | Description |
|---|---|---|---|
burst | number | – | Fires a burst each time this number changes (not on mount). Or call `ref.current.fire()`. |
count | number | 60 | Pieces per burst. Default 60. |
origin | { x: number; y: number; } | {x: 0.5, y: 0.5} | Where the burst starts, as 0 to 1 of the window. Default the centre. |
colors | string[] | – | Fill colours. Default: the accent, foreground and muted tokens. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
This component sets no state attributes.
CSS classes
| Class | Stylesheet |
|---|---|
.confetti | confetti.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.confetti {
border-color: var(--accent);
}
Accessibility
- The canvas is aria-hidden and ignores the pointer, so it never blocks or announces anything.
- Off under prefers-reduced-motion: no burst is drawn. Announce the event it celebrates in text as well.