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
Section titled “Import”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> )}Examples
Section titled “Examples”Help and secondary metrics
Section titled “Help and secondary metrics”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> )}Pressable and selected
Section titled “Pressable and selected”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> )}Empty and loading
Section titled “Empty and loading”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> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | Focus a pressable card (with onPress) and the help question mark |
| Space / Return | Press the card (toggle selection) |
Accessibility
Section titled “Accessibility”- 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 / Don’t
Section titled “Do / Don’t”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.
StatCard
Section titled “StatCard”| 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