Layout
KpiCard
A metric card with a title, a value, an optional unit, a trend, an icon and a chart under the number.
<script>
import { KpiCard } from "@codeatlasdev/ui";
import { DollarSign } from "@lucide/svelte";
</script>
<KpiCard title="Monthly Revenue" value="$48,200" trend={12.4} icon={DollarSign} />
A KpiCard is a Stat inside a Card. For a plain number inside a card you already have, with a hint line and no second box, use Stat.
Put several cards in a KpiGrid so a row never ends on an empty cell.
Basic metrics
- Monthly Revenue
- $48,200
- ↑+12.4%
- Active Users
- 3,847
- ↓-2.1%
- Conversion
- 4.8%
- ↑+0.6%
Reference #175 · Pick in the gallery
Code
Without trend
Omit trend and the indicator disappears.
- Orders Today
- 124
- Avg. Session
- 3m 42s
- Error Rate
- 0.03%
Reference #177 · Pick in the gallery
Code
Negative trend
A falling number that is good news: trendTone="positive-down".
- Churn Rate
- 5.2%
- ↓-1.8%
- Response Time
- 1.4s
- ↓-12.3%
Reference #176 · Pick in the gallery
Code
Sparkline
An icon and a recent-history chart in the same tile: the chart snippet takes a Sparkline.
- Active users
- 24.8k
- ↑+12.1%
- Churn
- 1.7%
- ↓-0.2%
- Down from 2.4% in January
Reference #985 · Pick in the gallery
Code
Trend tone
Down is good for churn and latency; a neutral tone shows the change without judging it.
- Churn Rate
- 5.2%
- ↓-1.8%
- Response Time
- 1.4s
- ↑+12.3%
- Sessions
- 3,847
- ↓-2.1%
Reference #984 · Pick in the gallery
Code
trend is a relative percent change (12.4 renders +12.4%), computed by you: a metric that went from 80 to 90 passes 12.5, not 10. By default a rise is green and a fall red. trendTone="positive-down" flips the colour for metrics where down is good (churn, cost, latency); the arrow still follows the sign and the accessible label says “better” or “worse”. trendTone="neutral" judges neither way. Do not omit trend to avoid a wrong colour.
chart is a snippet, usually <Sparkline data={...} /> from @codeatlasdev/ui/charts (it needs the echarts peer). It is not a data prop because the charts subpath stays out of the core entry. The sparkline colour comes from its own trend ("up" is green), independent of trendTone: for a falling churn give the Sparkline trend="up". Do not compose Card + Stat + Sparkline for this tile.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | – | Metric name. |
value | string | number | – | Main value. |
unit | string | – | Unit shown after the value (%, s, users). |
hint | string | – | Secondary caption below the value ("Down from 2.4%"). |
trend | number | – | Percentage change. The arrow follows the sign; by default a rise is green, a fall red, zero neutral. |
trendTone | 'positive-up' | 'positive-down' | 'neutral' | – | Which direction of `trend` is good news. `'positive-down'` makes a fall green (churn, cost, latency); `'neutral'` judges neither. Adds "better" or "worse" to the accessible label. |
icon | IconComponent | – | Lucide icon. Size and color are managed by the card. |
chart | Snippet | – | A chart under the number, usually a `Sparkline` from `@codeatlasdev/ui/charts`. Give it an accessible name when it carries information. |
skeleton | boolean | false | Loading placeholder with the exact size of the loaded card. See Skeleton. |
class | string | '' | Extra class names. |