Demos

A full ring with the value as a percentage.

Usage

Use a gauge to show a single measurement against a fixed range: a health score, sleep quality, recovery. It reads as a reading, not a task, so use a progress bar for uploads and other work in flight.

Import it from @workspace/ui/components/gauge.

For the common case, GaugeCombined renders the indicator, track, range and value text for you.

Anatomy

  • Gauge — The root. Holds the value and geometry, and has the meter role.
  • GaugeIndicator — The SVG that draws the ring. Put GaugeTrack and GaugeRange inside it.
  • GaugeTrack — Every segment, in a muted colour.
  • GaugeRange — The filled segments, up to the current value.
  • GaugeValueText — The text centred over the ring. Defaults to a percentage.
  • GaugeLabel — Names the measurement. Read by screen readers.

Notes

  • Without a GaugeLabel, give the root an aria-label.
  • GaugeValueText is centred over its nearest positioned parent. If you place a GaugeLabel below the ring, wrap the indicator and value text in a relative element so the text stays centred on the ring.
  • Pass getValueText to change the text read by screen readers and shown by default. Pass children to GaugeValueText to change only what is shown.
  • Colour the fill with a text colour class on GaugeRange, for example text-chart-2. Segments use currentColor.
  • The gauge lowers segments when they would not fit around the ring at the given thickness and gap.

Examples

With label

A GaugeLabel below the ring.

Arc

Set startAngle and endAngle to draw part of a ring. Angles are in degrees, with 0 at the top, increasing clockwise.

Custom value

Set min and max for a range that is not 0–100, and pass children to GaugeValueText to show a unit and caption.

Sizes

Change size, and lower segments and tickInnerRadius on small gauges so the ticks stay readable.

Indeterminate

Set value={null} when there is no reading yet. Only the track is drawn.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

Gauge

PropTypeDefaultDescription
valuenumber or nullnullCurrent value. null is indeterminate. Clamped to min–max.
minnumber0Lowest value.
maxnumber100Highest value.
getValueText(value, min, max) => stringPercentageText for screen readers and the default GaugeValueText.
sizenumber200Width and height in pixels.
thicknessnumber2Stroke width of each segment.
gapnumber4Minimum space between segments.
segmentsnumber60Number of segments.
startAnglenumber0Where the ring starts, in degrees.
endAnglenumber360Where the ring ends, in degrees.
tickInnerRadiusnumberRadius − 24Inner end of each segment.
tickOuterRadiusnumberRadiusOuter end of each segment.
classNamestring—Classes merged onto the root.

Data attributes

The root, GaugeIndicator and GaugeRange set data-state to indeterminate, loading or complete, so you can style each state, for example data-[state=complete]:text-chart-2.