SwipeUI

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-card
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.ts and 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 install so versions match your SDK.

Usage

app/dashboard.tsx
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

app/insights.tsx
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}
/>;
app/revenue.tsx
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

PropTypeDefaultDescription
titlestring—

What the number measures, in muted text at the top start.

valuestring | number—

The value. A number is formatted with locale and precision and counts to each new value; a string is shown exactly as you pass it (you format money, units and abbreviations).

change?string—

The change, exactly as it should read in the chip, such as "−2.1%" or "+340".

trend?MetricTrend'neutral'

Which way it moved: tints the chip green, red or grey. Never inferred from a minus sign.

trendLabels?Partial<Record<MetricTrend, string>>{ up: 'up', down: 'down', neutral: '' }

How screen readers hear the trend word before the change. The sign is dropped after a word, so "−2.1%" with down reads "down 2.1%".

description?string—

A muted line under the value, such as "Compared with the last 90 days".

chip?booleantrue when `change` is set

Shows the change as a chip at the top end.

animateValue?booleantrue

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?number0

Decimal places for a numeric value, from 0 to 6.

locale?stringthe device locale

Number locale for a numeric value.

series?readonly number[]—

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?booleantrue when `series` has two or more numbers

Draws the trend line behind the content.

trendLineFill?booleantrue

A soft wash under the trend line, fading toward the bottom. Off under Reduce Transparency.

animateTrendLine?booleantrue

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?ReactNode—

Your own small chart under the description; decorative and hidden from screen readers.

backdrop?ReactNodeundefined

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?ReactNode—

Content under everything else, such as a View report button; it keeps its own focus.

surface?MetricCardSurface'raised'

Surface treatment. raised adds the deeper layered shadow and a hairline.

surfaceBackground?objectundefined

Decorative replacement for the card fill. It receives the card’s bounds.

onPress?((event: GestureResponderEvent) => void)—

Opens the metric's detail. Without it the card is a static surface.

disabled?booleanfalse

Prevents pressing and dims the card.

haptics?booleantrue

A light haptic tap when pressed.

motion?MotionOverridethe app's feel

Motion for the press and the value's count.

accessibilityLabel?stringthe title, value, change and description, joined

What a screen reader announces.

accessibilityHint?string—

Says what pressing does, such as "Opens the users report".

className?string—

Classes merged over the card.

style?StyleProp<ViewStyle>—

Native style escape hatch for the card.

testID?string—

Root identifier; parts add -chip, -value, -description and -trend.

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 label to title and positive / negative to up / down, and replaced Card's variants with surface. See the changelog.

Metric settings

PropDoesDefault
trendup, down or neutral: tints the chipneutral
chipShows the change as a chiptrue with a change
trendLabelsThe trend words screen readers hearup, down
animateValueNumbers count to each new valuetrue
precisionDecimal places for a number0
localeNumber grouping and decimalsthe device locale
seriesThe history drawn as a line behind the contentnone
trendLineShows the linetrue with two or more numbers
trendLineFillThe soft wash under the linetrue
animateTrendLineGrows in and morphs to each new seriestrue
surfaceraised, outline or filledraised
backdropA decorative layer above the fill and behind the text, such as a background Sparklinenone
onPressMakes the card one buttonnone (static)
footerYour own controls under the contentnone
hapticsA light tap when pressedtrue

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 number and press motion roles, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items