# Badge (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-badge` · version 1.0.0 · component · free
- category: Feedback
- build: Base UI (this item also ships a Radix build)
- install (this build): `npx shadcn@latest add https://beautiful-ui.dev/r/lumen-badge.json`
- npm dependencies: @base-ui/react@^1, class-variance-authority@^0.7
- registry dependencies: utils, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-badge
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

Status you can read at a glance: five tones, a square cell dot that blinks for anything live, and a mono count for the numbers that pile up. shadcn's Badge, cut from Lumen glass.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: `@base-ui/react@^1`, `class-variance-authority@^0.7` (Base UI build); `class-variance-authority@^0.7`, `radix-ui@^1` (Radix build).
- Files: `components/ui/lumen/badge.tsx`; shared code: `lib/beautiful-ui/lumen/badge-variants.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-foundation`.
- Builds: separate Base UI and Radix files. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `Badge`, `BadgeCount`, `badgeVariants`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-mono`, `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { Badge, BadgeCount } from "@/components/ui/lumen/badge";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `Badge` | `badge` | The badge, with its optional cell dot. |
| `BadgeCount` | `badge-count` | Beautiful UI: the mono count. |
| `badgeVariants` | `badge` | The classes alone, as shadcn. |

Style a part with `[data-slot="<slot>"]` selectors or its `className`; keep the attributes when editing.

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/badge.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- badge, status badge, tag, label, live indicator, count badge, pill, shadcn badge, Lumen
- Status: Live, Syncing, Needs review, Failed: the soft variant with a tone
- Live states: pulse blinks the cell dot
- Counts: BadgeCount (99+ past the max)
- A drop-in for shadcn's Badge: same export, variants and data-slot

### Not when
- Something people press to filter: use Lumen Toggle
- Long text: a badge is one short phrase

## Mistakes
- Don't use colour alone: the label must say the status
- Give BadgeCount an aria-label ("12 unread")
- Import from @/components/ui/lumen/badge: it never replaces your own

## Usage

```tsx
import { Badge, BadgeCount } from "@/components/ui/lumen/badge";

<Badge variant="soft" tone="success" pulse>Live</Badge>
<Badge variant="soft" tone="warning" dot>Needs review</Badge>
<BadgeCount count={12} aria-label="12 unread" />
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `variant` | `"default" \| "secondary" \| "destructive" \| "outline" \| "ghost" \| "link" \| "soft"` | `"default"` | shadcn's six in Lumen (solid, glass, soft danger, ring, bare, link) plus soft, the tinted status badge. |
| `tone` | `"neutral" \| "info" \| "success" \| "warning" \| "danger"` | `"neutral"` | Beautiful UI: the hue for solid, soft, outline and ghost. |
| `dot / pulse` | `boolean / boolean` |  | Beautiful UI: the square cell dot; pulse blinks it (and shows it). |
| `size` | `"default" \| "sm"` | `"default"` | Beautiful UI: 24px, or 20px mono uppercase. |
| `render (Base UI) / asChild (Radix)` | `ReactElement / boolean` |  | Render as a link or button, as shadcn; the dot still draws. |
| `BadgeCount count / max / variant` | `number / number / "glass" \| "strong"` | `— / 99 / glass` | Beautiful UI: a mono count; give it an aria-label for context. |

Full docs: https://beautiful-ui.dev/components/lumen-badge

## Customising
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Tab | Only when rendered as a link or button |

## Motion inventory

| Interaction | What moves |
|---|---|
| Pulse | The cell dot blinks on a 1.6s ease-in-out loop |
| Link or button | Brightens slightly on hover; a focus ring on keyboard focus |

## Accessibility contract (preserve when editing)
- A <span> (or your link or button); the dot is decoration drawn in CSS
- Tone is never the only signal: the label says the status
- Every tone reaches 4.5:1 on its fill in dark and light
- Reduced motion: the pulse holds still

## Install

Base UI project (a base-* style in components.json):

```bash
npx shadcn@latest add https://beautiful-ui.dev/r/lumen-badge.json
```

Radix project (a radix-*, new-york or default style):

```bash
npx shadcn@latest add https://beautiful-ui.dev/r/radix-nova/lumen-badge.json
```

Or add the `@beautiful-ui` registry to components.json and run `npx shadcn@latest add @beautiful-ui/lumen-badge`: the CLI picks the build from your style.

## Credits
- Built on shadcn/ui (https://ui.shadcn.com)

## Source (Base UI build)

### components/ui/lumen/badge.tsx

```tsx
/**
 * Badge (Lumen Halo) v1.0.0 · Beautiful UI
 * Docs: https://beautiful-ui.dev/components/lumen-badge · Agent prompt: https://beautiful-ui.dev/md/lumen-badge.md
 * Licensed to the purchaser under the Beautiful UI license: https://beautiful-ui.dev/license
 */
import * as React from "react";
import { mergeProps } from "@base-ui/react/merge-props";
import { useRender } from "@base-ui/react/use-render";
import type { VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
import { badgeAttrs, badgeVariants, formatCount, type BadgeExtras } from "@/lib/beautiful-ui/lumen/badge-variants";

/*
 * Lumen Badge (Base UI build). shadcn's Badge in Lumen Halo: solid, glass, soft (the status badge),
 * outline, ghost and link, in five tones, with the square cell dot that can blink for live states,
 * and a small mono size. BadgeCount is the mono count (99+). Server-safe, like shadcn's.
 */

function Badge({ className, variant = "default", tone, dot, pulse, size, render, ...props }: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & BadgeExtras) {
  return useRender({
    defaultTagName: "span",
    props: mergeProps<"span">({ className: cn(badgeVariants({ variant }), className), ...badgeAttrs({ tone, dot, pulse, size }) } as React.ComponentProps<"span">, props),
    render,
    state: { slot: "badge", variant },
  });
}

/** Beautiful UI: a mono count badge, at least 20px wide; past `max` it reads "99+". Give it context with aria-label ("12 unread"). */
function BadgeCount({ count, max = 99, variant = "glass", className, ...props }: Omit<React.ComponentProps<"span">, "children"> & { count: number; max?: number; variant?: "glass" | "strong" }) {
  return (
    <span data-slot="badge-count" data-variant={variant} className={cn(`lumen-badge-count`, className)} {...props}>
      {formatCount(count, max)}
    </span>
  );
}

export { Badge, BadgeCount, badgeVariants };
```

### lib/beautiful-ui/lumen/badge-variants.ts

```tsx
import { cva } from "class-variance-authority";

/*
 * Lumen Badge's classes, shared by both builds (server-safe: call it anywhere). shadcn's six
 * variants plus soft, the Lumen status badge; tones, the dot and the size are data attributes.
 */

export const badgeVariants = cva(`lumen-badge`, {
  variants: {
    variant: {
      default: `lumen-badge-default`,
      secondary: `lumen-badge-secondary`,
      destructive: `lumen-badge-destructive`,
      outline: `lumen-badge-outline`,
      ghost: `lumen-badge-ghost`,
      link: `lumen-badge-link`,
      soft: `lumen-badge-soft`,
    },
  },
  defaultVariants: { variant: "default" },
});

export type BadgeTone = "neutral" | "info" | "success" | "warning" | "danger";

/** The Beautiful UI props both builds add to shadcn's Badge (all optional). */
export interface BadgeExtras {
  /** The hue: neutral (default), info, success, warning, danger. */
  tone?: BadgeTone | undefined;
  /** The square cell dot before the label. */
  dot?: boolean | undefined;
  /** Blinks the dot, for live states ("Syncing", "Live"). */
  pulse?: boolean | undefined;
  /** "sm": 20px, mono uppercase. Default 24px. */
  size?: "default" | "sm" | undefined;
}

export const badgeAttrs = ({ tone, dot, pulse, size }: BadgeExtras) => ({
  "data-tone": tone && tone !== "neutral" ? tone : undefined,
  "data-dot": dot || pulse ? "" : undefined,
  "data-pulse": pulse ? "" : undefined,
  "data-size": size === "sm" ? "sm" : undefined,
});

/** 99 → "99", 120 → "99+" (for BadgeCount). */
export const formatCount = (count: number, max = 99) => (count > max ? `${max}+` : String(Math.max(0, Math.round(count))));
```

### CSS (the registry `css` / `cssVars`, merged into the global stylesheet by the shadcn CLI)

```css
@layer components {
  .lumen-badge {
    --k-fg: var(--gc-m80);
    --k-dot: var(--gc-m50);
    --k-soft: var(--gc-neutSoft);
    --k-ring: var(--gc-m14);
    --k-solid: var(--gc-neutSolid);
    --k-on: var(--gc-neutOn);
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
    flex: none;
    max-width: 100%;
    height: 24px;
    padding: 0 9px;
    border: none;
    border-radius: calc(8px * var(--lumen-radius-k, 1));
    font: 500 12px/1 var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
    letter-spacing: 0;
    white-space: nowrap;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    -webkit-font-smoothing: antialiased;
    transition: background var(--gc-t-c) ease,color var(--gc-t-c) ease,box-shadow var(--gc-t-c) ease;
  }
  .lumen-badge>svg {
    width: 12px;
    height: 12px;
    flex: none;
  }
  .lumen-badge[data-dot] {
    padding-left: 8px;
  }
  .lumen-badge[data-dot]::before {
    content: "";
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: calc(1.5px * var(--lumen-radius-k, 1));
    background: var(--k-dot);
  }
  .lumen-badge[data-pulse]::before {
    animation: lumen-blink 1.6s ease-in-out infinite;
  }
  .lumen-badge[data-size="sm"] {
    gap: 5px;
    height: 20px;
    padding: 0 7px;
    border-radius: calc(6px * var(--lumen-radius-k, 1));
    font: 500 10px/1 var(--lumen-font-mono, var(--font-mono, var(--font-geist-mono, 'Geist Mono'))), ui-monospace, monospace;
    letter-spacing: .08em;
    text-transform: uppercase;
  }
  .lumen-badge[data-size="sm"][data-dot] {
    padding-left: 6px;
  }
  .lumen-badge[data-size="sm"][data-dot]::before {
    width: 5px;
    height: 5px;
  }
  .lumen-badge-default {
    background: var(--k-solid);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.3);
    color: var(--k-on);
  }
  .lumen-badge-default[data-dot]::before {
    background: var(--gc-strongDot);
  }
  .lumen-badge-secondary {
    background: var(--gc-glassB);
    box-shadow: inset 0 0 0 1px var(--gc-glassR),var(--gc-glassX);
    color: var(--gc-m85);
  }
  .lumen-badge-soft,.lumen-badge-destructive {
    background: var(--k-soft);
    box-shadow: inset 0 0 0 1px var(--k-ring);
    color: var(--k-fg);
  }
  .lumen-badge-destructive {
    --k-fg: var(--gc-bad-tint);
    --k-dot: var(--gc-bad);
    --k-soft: color-mix(in srgb, var(--gc-bad) 12%, transparent);
    --k-ring: color-mix(in srgb, var(--gc-bad) 32%, transparent);
    --k-solid: var(--gc-bad-solid);
    --k-on: var(--gc-onSolid);
  }
  .lumen-badge-outline {
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--k-ring);
    color: var(--k-fg);
  }
  .lumen-badge-ghost {
    background: transparent;
    color: var(--k-fg);
  }
  .lumen-badge-link {
    background: transparent;
    padding: 0 2px;
    color: var(--gc-acc-ui);
    text-underline-offset: 3px;
  }
  .lumen-badge[data-tone="info"] {
    --k-fg: var(--gc-acc-tint);
    --k-dot: var(--gc-acc);
    --k-soft: color-mix(in srgb, var(--gc-acc) 13%, transparent);
    --k-ring: color-mix(in srgb, var(--gc-acc) 30%, transparent);
    --k-solid: var(--gc-acc-solid);
    --k-on: var(--gc-onSolid);
  }
  .lumen-badge[data-tone="success"] {
    --k-fg: var(--gc-good-tint);
    --k-dot: var(--gc-good);
    --k-soft: color-mix(in srgb, var(--gc-good) 12%, transparent);
    --k-ring: color-mix(in srgb, var(--gc-good) 30%, transparent);
    --k-solid: var(--gc-good-solid);
    --k-on: var(--gc-onSolid);
  }
  .lumen-badge[data-tone="warning"] {
    --k-fg: var(--gc-warn-tint);
    --k-dot: var(--gc-warn);
    --k-soft: color-mix(in srgb, var(--gc-warn) 12%, transparent);
    --k-ring: color-mix(in srgb, var(--gc-warn) 32%, transparent);
    --k-solid: var(--gc-warn);
    --k-on: #1d1304;
  }
  .lumen-badge[data-tone="danger"] {
    --k-fg: var(--gc-bad-tint);
    --k-dot: var(--gc-bad);
    --k-soft: color-mix(in srgb, var(--gc-bad) 12%, transparent);
    --k-ring: color-mix(in srgb, var(--gc-bad) 32%, transparent);
    --k-solid: var(--gc-bad-solid);
    --k-on: var(--gc-onSolid);
  }
  .lumen-badge-default[data-tone="warning"][data-dot]::before {
    background: rgba(0,0,0,.4);
  }
  .lumen-badge-destructive,.lumen-badge-destructive[data-tone] {
    --k-fg: var(--gc-bad-tint);
    --k-dot: var(--gc-bad);
    --k-soft: color-mix(in srgb, var(--gc-bad) 12%, transparent);
    --k-ring: color-mix(in srgb, var(--gc-bad) 32%, transparent);
    --k-solid: var(--gc-bad-solid);
    --k-on: var(--gc-onSolid);
  }
  @media (prefers-reduced-motion: reduce) {
    .lumen-badge[data-pulse]::before {
      animation: none;
    }
  }
  @media (hover:hover) {
    :is(a,button).lumen-badge:hover {
      filter: brightness(1.08);
    }
    :is(a,button).lumen-badge-ghost:hover {
      background: var(--gc-neutSoft);
    }
    :is(a,button).lumen-badge-link:hover {
      text-decoration: underline;
      filter: none;
    }
  }
  :is(a,button).lumen-badge:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--gc-gap), 0 0 0 4px var(--gc-p-focus), 0 0 #0000;
  }
  .lumen-badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    flex: none;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: calc(6px * var(--lumen-radius-k, 1));
    background: var(--gc-glassB);
    box-shadow: inset 0 0 0 1px var(--gc-glassR);
    color: var(--gc-m85);
    font: 500 10.5px/1 var(--lumen-font-mono, var(--font-mono, var(--font-geist-mono, 'Geist Mono'))), ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    vertical-align: middle;
  }
  .lumen-badge-count[data-variant="strong"] {
    background: var(--gc-acc-solid);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.3);
    color: var(--gc-onSolid);
  }
}
```

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
