Passa al contenuto principale

LevelIndicator

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

A scale of equal bands, such as an air quality index or a pollen count, with the current band emphasized.

Import​

import { LevelIndicator } from "~lib/data-display/level-indicator";

Props​

NameTypeRequiredDefaultDescription
levels{ label: string; pattern?: PatternType }[]YesN/AThe bands of the scale, lowest first
activenumberNoN/APosition of the current band, counting from 0. Leave it out when there is no reading
labels"auto" | "all" | "active" | "none"No"auto"Which band names to show under the bar
size"sm" | "md" | "lg"No"md"Height of the bar and size of its labels
widthnumber | stringNo"100%"Width of the indicator
inactive"dim" | "outline"No"dim"How the bands other than the current one are drawn
labelstringNoN/AName of the scale, shown above the bar
showCategorybooleanNofalseShow the current band's name above the bar, at the other end from the label
captionReactNodeNoN/AContent shown above the bar in place of the label

PatternType: "solid" | "diagonal" | "dots" | "crosshatch". A band without a pattern is drawn as an outline, and fills in when it is the current one.

Labels: "auto" shows every band's name when they all fit, only the current band's name when they would not, and none when even that would not fit. The row the names sit in keeps its height either way, so the indicator is the same height at any width. "none" leaves the row out.

Examples​

Air Quality​

active counts from 0, so an air quality index of 3 on a 1 to 5 scale is active={2}.

Apri Air Quality in Storybook

Pollen​

Apri Pollen in Storybook

UV Index​

Apri UV Index in Storybook

Narrow​

When the names would not all fit, only the current band's name is shown.

Apri Narrow in Storybook

No Reading​

Apri No Reading in Storybook

Patterned​

Apri Patterned in Storybook

Outlined​

The bands other than the current one are dimmed by default, so a solid band shows as grey on screen and as speckles on the frame. Set inactive="outline" to draw them as plain outlines instead; only the current band is filled.

Apri Outlined in Storybook

Sizes​

Apri Small in Storybook
Apri Large in Storybook

Label Modes​

Apri Active Label Only in Storybook
Apri Without Labels in Storybook

Name and Category​

Give the scale a label to name it above the bar, and set showCategory to show the current band's name at the other end of that row. Their text grows with size. The row stays the same height when there is no reading, so the indicator does too.

Apri With Label And Category in Storybook

Caption​

Pass caption to put your own content above the bar in place of the label, such as a name beside a Badge.

Apri Caption With Badge in Storybook

See Also​

  • Meter - A continuous bar with a marker
  • Gauge - A semicircular dial
  • Badge - Inline label