Metric card
A key number with its trend: a muted title, a tinted trend chip, a very large value that counts to each new number, a description and the metric's history as a line behind it.
npx @swipeui/cli add metric-cardWhen to use it
- Dashboard tiles for one key number, such as active users, revenue or steps today, with how it moved.
- A KPI that switches range (7D, 30D, 90D) from a segmented control below the card and counts to the new value.
- A home screen row of two or three key numbers, each with a trend chip.
- Any place where the exact formatted number matters more than decoration.
When not to use it
- Several facts of equal weight, such as session settings. Table card lists label and value rows.
- Progress toward a goal. Progress or Usage meter shows how much is left.
- Full charts with axes and legends; the sparkline slot only has room for a small chart.
- A daily focus summary over artwork. Time-of-day card is designed for that.
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 metric-card- Adds
components/swipeui/card/metric-card.tsx,components/swipeui/card/use-metric-trend.tsand 8 shared helpers. - Installs class-variance-authority, react-native-reanimated, react-native-svg, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { MetricCard } from '@/components/swipeui/card/metric-card';
<MetricCard
title="Quarterly active users"
value={21870}
change="−2.1%"
trend="down"
description="Compared with the last 90 days"
series={last90Days}
/>;Examples
import { useState } from 'react';
import { MetricCard } from '@/components/swipeui/card/metric-card';
import { SegmentedControl } from '@/components/swipeui/ui/segmented-control';
// The range control sits below the card; the value counts to each range.
const [range, setRange] = useState<'7d' | '30d' | '90d'>('90d');
const stat = stats[range];
<MetricCard
title="Active users"
value={stat.value}
change={stat.change}
trend={stat.trend}
description={stat.description}
series={stat.history}
/>;
<SegmentedControl
options={[
{ value: '7d', label: '7D' },
{ value: '30d', label: '30D' },
{ value: '90d', label: '90D' },
]}
value={range}
onValueChange={setRange}
/>;import { MetricCard } from '@/components/swipeui/card/metric-card';
import { Button } from '@/components/swipeui/ui/button';
// A preformatted string, an outline surface and a footer action.
<MetricCard
title="Revenue this month"
value="$1.2M"
change="+8%"
trend="up"
surface="outline"
footer={<Button variant="outline" onPress={openReport}>View report</Button>}
/>;Glass appearance
In the preview, choose Glass in the Preset picker. Pass the Pro Glass material into surfaceBackground to style the card fill.
API reference
MetricCardProps
| Prop | Type | Default | Description |
|---|---|---|---|
title | | — | What the number measures, in muted text at the top start. |
value | | — | The value. A number is formatted with |
change? | | — | The change, exactly as it should read in the chip, such as "−2.1%" or "+340". |
trend? | | | Which way it moved: tints the chip green, red or grey. Never inferred from a minus sign. |
trendLabels? | | | How screen readers hear the trend word before the change. The sign is dropped after a word, so
"−2.1%" with |
description? | | — | A muted line under the value, such as "Compared with the last 90 days". |
chip? | | | Shows the change as a chip at the top end. |
animateValue? | | | Numeric values count from the previous value on the number role. Strings always swap at once, and Reduce Motion shows the new value at once. |
precision? | | | Decimal places for a numeric value, from 0 to 6. |
locale? | | | Number locale for a numeric value. |
series? | | — | The metric's history, oldest first, such as one value per day of the range. It's drawn as a trend line behind the card's content, edge to edge, scaled so its lowest value sits near the bottom and its highest near the top. Pass the new range's numbers to morph the line. |
trendLine? | | | Draws the trend line behind the content. |
trendLineFill? | | | A soft wash under the trend line, fading toward the bottom. Off under Reduce Transparency. |
animateTrendLine? | | | The line grows in on first appearance and morphs to each new series with the value's count. Reduce Motion shows the new line at once. |
sparkline? | | — | Your own small chart under the description; decorative and hidden from screen readers. |
backdrop? | | | A decorative layer behind the text and above the card fill (solid or Glass), clipped to the card and aligned to its bottom, such as a full-width background Sparkline. Hidden from screen readers and touches pass through. |
footer? | | — | Content under everything else, such as a View report button; it keeps its own focus. |
surface? | | | Surface treatment. |
surfaceBackground? | | | Decorative replacement for the card fill. It receives the card’s bounds. |
onPress? | | — | Opens the metric's detail. Without it the card is a static surface. |
disabled? | | | Prevents pressing and dims the card. |
haptics? | | | A light haptic tap when pressed. |
motion? | | | Motion for the press and the value's count. |
accessibilityLabel? | | | What a screen reader announces. |
accessibilityHint? | | — | Says what pressing does, such as "Opens the users report". |
className? | | — | Classes merged over the card. |
style? | | — | Native style escape hatch for the card. |
testID? | | — | Root identifier; parts add |
Composition and behavior
- title sits at the top start in muted text and change shows as a chip at the top end, tinted by trend: green for up, red for down, grey for neutral. The trend is never inferred from a minus sign.
- value is the very large number. Pass a number to get locale grouping and a count to each new value on the number role, or a preformatted string to show it exactly. description is a muted line under it.
- series draws the metric's history as a line behind everything, edge to edge and tinted by trend, with a soft wash under it. A new range's numbers morph the line in step with the value's count; it's decorative and hidden from screen readers.
- Put range controls, such as a 7D / 30D / 90D segmented control, outside the card and change value, change, trend and description together.
- The card is read as one element with the trend spoken, such as "Quarterly active users, 21,870, down 2.1%, Compared with the last 90 days". The sparkline slot is decorative and hidden.
- 2.0 renamed
labelto title andpositive/negativeto up / down, and replaced Card's variants with surface. See the changelog.
Metric settings
| Prop | Does | Default |
|---|---|---|
| trend | up, down or neutral: tints the chip | neutral |
| chip | Shows the change as a chip | true with a change |
| trendLabels | The trend words screen readers hear | up, down |
| animateValue | Numbers count to each new value | true |
| precision | Decimal places for a number | 0 |
| locale | Number grouping and decimals | the device locale |
| series | The history drawn as a line behind the content | none |
| trendLine | Shows the line | true with two or more numbers |
| trendLineFill | The soft wash under the line | true |
| animateTrendLine | Grows in and morphs to each new series | true |
| surface | raised, outline or filled | raised |
| backdrop | A decorative layer above the fill and behind the text, such as a background Sparkline | none |
| onPress | Makes the card one button | none (static) |
| footer | Your own controls under the content | none |
| haptics | A light tap when pressed | true |
With a standalone sparkline
Pass Sparkline through the existing sparkline slot with decorative enabled to show it under the description. The metric card already announces its title, value, trend and description.
To run the trend behind the number instead, pass it to backdrop. The backdrop sits above the card fill and behind the text, so it stays visible with the Glass material, and it is clipped to the card's corners:
<MetricCard
title="Active users"
value={130}
change="+8.3%"
trend="up"
description="Over the last 7 days"
backdrop={
<View className="opacity-40">
<Sparkline label="Active users" data={points} area height={164} decorative />
</View>
}
/>Behavior and gestures
- Use surfaceBackground to place the Pro Glass material below the trend line.
- Static by default, so it's safe inside scroll views and grids. With onPress the whole card is one button that presses in with a light haptic.
- A numeric value counts from the previous value to the new one on the number role when it changes, for example when a range control below the card switches 7D to 90D. animateValue={false} swaps at once; strings always swap at once.
- series draws the metric's history as a line behind everything, edge to edge: oldest at the start, newest at the end, lowest near the bottom and highest near the top, tinted by trend with a soft wash under it. Pass a new range's numbers and the line morphs to them with the value's count. trendLine={false}, trendLineFill={false} and animateTrendLine={false} switch each part off.
- change shows as a chip at the top end, tinted by trend: green for up, red for down and grey for neutral. chip={false} hides it.
- surface picks raised (the default), outline or filled. footer holds your own controls under the card's content, such as a View report button.
- disabled dims the card and ignores presses; haptics={false} turns off the tap.
Accessibility
- The card is read as one element: the title, the value, the change with its trend word and the description, for example "Quarterly active users, 21,870, down 2.1%, Compared with the last 90 days".
- The trend word comes from trendLabels (up, down) and the change's leading sign is dropped after it; trend colour is never the only signal.
- A counting value is announced as its final number, never the frames in between.
- The trend line is decorative and hidden from screen readers; the change and description say what it shows. It drops its wash under Reduce Transparency and mirrors in right-to-left layouts so time runs toward the reading end.
- The sparkline is decorative and hidden; with a footer, the details stay one element and the footer's buttons keep their own focus.
- Text follows Dynamic Type; the title wraps beside the chip and the chip stays at the end in right-to-left layouts.
Motion
- Uses the
numberandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - A numeric value counts to its new number on the number role, interrupted cleanly if it changes again mid-count.
- The trend line grows up from the bottom when it first appears and morphs from its current shape to each new series on the number role, so it moves in step with the count; a morph can be interrupted mid-way.
- With onPress the card scales on the press role.
- Under Reduce Motion, or with the none feel, the new value and line appear at once and the card doesn't scale.
Performance
- The count and the trend line run on the UI thread (Animated counter and two animated SVG paths); every series is resampled to 48 points, so long histories stay cheap. React renders only when props change.
Notes for AI
- Pass value as a number to get the count and locale grouping (precision, locale), or as a preformatted string such as "$1.2M".
- Pass series as the range's history, oldest first, one number per day or bucket; it doesn't need to match the value's units exactly, only its shape. A spread under 2% of the average is drawn near-flat on purpose.
- Format change yourself, including its sign, such as "−2.1%", and set trend explicitly; it's never inferred.
- Put range controls such as a 7D / 30D / 90D segmented control below the card, not inside it, and update value, change, trend and description together.
- Migrating from 1.x: label is now title, trend positive / negative are now up / down, and the Card variants are now surface.
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.