Usage Meter
ProNewHow much of an allowance is used: amber and red as the limit nears, a tick where the warning starts, and overage shown as an amount.
Installation
pnpm dlx shadcn@latest add @viewport/usage-meter
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| label* | stringWhat is metered, e.g. "API requests". | — |
| used* | number | — |
| limit* | number | — |
| format | (value: number) => stringFormats the two numbers, e.g. to add a unit. | (value) => new Intl.NumberFormat().format(value) |
| warnAt | numberThe share of the limit at which the bar turns to the warning color, and to the danger color. | 0.75 |
| dangerAt | number | 0.9 |
| hint | stringA note at the end of the row, e.g. "Resets Jan 1". | — |
| className | string | — |
Accessibility
- A meter with a value text that includes the state.
- “Getting close”, “Near the limit” and “Over the limit” are written out.
- Server component with no client JavaScript.
- Respects prefers-reduced-motion.