Skip to content

control · Canvas 2D

FireworkRating

A five-star rating that is a real radio group; each star you choose goes up as a firework.

Five-star rating as a real radio group; hover previews, and each chosen star bursts as a firework

  • Canvas 2D
  • Reduced motion: static
  • 3.59 KB gzip
  • Layout shift 0
View the source Spec sheet as Markdown

Install

Install
pnpm dlx shadcn@4.21.1 add @frictionborn/firework-rating

Playground

Palette
Your code
import { FireworkRating } from "@/components/ui/firework-rating";

<FireworkRating />

In a full example

The full example loads as you scroll to it.

Accessibility

  • role=radiogroup with a name and five native buttons with role=radio, aria-checked and names ("3 stars"); one tab stop. The word for the rating is aria-live=polite. Unlit stars keep 3:1 against the dark ground. The firework canvas is aria-hidden.
  • Keyboard: A radio group with roving focus: arrows move and rate (Right/Up up, Left/Down down)
  • Touch: Tap rates
  • WCAG criteria it is built for: 1.3.1, 1.4.11, 2.1.1, 4.1.2, 4.1.3

Props

PropTypeDefaultWhat it does
valuenumbernoneControlled rating, 0 (not rated) to 5.
defaultValuenumber0Initial rating when uncontrolled.
onValueChange(value: number) => voidnoneCalled with the new rating.
labelstring"Rating"Accessible name of the radio group.
words[string, string, string, string, string, string] | null"[\"Not rated\", \"Poor\", \"Fair\", \"Good\", \"Great\", \"Spectacular\"]"Words for 0-5 stars, shown and announced; null hides them.
palette"fire" | "ice" | "neon" | "mono" | "custom""fire"Colours of the effect (DESIGN.md A8). custom reads --fb-heat-0..4 from the page.
pausedbooleanfalseUniversal pause prop: the effect stops drawing; the control keeps working.
maxTiernumber3Hard ceiling on the capability tier.
noncestringnoneCSP nonce for the component's <style> element.
classNamestring""Extra classes on the root.
styleReact.CSSPropertiesnoneInline styles on the root, merged after the palette variables.
refReact.Ref<HTMLDivElement>noneReceives the root element.

Measured on the bench

Measured by the automated bench at commit 801163e on 2026-10-21. These numbers are written by the bench, never by hand.

MeasureResult
Size, gzip3.59 KB at load, 0.02 KB loaded later
Layout shift0
Frames when nothing should moveoff screen 0, hidden tab 0, reduced motion 0
axe accessibility scan0 serious, 0 critical

Browsers it ran in

Automated Playwright runs, some with device emulation. Results from physical phones and tablets are still pending, so none are listed.

EnvironmentTierResultDateNotes
Chromium Desktop (SwiftShader)3pass2026-10-2116 passed, 0 failed
Chromium Mobile (Pixel 7 emulation)2pass2026-10-2115 passed, 0 failed
Firefox Desktop3pass2026-10-2114 passed, 0 failed
WebKit Desktop3pass2026-10-2115 passed, 0 failed
WebKit Mobile (iPhone 14 emulation)2pass2026-10-2115 passed, 0 failed

On different devices

Reduced motion (static): The stars light up without bursts; no canvas.

TierWhat it does
T3 FullEffect on a canvas at DPR <= 2 with the full particle count
T2 StandardEffect on a canvas at DPR <= 1.5 with half the particles
T1 LiteSame as tier 2
T0 StaticThe control alone (server render, reduced motion, Save-Data, no WebGL2): no canvas

Content Security Policy

  • Works without 'unsafe-eval'.
  • Uses the reveal gate ([data-motion="ok"]): render <MotionReadyScript /> in <head> (with your nonce), or call initMotionReady() in Vite.
  • Sets inline style attributes, so allow style-src-attr 'unsafe-inline'.

Goes well with