Gauge
Half-circle gauge with warning and danger thresholds.
$
pnpm dlx shadcn@latest add https://lodeui.com/r/gauge.json64%
Storage used
components/examples/gauge-demo.tsx
"use client";
import * as React from "react";
import { Gauge } from "@/components/ui/gauge";
import { Slider } from "@/components/ui/slider";
export default function GaugeDemo() {
const [v, setV] = React.useState(64);
return (
<div className="flex w-full max-w-xs flex-col items-center gap-6">
<Gauge value={v} label="Storage used" />
<Slider aria-label="Value" value={v} onValueChange={setV} />
</div>
);
}When to use
- Scores, capacity and SLA targets against a maximum.
When not to use
- Trends: use a chart.
Installation
$
pnpm dlx shadcn@latest add https://lodeui.com/r/gauge.json1Install the dependencies
npm install motion2Copy the source into your project
components/ui/gauge.tsx"use client"; import * as React from "react"; import { motion } from "motion/react"; import { cn } from "@/lib/utils"; export interface GaugeProps { value: number; max?: number; label?: string; /** Fractions where the arc turns amber, then red. */ thresholds?: [warn: number, danger: number]; format?: (v: number) => string; size?: number; className?: string; } /** A half-circle gauge for scores, capacity and SLAs. */ export function Gauge({ value, max = 100, label, thresholds = [0.7, 0.9], format = (v) => `${Math.round(v)}%`, size = 200, className }: GaugeProps) { const t = Math.min(1, Math.max(0, value / max)); const color = t >= thresholds[1] ? "var(--destructive)" : t >= thresholds[0] ? "#f59e0b" : "var(--chart-4)"; const r = 80; const arc = `M 20 100 A ${r} ${r} 0 0 1 180 100`; return ( <div className={cn("relative inline-flex flex-col items-center", className)} style={{ width: size }} role="meter" aria-valuemin={0} aria-valuemax={max} aria-valuenow={value} aria-label={label}> <svg viewBox="0 0 200 112" className="w-full overflow-visible"> <path d={arc} fill="none" stroke="var(--muted)" strokeWidth={14} strokeLinecap="round" /> <motion.path d={arc} fill="none" stroke={color} strokeWidth={14} strokeLinecap="round" initial={{ pathLength: 0 }} animate={{ pathLength: t, stroke: color }} transition={{ type: "spring", stiffness: 60, damping: 16 }} /> </svg> <div className="absolute inset-x-0 bottom-1 text-center"> <p className="text-3xl font-semibold tracking-tight tabular-nums">{format(value)}</p> {label && <p className="text-xs text-muted-foreground">{label}</p>} </div> </div> ); }
Usage
Import it from @/components/ui/gauge after installing.
example.tsx
import { Gauge } from "@/components/ui/gauge";
export function Cpu() {
return <Gauge value={72} label="CPU" thresholds={[0.7, 0.9]} format={(v) => `${v}%`} />;
}API reference
Gauge
A half-circle gauge that turns amber, then red, past thresholds.
| Prop | Type | Default | Description |
|---|---|---|---|
| value / max | number | — / 100 | Reading. |
| label / format | string / (v) => string | – | Caption and number. |
| thresholds | [warn, danger] | – | Fractions of max. |
| size | number | 200 | Width in px. |
Accessibility
- role="meter" with min, max and now.
Motion
- The arc sweeps to its value.
Responsive behavior
- Shrinks to fit narrow containers.
Performance
- One SVG.
Notes for AI
- thresholds are fractions (0.7), not values (70).
This page as Markdown, for assistants and coding agents:
/components/gauge/markdownThe full library index for assistants is at /llms.txt.
Lode222 doc pagesllms.txt