# ember-badge — Specification Sheet

> feedback: Unread-count badge that is a live ember: flares on new items, cools to ash at zero (canvas 2D, server-safe, reduced motion -> static badge)

## Overview

- **Item Name**: `ember-badge`
- **Version**: `0.1.0`
- **Slot**: `feedback`
- **Kind**: `canvas`
- **Install**: `npx shadcn@4.21.1 add @frictionborn/ember-badge`

## Intent

### Use When
- An unread or pending count on an icon button, avatar or tab
- A notification bell in a header where new items deserve a moment of attention

### Avoid When
- Many badges in one list (one ember per screen is enough)
- Counts that change several times a second (it would flare constantly)

## Runtime & Server Boundaries

- **Server Output**: `final-state` (accessible fallback in static HTML; measured CLS 0)
- **Client Only**: `false`
- **Lazy Loaded**: `in-view`
- **Client Reveal Gate**: This item reads `[data-motion="ok"]` on `<html>`. Next.js: render `<MotionReadyScript />` from `@frictionborn/runtime` inside `<head>` of the root layout (pass `nonce` under a strict CSP). Vite / SPA: call `initMotionReady()` from `@frictionborn/runtime` once before `createRoot(...).render(...)`. Without it the item stays in its static, fully visible state (no motion).
- **Requirements**: React `>=19`, Frameworks: next-app-router, vite-react

## Behavior & Tiers

- **Animation Loop**: `on-interaction` (no JavaScript frame loop of its own: CSS, IntersectionObserver, or its parts)
- **WebGL Contexts**: `0`
- **Reduced Motion**: Mode `static` — A static ember-coloured badge with the number; no flare, no sparks, no canvas.

### Device Tiers
- **T0 Static (reduced motion, Save-Data, no WebGL2, server render, or the frame guard gave up)**: The control alone (server render, reduced motion, Save-Data, no WebGL2): no canvas
- **T1 Lite (coarse pointer on a low-end device: 4 cores or fewer, or 2 GB or less)**: Same as tier 2
- **T2 Standard (coarse pointer on a capable phone, or a narrow or low-end fine-pointer screen)**: Effect on a canvas at DPR <= 1.5 with half the particles
- **T3 Full (fine pointer with hover on a capable machine)**: Effect on a canvas at DPR <= 2 with the full particle count

### Input Interactions
- **Pointer**: None of its own: the wrapped element keeps its own handlers
- **Touch**: Same
- **Keyboard**: None of its own: the wrapped button or link stays focusable

## Accessibility (a11y)

- **Role**: `interactive`
- **Hidden from Assistive Tech**: `false`
- **Text Stays in DOM**: `true`
- **Pause Control**: `via-runtime`
- **WCAG Criteria**: 1.3.1, 4.1.3
- **Notes**: The visible number is aria-hidden; a visually hidden role=status reads "<count> <label>" when the count changes. The wrapped element keeps its own name and role.

## Composition

- **Max Per Page**: 6
- **Singleton**: false
- **Conflicts With**: None
- **Pairs Well With**: flame-switch, fuse-toast

## Props

| Prop | Type | Default | Effect |
|---|---|---|---|
| `count` | `number` | `—` | Required. The unread count; a rise flares the ember, 0 cools it to ash and hides the number. |
| `children` | `React.ReactNode` | `—` | Required. The element the badge sits on (an icon button, an avatar). |
| `max` | `number` | `99` | Counts above this show as max+. |
| `label` | `string` | `"unread"` | What the count counts, read after the number by screen readers. |
| `palette` | `"fire" \| "ice" \| "neon" \| "mono" \| "custom"` | `"fire"` | Colours of the effect (DESIGN.md A8). custom reads --fb-heat-0..4 from the page. |
| `paused` | `boolean` | `false` | Universal pause prop: the effect stops drawing; the control keeps working. |
| `maxTier` | `number` | `3` | Hard ceiling on the capability tier. |
| `nonce` | `string` | `—` | CSP nonce for the component's <style> element. |
| `className` | `string` | `""` | Extra classes on the root. |
| `style` | `React.CSSProperties` | `—` | Inline styles on the root, merged after the palette variables. |
| `ref` | `React.Ref<HTMLDivElement>` | `—` | Receives the root element. |

## Dependencies

- **Runtime package**: `@frictionborn/runtime` (installed by the registry item)
- **Registry items pulled in**: none
- **npm packages**: none

## Agent Instructions

### Installation
```bash
npx shadcn@4.21.1 add @frictionborn/ember-badge
```

### Usage
```tsx
import { EmberBadge } from "@/components/ui/ember-badge";

export function Inbox({ unread }: { unread: number }) {
  return (
    <EmberBadge count={unread} label="unread messages">
      <button type="button" aria-label="Inbox">
        <span aria-hidden="true">🔔</span>
      </button>
    </EmberBadge>
  );
}
```

### Common Mistakes to Avoid
- Put the accessible name on the wrapped button (aria-label="Inbox"); the badge only adds the count.
- The sparks rise above the badge: do not clip the parent with overflow: hidden.
- Pass the real count (a number), not a string; the badge formats max+ itself.

### How to Verify
- Server HTML shows the number on a static ember badge.
- Raising count flares the ember and a status message reads the new count.
- At count 0 the number disappears and the loop stops.

## Measured Bench Evidence

- **Bench Commit**: `ffd0225` (2026-10-21)
- **Size**: 2.64 KiB initial / none deferred. Gzip of this item's own source files only (method: gzip-9); excludes the runtime, third-party packages and any registry items it pulls in.
- **Cumulative Layout Shift (CLS)**: `0`
- **Frames When Idle**:
  - Off-screen: 0 frames
  - Hidden tab: 0 frames
  - Reduced motion: 0 frames
- **axe-core Violations**: Serious: 0, Critical: 0

### Verified Devices
| Environment | Via | Tier | Result | Date | Notes |
|---|---|---|---|---|---|
| Chromium Desktop (SwiftShader) | playwright | 3 | pass | 2026-10-21 | 16 passed, 0 failed |
| Chromium Mobile (Pixel 7 emulation) | playwright | 2 | pass | 2026-10-21 | 15 passed, 0 failed |
| Firefox Desktop | playwright | 3 | pass | 2026-10-21 | 14 passed, 0 failed |
| WebKit Desktop | playwright | 3 | pass | 2026-10-21 | 15 passed, 0 failed |
| WebKit Mobile (iPhone 14 emulation) | playwright | 2 | pass | 2026-10-21 | 15 passed, 0 failed |

## License & Provenance

- **Code License**: MIT
- **Origin**: Original implementation for Frictionborn Motion.
