Skip to content

Meter

A labelled bar for a bounded measurement, with normal, warning and danger tones and a usage variant.

Base UI2.3 kB gzipSource Registry JSON

Meter playground

Requests
x

Props

tone

Installation

npx shadcn@latest add https://sproutboat.com/ikada/r/meter.json

The CLI writes components/ikada/meter.tsx and merges the ikada theme into your CSS. It also installs the components it is built from: Status Glyph. Or take it from the package: import { Meter, UsageMeter } from "@sproutboat/ikada";

Usage

import { Meter, UsageMeter } from "@/components/ikada/meter";

<Meter label="Requests" value={62} />

Examples

Tones

Normal, warning (amber) and danger (red). The fill grows over 250ms.
Requests
x
Storage
x
Build minutes
x

Usage against a plan limit

Amber from 80% and at 100%; red only when the platform is actually refusing work (blocked). The state is written out too.
RequestsNear limit860K of 1M
x
StorageNear limit4.4 of 5 GB
x
DeploysBlocked100 of 100
x
Sprouts4, unlimited

Without a visible label

Pass aria-label, and valueLabel={null} to drop the number as well.
x

Props

MeterProps
PropTypeDescription
classNamestringClasses merged onto the root element, after ikada's own.
localestringNumber-formatting locale; defaults to the `LocaleProvider` value, else `en`.
labelReactNodeVisible label above the bar. Without one, pass `aria-label`.
toneMeterToneFill colour: normal, warning (amber) or danger (red). Default normal.
valueLabelReactNodeRight of the label; defaults to the formatted value.
styleCSSProperties | ((state: MeterRootState) => CSSProperties)Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MeterRootState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

Also takes every prop of Omit<ComponentProps<typeof BaseMeter.Root>, "className" | "children" | "locale">.

UsageMeterProps
PropTypeDescription
usedrequirednumberAmount used so far, in the same unit as the limit.
limitrequirednumber | null`null` is unlimited: the bar is replaced by the number alone.
unitstringUnit suffix, e.g. "GB" or "requests".
warnAtnumberNear-limit threshold as a fraction. Default 0.8.
blockedbooleanThe platform is actually refusing work (writes rejected, deploys paused). Only then is the meter red. Reaching the limit without being blocked stays amber. Default `false`.
formatValue((n: number) => string)Defaults to compact units in the resolved locale: 860K, 1M, 4.4.
classNamestringClasses merged onto the root element, after ikada's own.
styleCSSProperties | ((state: MeterRootState) => CSSProperties)Style applied to the element, or a function that returns a style object based on the component's state.
labelReactNodeVisible label above the bar. Without one, pass `aria-label`.
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MeterRootState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
localestringNumber-formatting locale; defaults to the `LocaleProvider` value, else `en`.

Also takes every prop of Omit<MeterProps, "value" | "max" | "min" | "tone" | "valueLabel" | "format">.

Source: src/components/meter.tsx