Usage Meter
NewPlan quota bar: amber near the limit, red with the overage once passed, unlimited state and a compact list size.
Installation
$ pnpm dlx shadcn@latest add @synccn/usage-meterFirst time in this project? Connect synccn with one command.
Usage
import { UsageMeter, usageStatus } from "@/components/ui/usage-meter";<UsageMeter label="API requests" value={842000} limit={1000000} hint="Resets Dec 1" />API reference
Generated from the component's TypeScript types, so it always matches the code.
UsageMeter
Quota bar for plans and billing: used of limit, amber near the limit, red with the overage once it's passed, and an "unlimited" state. Uses role meter with readable values.
- labelrequired
React.ReactNodeWhat's being measured, e.g. "API requests".
- valuerequired
numberAmount used so far.
- limitrequired
number | nullThe plan's limit. Pass null for unlimited.
- unit
stringUnit after the numbers, e.g. "GB".
- format
(n: number) => stringDefault
compactFormats numbers. Defaults to compact notation: 1.2k, 3.4M.
- warnAt
numberDefault
0.8Share of the limit at which the meter turns amber, from 0 to 1.
- hint
React.ReactNodeSmall print under the bar, such as "Resets Dec 1".
- action
React.ReactNodeSomething to do about it, such as an Upgrade link, shown when the meter is amber or over.
- size
"default" | "compact"Default
"default""default" stacks the label over the bar; "compact" fits on one line for lists.
- className
stringExtra classes for the root element.
usageStatus
Works out the meter's state, so you can show the same thing elsewhere (a badge, an email).
Takes no props.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for AlertTriangle, Infinity
Used by
Accessibility
- Uses role meter with aria-valuetext such as "842K of 1M, 12K over the limit", so the state isn't conveyed by colour alone.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: meter
- ARIA attributes: aria-label, aria-valuemax, aria-valuemin, aria-valuenow, aria-valuetext