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

- id: `lumen-gauge` · version 1.0.0 · component · free
- category: Data
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add https://beautiful-ui.dev/r/lumen-gauge.json`
- npm dependencies: none
- registry dependencies: utils, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-gauge
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A value in a known range, read as a dial of hairline ticks: ticks light to the value in the tone of its band, a longer tick marks where each band begins, and the band's word sits under the number.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: none beyond React.
- Files: `components/ui/lumen/controls/gauge.tsx`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. 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: `Gauge`, 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-foreground`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-chart-accent`, `--lumen-chart-accent-foreground`, `--lumen-chart-accent-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-sans`. Never add Tailwind colour classes inside the component.

```tsx
import { Gauge } from "@/components/ui/lumen/controls/gauge";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `Gauge` | — | The meter: its dial (gauge-dial) and the number with its caption (gauge-readout). |

## 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/controls/gauge.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
- gauge, dial, meter, speedometer, score, health score, CPU, latency, threshold, KPI dial
- One reading in a known range where thresholds matter: CPU, error budget, a health or credit score
- Status tiles where the zone matters more than the exact number

### Not when
- An allowance by category: use Usage Meter
- Progress toward done: use Progress
- Comparing several values: a bar chart reads better than several dials

## Mistakes
- Thresholds are where a band begins, in the gauge's own units (not 0–1)
- Give every band a word if colour carries meaning

## Usage

```tsx
"use client";

import { Gauge } from "@/components/ui/lumen/controls/gauge";

export function CpuGauge({ cpu }: { cpu: number }) {
  return (
    <Gauge
      label="CPU"
      value={cpu}
      unit="%"
      thresholds={[
        { at: 0, tone: "good", label: "Healthy" },
        { at: 65, tone: "warn", label: "Busy" },
        { at: 85, tone: "bad", label: "Saturated" },
      ]}
    />
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `value` | `number` |  | The reading. The dial clamps it to min–max; the number shows it as given. |
| `min / max` | `number` | `0 / 100` | The range. |
| `label` | `string` |  | What is measured: the accessible name, and the caption when no band has a word. |
| `thresholds` | `{ at, tone: "neutral" \| "good" \| "warn" \| "bad", label? }[]` | `[]` | Where bands begin. Below the first, the dial is neutral ink. |
| `unit` | `string` |  | After the number, e.g. "%" or "ms". |
| `format / locale` | `(v) => string / string` |  | Formats the number. Default: the locale's number, up to one decimal. |
| `caption` | `ReactNode` |  | Replaces the word under the number. |
| `ticks / size` | `number` | `41 / 176` | How many ticks, and the width in px. |

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

## 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 | Not focusable: it reports a reading |

## Motion inventory

| Interaction | What moves |
|---|---|
| First paint and changes | Ticks light in order from the start; reduced motion shows them at once |

## Accessibility contract (preserve when editing)
- role=meter with min, max and now; the value text adds the band's word ("72%, Busy")
- The zone is in words under the number, never colour alone

## Install

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

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

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

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

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

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

## Source (Base UI build)

### components/ui/lumen/controls/gauge.tsx

```tsx
"use client";
// Generated from src/registry/core/controls/gauge.tsx by scripts/gen-systems.ts. Edit the core file, not this one.

import * as React from "react";
import { cn } from "@/lib/utils";

/*
 * Gauge: a value in a known range, read as a dial of hairline ticks. Ticks light up to the value, in the
 * tone of the band the value is in (thresholds), and a longer tick marks where each band begins, so the
 * zones ahead are readable before the value reaches them. The number sits in the middle with the band's
 * word under it: the state never relies on colour alone. A meter for assistive tech.
 *
 *   <Gauge label="CPU" value={72} unit="%" thresholds={[{ at: 60, tone: "warn", label: "Busy" }, { at: 85, tone: "bad", label: "Saturated" }]} />
 */

export type GaugeTone = "neutral" | "good" | "warn" | "bad";

export interface GaugeThreshold {
  /** The band starts at this value (in the gauge's own range). */
  at: number;
  tone: GaugeTone;
  /** The word under the number while the value is in this band. */
  label?: string | undefined;
}

const START = 150; // degrees clockwise from 3 o'clock: the dial opens at the bottom
const SWEEP = 240;

/** The band a value falls in: the last threshold at or below it (none below the first). */
export function gaugeBand(value: number, thresholds: readonly GaugeThreshold[]): GaugeThreshold | undefined {
  return [...thresholds].sort((a, b) => a.at - b.at).filter((t) => value >= t.at).pop();
}

const pt = (c: number, r: number, deg: number) => {
  const a = (deg * Math.PI) / 180;
  return [+(c + r * Math.cos(a)).toFixed(2), +(c + r * Math.sin(a)).toFixed(2)] as const;
};

function Gauge({
  value,
  min = 0,
  max = 100,
  label,
  thresholds = [],
  ticks = 41,
  size = 176,
  unit,
  format,
  locale,
  caption,
  className,
  style,
  ...props
}: Omit<React.ComponentProps<"div">, "children"> & {
  /** The reading. Clamped to min–max for the dial; the number shows it as given. */
  value: number;
  min?: number;
  max?: number;
  /** What is measured. The accessible name, and the caption when no band has a word. */
  label: string;
  /** Where bands begin, with their tone and word. Below the first: neutral. */
  thresholds?: readonly GaugeThreshold[];
  /** How many ticks draw the dial. Default 41. */
  ticks?: number;
  /** Width in px. Default 176. */
  size?: number;
  /** After the number, e.g. "%" or "ms". */
  unit?: string | undefined;
  /** Formats the number. Default: the locale's number, up to one decimal. */
  format?: ((value: number) => string) | undefined;
  locale?: string | undefined;
  /** Replaces the word under the number. */
  caption?: React.ReactNode;
}) {
  const span = max - min || 1;
  const clamped = Math.min(max, Math.max(min, Number.isFinite(value) ? value : min));
  const t = (clamped - min) / span;
  const band = gaugeBand(clamped, thresholds);
  const tone: GaugeTone = band?.tone ?? "neutral";
  const fmt = format ?? ((v: number) => new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }).format(v));
  const text = `${fmt(value)}${unit ? (unit === "%" ? "%" : ` ${unit}`) : ""}`;

  // Numeric props from config or a CMS can be anything: keep the dial drawable.
  const n = Number.isFinite(ticks) ? Math.max(2, Math.min(120, Math.round(ticks))) : 41;
  const dial = Number.isFinite(size) && size >= 48 ? size : 176;
  const c = dial / 2;
  const outer = c - 2;
  const len = Math.max(6, dial * 0.065);
  const lit = Math.round(t * (n - 1));
  // Ticks where a band begins are drawn longer.
  const edges = new Set(thresholds.filter((th) => th.at > min && th.at < max).map((th) => Math.round(((th.at - min) / span) * (n - 1))));
  const height = Math.ceil(c + outer * Math.sin((START * Math.PI) / 180) + 4);

  return (
    <div
      role="meter"
      aria-label={label}
      aria-valuemin={min}
      aria-valuemax={max}
      aria-valuenow={clamped}
      aria-valuetext={band?.label ? `${text}, ${band.label}` : text}
      data-slot="gauge"
      data-tone={tone}
      className={cn(`lumen-gauge`, className)}
      style={{ width: dial, height, ...style }}
      {...props}
    >
      <svg aria-hidden viewBox={`0 0 ${dial} ${height}`} width={dial} height={height} className={`lumen-gauge-dial`} data-slot="gauge-dial">
        {Array.from({ length: n }, (_, i) => {
          const deg = START + (SWEEP * i) / (n - 1);
          const edge = edges.has(i);
          const [x1, y1] = pt(c, outer, deg);
          const [x2, y2] = pt(c, outer - (edge ? len * 1.6 : len), deg);
          // The ticks a band covers carry its tone, lit or not, so the zones read ahead of the value.
          const at = min + (span * i) / (n - 1);
          const zone = gaugeBand(at, thresholds)?.tone ?? "neutral";
          return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2} data-on={i <= lit || undefined} data-zone={zone} data-edge={edge || undefined} style={{ "--i": i } as React.CSSProperties} />;
        })}
      </svg>
      <div className={`lumen-gauge-readout`} data-slot="gauge-readout">
        <span className={`lumen-gauge-value`} style={{ fontSize: Math.round(dial * 0.18) }}>
          {fmt(value)}
          {unit && <span className={`lumen-gauge-unit`}>{unit}</span>}
        </span>
        <span className={`lumen-gauge-caption`}>{caption ?? band?.label ?? label}</span>
      </div>
    </div>
  );
}

export { Gauge };
```

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

```css
@layer components {
  .lumen-gauge {
    --gauge-tone: var(--gc-ink);
    --gauge-text: var(--gc-sec);
    position: relative;
    display: inline-grid;
    place-items: center;
    flex: none;
    max-width: 100%;
    color: var(--gc-ink);
    font: 400 13px/1.3 var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
  }
  .lumen-gauge[data-tone="good"] {
    --gauge-tone: var(--gc-good);
    --gauge-text: var(--gc-good-ui);
  }
  .lumen-gauge[data-tone="warn"] {
    --gauge-tone: var(--gc-warn);
    --gauge-text: var(--gc-warn-ui);
  }
  .lumen-gauge[data-tone="bad"] {
    --gauge-tone: var(--gc-bad);
    --gauge-text: var(--gc-bad-ui);
  }
  .lumen-gauge-dial {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
  }
  .lumen-gauge-dial line {
    stroke: var(--gc-cellOff);
    stroke-width: 2;
    stroke-linecap: round;
    transition: stroke calc(.35s * var(--gcp-k,1)) ease calc(var(--i) * 8ms * var(--gcp-k,1));
  }
  .lumen-gauge-dial line[data-zone="good"]:not([data-on]) {
    stroke: color-mix(in srgb,var(--gc-good) 24%,transparent);
  }
  .lumen-gauge-dial line[data-zone="warn"]:not([data-on]) {
    stroke: color-mix(in srgb,var(--gc-warn) 24%,transparent);
  }
  .lumen-gauge-dial line[data-zone="bad"]:not([data-on]) {
    stroke: color-mix(in srgb,var(--gc-bad) 24%,transparent);
  }
  .lumen-gauge-dial line[data-on] {
    stroke: var(--gauge-tone);
    animation: lumen-gauge-on calc(.4s * var(--gcp-k,1)) ease calc(var(--i) * 14ms * var(--gcp-k,1)) both;
  }
  .lumen-gauge:not([data-tone="neutral"]) .lumen-gauge-dial line[data-on] {
    filter: drop-shadow(0 0 2px color-mix(in srgb,var(--gauge-tone) 60%,transparent));
  }
  @keyframes lumen-gauge-on {
    from {
      stroke: var(--gc-cellOff);
    }
  }
  .lumen-gauge-readout {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding-top: 6%;
    text-align: center;
  }
  .lumen-gauge-value {
    font-weight: 600;
    line-height: 1;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
  }
  .lumen-gauge-unit {
    margin-inline-start: 2px;
    font-size: .5em;
    font-weight: 500;
    letter-spacing: 0;
    color: var(--gc-sec);
  }
  .lumen-gauge-caption {
    max-width: 12ch;
    font-size: 12px;
    font-weight: 500;
    color: var(--gauge-text);
  }
  @media (prefers-reduced-motion:reduce) {
    .lumen-gauge-dial line {
      transition: none;
    }
    .lumen-gauge-dial line[data-on] {
      animation: none;
    }
  }
}
```

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.
