Skip to content
Nacre
Color palette
中文

StatCard

stableStatCardOpen in playground
StatCard
Runs the real component in your browser.

One metric on a dashboard: title, value, change, and secondary metrics below a divider. It can be pressable and selected (press a card to switch the trend chart’s metric). Place it on plane.

Status: stable · Components: StatCard

import { StatCard } from 'nacre'
import { View } from 'nsh'
import { StatCard, TOUCH } from 'nacre'
export function StatCardUsage() {
return (
<View class="gap-3" classList={{ 'px-4': TOUCH, 'flex-row p-[21px] rounded-xl bg-plane': !TOUCH }}>
<StatCard title="Chats handled" value="1,284" delta={{ label: '+5.0% vs. yesterday', trend: 'up', tone: 'good' }} />
<StatCard title="Avg. response time" value="38s" delta={{ label: '+12.0% vs. yesterday', trend: 'up', tone: 'bad' }} />
</View>
)
}

help puts a question-mark explanation next to the title; the caller formats delta’s label, trend is the direction and tone is good or bad (the caller flips it for lower-is-better metrics); extra holds the secondary metrics below the divider, which can also carry help.

import { View } from 'nsh'
import { StatCard, TOUCH } from 'nacre'
export function StatCardDetail() {
return (
<View class="gap-3" classList={{ 'px-4': TOUCH, 'flex-row p-[21px] rounded-xl bg-plane': !TOUCH }}>
<StatCard
title="Chats handled"
help="Chats accepted today"
value="1,284"
delta={{ label: '+5.0% vs. yesterday', trend: 'up', tone: 'good' }}
extra={[
{ label: 'Handled by agents', value: '932', help: 'Handled by an agent after transfer to a human' },
{ label: 'Handled by bot', value: '352' },
]}
/>
<StatCard
title="Avg. queue time"
value="1m 12s"
delta={{ label: '-8.0% vs. yesterday', trend: 'down', tone: 'good' }}
extra={[
{ label: 'Longest wait', value: '6m 40s' },
{ label: 'Abandoned', value: '17' },
]}
/>
</View>
)
}

With onPress the card is a button: a faint border on hover, a slightly stronger border on press (no scaling), and a 1pt foreground border on the selected card.

Phone: With onPress it is a button: the outline darkens on press (no scaling), and the selected card gets a 1 pt foreground outline.

import { View, signal } from 'nsh'
import { StatCard, TOUCH } from 'nacre'
export function StatCardSelectable() {
const metric = signal('sessions')
return (
<View class="gap-3" classList={{ 'px-4': TOUCH, 'flex-row p-[21px] rounded-xl bg-plane': !TOUCH }}>
<StatCard title="Chats handled" value="1,284" selected={metric() === 'sessions'} onPress={() => metric.set('sessions')} />
<StatCard title="Avg. response time" value="38s" selected={metric() === 'response'} onPress={() => metric.set('response')} />
<StatCard title="Satisfaction" value="96.2%" selected={metric() === 'csat'} onPress={() => metric.set('csat')} />
</View>
)
}

muted dims the value to the placeholder color, and note gives the reason; without value, the number area is a skeleton. icon gives each card a visual anchor, and the change direction becomes a small arrow next to the number.

import { View } from 'nsh'
import { StatCard, TOUCH } from 'nacre'
export function StatCardStates() {
return (
<View class="gap-3" classList={{ 'px-4': TOUCH, 'flex-row p-[21px] rounded-xl bg-plane': !TOUCH }}>
<StatCard title="First contact resolution" value="– –" muted note="Unavailable under current filters" />
<StatCard title="Satisfaction" />
<StatCard icon="headset" title="Online agents" value="42" delta={{ label: '+3 vs. yesterday', trend: 'up' }} />
</View>
)
}
Key Action
Tab Focus a pressable card (with onPress) and the help question mark
Space / Return Press the card (toggle selection)
  • The accessible name is “title value”; a pressable card has role button, and selected announces the selected state.
  • Color alone doesn’t say whether a change is good: write the full direction and amount in delta’s label (“+5.0% vs. yesterday”).

Do

  • Place it on plane
  • Let the metric’s direction decide whether a change is good (tone)
  • Give cards in a row the same structure (all with or all without secondary metrics)

Don’t

  • Place it directly on a white background
  • Put long text or charts in the card (use viz for sparklines)

Property descriptions follow the Chinese source comments.

Prop Type Default Description
title * string —
value string — 已格式化的值;加载中不给
help string —
delta StatDelta —
extra StatExtra[] —
muted boolean — 值是空占位(– / – –)
note string —
icon IconName — 标题前的着色小图标块(看板指标卡;照参考稿:图标给每张卡一个视觉锚点)
viz JSX.Element — 右上的迷你图(如近期趋势的小柱),有它时不画趋势方块
selected boolean — 可点的卡(留言记录的状态切换):当前项 selected
onPress () => void —
testID string —

* required