Display

KpiCard

Display 1–4 metrics in a responsive grid with background sparklines, animated values, delta indicators, and locale-aware formatting.

State

Q4 Performance

October through December 2025

Revenue
$0+12.4%
Active Users
0+8.2%
Churn Rate
0.0%-0.8%
NPS Score
0+5%
Stripe + Analytics· 2 hours ago

Installation

Terminal
npx taw-ui add kpi-card

This copies the component source and schema into your project. You own the code — customize anything.

Usage

server — define tool
import { tool } from "ai"
import { KpiCardSchema } from "@/components/taw/kpi-card"

export const getMetrics = tool({
  description: "Get business metrics",
  parameters: z.object({ metric: z.string() }),
  outputSchema: KpiCardSchema,
  execute: async ({ metric }) => {
    const data = await fetchMetric(metric)
    return {
      id: metric,
      stats: [{
        key: metric,
        label: data.name,
        value: data.value,
        format: { kind: "currency", currency: "USD" },
        diff: { value: data.change },
        sparkline: { data: data.history },
      }],
      source: { label: "Stripe", freshness: "just now" },
    }
  },
})
client — render
import { KpiCard } from "@/components/taw/kpi-card"
import type { TawToolPart } from "taw-ui"

function ToolOutput({ part }: { part: TawToolPart }) {
  // Handles loading, error, and success states
  return <KpiCard part={part} />
}

Examples

The layout adapts automatically based on the number of stats. 1 stat renders as a hero, 2–4 as a 2-column grid.

1 statsingle
88%

Monthly Revenue

Current month to date

Revenue
$142,580+12.4%
Based on partial data — full sync completes tonight
Stripe Dashboard· just now
2 statstwo-stats
95%

Growth Overview

Last 10 months trend

MRR
$48,200+6.3%
Customers
1,284+3.1%
Customer count includes trial accounts that haven't converted yet
Stripe· 10 min ago
3 statsthree-stats
99%

Infrastructure Health

Production cluster metrics

P95 Latency
142-21.1%
Uptime
99.98%+0.01%
Error Rate
0.02%-0.01%
Latency measured at edge, not origin — actual server latency may differ
Datadog· 5 min ago
4 statsready
92%

Q4 Performance

October through December 2025

Revenue
$847,300+12.4%
Active Users
24.9K+8.2%
Churn Rate
2.1%-0.8%
NPS Score
72+5%
NPS data is from a sample of 2,400 respondents, not the full user base
Stripe + Analytics· 2 hours ago

Props

FieldTypeDescription
part*TawToolPartTool call lifecycle state — handles loading, error, and success
animatebooleanEnable spring animations and sparkline draw-in (default: true)
localestringBCP 47 locale for number/currency formatting (e.g. "en-US")
classNamestringAdditional CSS classes on the wrapper

Schema

The tool output shape validated by the component. Invalid data renders a helpful error with field-level suggestions.

KpiCardSchema
FieldTypeDescription
id*stringStable identifier
titlestringCard header title
descriptionstringCard header subtitle
stats*StatItem[]1–4 metric items (see below)
confidencenumber (0-1)AI confidence badge
caveatstringUncertainty note from the AI
sourceSourceData provenance (label + freshness)
StatItem
FieldTypeDescription
key*stringUnique identifier for this stat
label*stringLabel displayed above the value
value*number | stringThe metric value — numbers animate on entrance
formatStatFormatFormatting: currency, number, percent, or text
diffStatDiffDelta indicator with value, decimals, upIsPositive
sparklineStatSparklineBackground trend chart: { data: number[], color?: string }
StatFormat
FieldTypeDescription
kind*"currency" | "number" | "percent" | "text"Format type
currencystringISO currency code (required for currency kind)
decimalsnumberDecimal places
compactbooleanCompact notation for large numbers (number kind)
basis"unit" | "fraction"Whether value is already a percentage or 0–1 (percent kind)

Features

Spring-animated numbers

Values count up using spring physics, not linear interpolation

Background sparklines

Full-bleed SVG area charts with draw-in animation and hover reveal

Delta indicators

Color-coded badges with configurable upIsPositive for metrics like churn

Format options

Currency, percent, number, text — locale-aware with compact notation

Adaptive layout

1 stat = hero mode, 2–4 = 2-column grid with subtle dividers

Helpful errors

Parse failures render field-level details with suggestions, never silent null

Related