Usage meter
Allowance progress and written category contributions with explicit near/exceeded status.
npx @swipeui/cli add usage-meterWhen to use it
- Storage, data or credit allowances, such as 12 of 15 GB used.
- Breakdowns by category, like photos, videos and documents.
- Warning people before they hit a limit and stating clearly when they've gone over.
When not to use it
- Simple progress. Use Progress.
- A single number. Use Metric card.
- Budgets with many categories; build a chart.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add usage-meter- Adds
components/swipeui/ui/usage-meter.tsxand 10 shared helpers. - Installs react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, class-variance-authority, expo-haptics. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { UsageMeter } from '@/components/swipeui/ui/usage-meter';
<UsageMeter label="Storage" limit={10} unit="GB" segments={usage} />;Examples
Storage shows an inspectable category breakdown. Credits shows a compact monthly balance. Each demo has an external control for exercising all three allowance states in the top-right tag.
API reference
UsageMeterProps
| Prop | Type | Default | Description |
|---|---|---|---|
animateValue? | | | Animate changing values. |
animateSegments? | | | Animate segment proportions. |
animateStatus? | | | Crossfade the allowance tag when its state changes. |
showLegend? | | | Show the written category breakdown. |
inspectBar? | | | Allow direct bar inspection; the legend remains independent. |
appearance? | | | Card or transparent surface. |
interactive? | | | Enable category inspection without modifying usage. |
selectedSegment? | | | Controlled inspected category; null shows the total. |
defaultSelectedSegment? | | | Initial inspected category. |
onSelectedSegmentChange? | | — | Category selection intent. |
messages? | | — | Translated allowance statuses. |
label | | — | Named allowance. |
limit | | — | Positive allowance. |
segments | | — | Ordered contributions; labels carry meaning beyond colour. |
unit? | | | Formatted unit suffix, such as 'GB'. |
locale? | | — | Locale for numeric labels. |
warningAt? | | | Warning fraction. |
motion? | | — | Shared number feel. |
haptics? | | | Action haptics. |
className? | | — | Root classes. |
style? | | — | Native layout escape hatch. |
testID? | | — | Root ID. |
Native view/input props not listed here pass through where the exported TypeScript type allows them.
Composition and behavior
- label and limit define the allowance; segments list categories with labels and values.
- unit, locale and warningAt shape the text and warning.
Settings
| Prop | Does / default |
|---|---|
id | Stable category identifier. |
label | Named allowance. |
value | Non-negative usage in the same unit as limit. |
appearance | Card or transparent surface. @default 'elevated' |
showLegend | Show category rows. Defaults to true. |
animateStatus | Crossfade the allowance tag when its state changes. Defaults to true and respects reduced motion. |
interactive | Enable category inspection without modifying usage. @default true |
selectedSegment | Controlled inspected category; null shows the total. @default undefined |
defaultSelectedSegment | Initial inspected category. @default null |
onSelectedSegmentChange | Category selection intent. |
messages | Translated allowance statuses. |
limit | Positive allowance. |
segments | Ordered contributions; labels carry meaning beyond colour. |
unit | Formatted unit suffix, such as 'GB'. @default '' |
locale | Locale for numeric labels. |
warningAt | Warning fraction. @default 0.9 |
motion | Shared number feel. |
className | Root classes. |
style | Native layout escape hatch. |
testID | Root ID. |
Behaviour
Tap the bar or a legend row to inspect a category. selectedSegment/defaultSelectedSegment/onSelectedSegmentChange support controlled and uncontrolled inspection. The component never changes usage. It belongs to Lists and data display.
Action haptics can be disabled independently with haptics={false} (default true).
Behavior and gestures
- The Storage board inspects category segments; Credits shows a compact monthly balance.
- Near the limit (90% by default) and over it, the status text changes, not just the colour.
Accessibility
- Announced as a progress bar with its label and status, such as "Storage: Near limit" or "Storage: Limit exceeded".
- Each category is written out with its value, so colour isn't the only signal.
- Over-limit allowances say so explicitly.
Motion
- Uses the
numberandmorphmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The number and bar animate independently of the status tag. Reduce Motion shows status changes immediately.
Performance
- A few views; numbers are formatted with your locale.
Notes for AI
- Pass limit and segments with values in the same unit; set unit like "GB".
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.