Playground

Confetti

A short burst of square confetti on a canvas, triggered by a prop or a ref method.

  • 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

Fire from a ref

Does nothing when the system asks for reduced motion.

Props

ConfettiProps

PropTypeDefaultDescription
burstnumber–Fires a burst each time this number changes (not on mount). Or call `ref.current.fire()`.
countnumber60Pieces 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.
colorsstring[]–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

ClassStylesheet
.confetticonfetti.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.