Confetti
A burst, two cannons or fireworks, in the theme’s colours — on a click, or from code. Decorative only, and none for reduced motion.
Installation
It has its own entry point, @semantic-components/ui/confetti, built on canvas-confetti — an optional peer of ui: install it where you use the component.
import { ScConfetti, ScConfettiTrigger } from '@semantic-components/ui/confetti';Usage
Usage
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton } from '@semantic-components/ui';import { ScConfettiTrigger } from '@semantic-components/ui/confetti';
/** scConfettiTrigger on a button: a click bursts from it, in the theme’s colours. Decorative — hidden from screen readers, never in the way, and none for reduced motion. */@Component({ selector: 'app-confetti-usage-demo', imports: [ScConfettiTrigger, ScButton], template: ` <button scButton scConfettiTrigger>Celebrate</button> `, host: { class: 'flex min-h-72 w-full items-center justify-center' },Anatomy
Two ways in, one effect: a trigger on your button (a click sets it off), or the service from your code (after a form, on an event). Both draw on one full-screen canvas, made on the first one; canvas-confetti is loaded only then.
import { ScConfetti, ScConfettiTrigger } from '@semantic-components/ui/confetti';<!-- On a click --><button scButton scConfettiTrigger>Celebrate</button><button scButton scConfettiTrigger confettiEffect="sides">Launch</button>
<!-- From code -->private readonly confetti = inject(ScConfetti);await this.confetti.sides();Effects and colours
burst (the default) bursts from the element clicked — or the bottom middle, from code; sides fires two cannons from the edges of the screen; fireworks bursts here and there for three seconds.
The colours are the theme's own confetti colours, --sc-confetti-1 to --sc-confetti-5: five tokens in your styles.css, light and dark, as shadcn's chart colours are — read each time it is fired, so they follow your theme and dark mode. Without them, canvas-confetti's colours (and a warning in development); pass colors for others.
Accessibility
- Decorative: the canvas is hidden from screen readers and never in the way of the pointer.
- None at all when the reader asks for reduced motion.
- Say what it celebrates in words too — a status of yours («Welcome aboard!»), as the form and event examples do.
Examples
From the element
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton } from '@semantic-components/ui';import { ScConfettiTrigger } from '@semantic-components/ui/confetti';
/** Each burst starts at the centre of what was clicked — wherever it is. */@Component({ selector: 'app-element-confetti-demo', imports: [ScConfettiTrigger, ScButton], template: ` <div class="flex w-full max-w-md justify-between">Sides
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton } from '@semantic-components/ui';import { ScConfettiTrigger } from '@semantic-components/ui/confetti';
/** confettiEffect="sides": two cannons, from the edges of the screen. */@Component({ selector: 'app-sides-confetti-demo', imports: [ScConfettiTrigger, ScButton], template: ` <button scButton scConfettiTrigger confettiEffect="sides">Launch</button>Fireworks
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton } from '@semantic-components/ui';import { ScConfettiTrigger } from '@semantic-components/ui/confetti';
/** confettiEffect="fireworks": bursts here and there, for three seconds — or the duration you give. */@Component({ selector: 'app-fireworks-confetti-demo', imports: [ScConfettiTrigger, ScButton], template: ` <buttonColours and shapes
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton } from '@semantic-components/ui';import { ScConfettiTrigger } from '@semantic-components/ui/confetti';
/** Any CSS colours, circles and squares, bigger pieces, a wider spread. */@Component({ selector: 'app-custom-confetti-demo', imports: [ScConfettiTrigger, ScButton], template: ` <buttonAfter a form
import { Component, ViewEncapsulation, inject, signal } from '@angular/core';import { FormField, FormRoot, form, required } from '@angular/forms/signals';import { ScButton, ScField, ScFieldErrors, ScInput, ScLabel,} from '@semantic-components/ui';import { ScConfetti } from '@semantic-components/ui/confetti';On an event
2 to go.
import { Component, ElementRef, ViewEncapsulation, computed, effect, inject, signal, untracked, viewChild,API reference
| Part | Selector | Description |
|---|---|---|
ScConfettiTrigger | [scConfettiTrigger] | On your button (or any element): a click sets it off — a burst from its centre by default. Behaviour only: the element keeps its look. exportAs scConfettiTrigger: fire(). |
ScConfetti | service | From code: burst(options), sides(options), fireworks(options), reset(). Each settles when the confetti has fallen. |
| Input | Type | Default | Description |
|---|---|---|---|
scConfettiTrigger | ScConfettiFireworksOptions | {} | The options (its value). |
confettiEffect | 'burst' | 'sides' | 'fireworks' | 'burst' | Which effect a click sets off. |
| Input | Type | Default | Description |
|---|---|---|---|
colors | string[] | --sc-confetti-1 … 5 | Any CSS colours. |
shapes | ('square' | 'circle' | 'star')[] | ['square', 'circle'] | The pieces’ shapes. |
count, spread | number | 100, 70 (a burst) | How many pieces, how wide (degrees). |
angle, velocity | number | canvas-confetti’s | Which way (degrees), how fast. |
size, gravity | number | canvas-confetti’s (1) | Bigger pieces; how fast they fall. |
origin | { x, y } | Element | the element clicked | Where a burst starts: 0 to 1 of the screen, or an element. |
duration | number | 3000 | Fireworks: how long, in ms. |