跳到正文
简体中文

用法

import { StatsBand } from './StatsBand.jsx'

// Every period given in data switches at once. Load others on demand with onPeriodChange:
<StatsBand
  locale="en"
  periods={[{ id: '30d', label: '30 days', compare: 'vs previous 30 days' }]}
  data={{ '30d': [{ id: 'teams', label: 'Teams onboarded', value: 1284, change: 12.4, trend: [880, 960, 1120, 1284] }] }}
  loading={!stats}
  onPeriodChange={async (id) => (await fetchStats(id)).items}
/>

属性

属性类型默认值作用
locale'en' | 'zh-CN' | 'es' | 'ja''en'内置文字和数字格式的语言。
periodsArray<{ id, label, compare }>30 days, 90 days, 12 months分段控件里的时间范围;`compare` 是变化值下方的说明。
data{ [periodId]: Array<{ id, label?, value, decimals?, prefix?, suffix?, change?, better?, trend? }> } | Array<…>sample numbers每个时间范围的数字;直接传数组表示只有一个时间范围,不显示切换。`change` 以百分比计;`better: "down"` 表示越低越好。没有数字的时间范围显示空状态。
period / defaultPeriodstringthe first period当前选中的时间范围(受控),或初始选中的范围。
loadingbooleanfalse显示数据卡片的骨架。
onPeriodChange(id) => void | Promise<Array | void>—切换时间范围时调用。`data` 里没有的范围,返回它的数字即可;等待期间卡片会变淡。
productstring'Halden' (sample)产品名称,用在标题下面那句话里。
labelsobject—替换任意内置文字(键名见 copy.js)。
classNamestring—加在根元素 section 上。

装进你的项目

把指令粘贴给 Codex 或 Claude Code。Agent 会读取公开的源码,先告诉你要写入哪些文件,再把区块连同它用到的组件一起加进项目。

StatsBand.jsxstats-band.csscopy.jskit.jsxkit.cssui/rolling-number/ui/empty-state/ui/sparkline/ui/skeleton-shimmer/ui/segmented-control/tokens.cssREADME.md

区块本身、样式和文案、共用的 kit、用到的组件和 tokens.css 会一起装进同一个文件夹。