Skip to content

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.

#175

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
svelte
<script lang="ts">
  import { KpiCard, KpiGrid } from '@codeatlasdev/ui';
  import { Users, DollarSign, TrendingUp } from '@lucide/svelte';
</script>

<KpiGrid>
  <KpiCard title="Monthly Revenue" value="$48,200" trend={12.4} icon={DollarSign} />
  <KpiCard title="Active Users" value="3,847" trend={-2.1} icon={Users} />
  <KpiCard title="Conversion" value="4.8" unit="%" trend={0.6} icon={TrendingUp} />
</KpiGrid>
#177

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
svelte
<script lang="ts">
  import { KpiCard, KpiGrid } from '@codeatlasdev/ui';
  import { ShoppingCart } from '@lucide/svelte';
</script>

<KpiGrid>
  <KpiCard title="Orders Today" value="124" icon={ShoppingCart} />
  <KpiCard title="Avg. Session" value="3m 42s" />
  <KpiCard title="Error Rate" value="0.03" unit="%" />
</KpiGrid>
#176

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
svelte
<script lang="ts">
  import { KpiCard, KpiGrid } from '@codeatlasdev/ui';
  import { Activity } from '@lucide/svelte';
</script>

<KpiGrid>
  <KpiCard title="Churn Rate" value="5.2" unit="%" trend={-1.8} trendTone="positive-down" icon={Activity} />
  <KpiCard title="Response Time" value="1.4" unit="s" trend={-12.3} trendTone="positive-down" />
</KpiGrid>
#985

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
svelte
<script lang="ts">
  import { KpiCard, KpiGrid } from '@codeatlasdev/ui';
  import { Sparkline } from '@codeatlasdev/ui/charts';
  import { UserMinus, Users } from '@lucide/svelte';
</script>

<KpiGrid>
  <KpiCard title="Active users" value="24.8k" trend={12.1} icon={Users}>
    {#snippet chart()}<Sparkline data={[18, 19, 21, 20, 23, 25]} trend="up" />{/snippet}
  </KpiCard>
  <KpiCard title="Churn" value="1.7" unit="%" trend={-0.2} trendTone="positive-down" hint="Down from 2.4% in January" icon={UserMinus}>
    {#snippet chart()}<Sparkline data={[2.4, 2.3, 2.1, 2.2, 1.9, 1.7]} trend="up" variant="bar" />{/snippet}
  </KpiCard>
</KpiGrid>
#984

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
svelte
<script lang="ts">
  import { KpiCard, KpiGrid } from '@codeatlasdev/ui';
  import { Activity, Gauge, UserMinus } from '@lucide/svelte';
</script>

<KpiGrid>
  <KpiCard title="Churn Rate" value="5.2" unit="%" trend={-1.8} trendTone="positive-down" icon={UserMinus} />
  <KpiCard title="Response Time" value="1.4" unit="s" trend={12.3} trendTone="positive-down" icon={Gauge} />
  <KpiCard title="Sessions" value="3,847" trend={-2.1} trendTone="neutral" icon={Activity} />
</KpiGrid>

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

PropTypeDefaultDescription
titlestring–Metric name.
valuestring | number–Main value.
unitstring–Unit shown after the value (%, s, users).
hintstring–Secondary caption below the value ("Down from 2.4%").
trendnumber–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.
iconIconComponent–Lucide icon. Size and color are managed by the card.
chartSnippet–A chart under the number, usually a `Sparkline` from `@codeatlasdev/ui/charts`. Give it an accessible name when it carries information.
skeletonbooleanfalseLoading placeholder with the exact size of the loaded card. See Skeleton.
classstring''Extra class names.