tremor-design-system
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTremor Design System
Tremor设计系统
Build production-grade dashboards and analytics interfaces using Tremor's React component library.
使用Tremor的React组件库构建生产级别的仪表盘和分析界面。
Version Detection
版本检测
Tremor has two distribution models. Detect which the user's project uses before writing code:
-
Tremor Raw (tremor.so) — Copy-and-paste components into
src/components/- Imports:
import { AreaChart } from "@/components/AreaChart" - Requires: Tailwind CSS v4+, Radix UI, Recharts
- Styling: Standard Tailwind utility classes
- Imports:
-
Tremor NPM (npm.tremor.so) — NPM package
@tremor/react- Imports:
import { AreaChart, Card } from "@tremor/react" - Requires: Tailwind CSS v3.4+, Headless UI, Remix Icons
- Styling: Tremor-specific tokens (,
text-tremor-content)dark:text-dark-tremor-content
- Imports:
If unclear, ask the user. Default to Tremor Raw for new projects, as it is the actively developed version (acquired by Vercel in Jan 2025).
Tremor有两种分发模式。在编写代码前,请先检测用户项目使用的版本:
-
Tremor Raw(tremor.so)—— 将组件复制粘贴到目录
src/components/- 导入方式:
import { AreaChart } from "@/components/AreaChart" - 依赖要求:Tailwind CSS v4+、Radix UI、Recharts
- 样式:使用标准Tailwind工具类
- 导入方式:
-
Tremor NPM(npm.tremor.so)—— NPM包
@tremor/react- 导入方式:
import { AreaChart, Card } from "@tremor/react" - 依赖要求:Tailwind CSS v3.4+、Headless UI、Remix Icons
- 样式:使用Tremor专属令牌(、
text-tremor-content)dark:text-dark-tremor-content
- 导入方式:
若不确定,请询问用户。对于新项目默认使用Tremor Raw,因为它是目前仍在积极开发的版本(2025年1月被Vercel收购)。
Workflow
工作流程
- Determine version — Check imports, , or ask
package.json - Identify pattern — See references/dashboard-patterns.md for common layouts (KPI rows, chart sections, filtered tables, full dashboards)
- Select components — See references/component-catalog.md for the full component API
- Compose — Assemble using the patterns below
- Style — Apply Tailwind utilities consistent with the detected version
- 确定版本 —— 检查导入语句、,或询问用户
package.json - 识别模式 —— 查看references/dashboard-patterns.md获取常见布局(KPI行、图表区域、筛选表格、完整仪表盘)
- 选择组件 —— 查看references/component-catalog.md获取完整组件API
- 组合组件 —— 按照以下模式组装
- 样式设置 —— 根据检测到的版本应用一致的Tailwind工具类
Key Principles
核心原则
- Card is the atom: Almost every dashboard section wraps in . KPIs, charts, tables, and forms all sit inside cards.
<Card> - Grid layout: Use Tailwind grid () for responsive dashboard layouts. Never hardcode widths.
grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 - Data shape convention: All chart components expect an array of objects. The prop selects the x-axis key;
indexselects the data series.categories - valueFormatter: Always provide a for charts displaying currency, percentages, or units. Use
valueFormatterfor numbers.Intl.NumberFormat - Dark mode: All components support dark mode. For Tremor Raw, use standard prefixes. For NPM, use
dark:tokens.dark-tremor-* - "use client": Chart components use browser APIs (Recharts). In Next.js App Router, mark pages or components containing charts with .
"use client"
- Card是基础单元:几乎所有仪表盘区域都包裹在组件中。KPI、图表、表格和表单都位于卡片内部。
<Card> - 网格布局:使用Tailwind网格()实现响应式仪表盘布局。切勿硬编码宽度。
grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 - 数据格式约定:所有图表组件都期望接收对象数组。属性用于选择x轴的键;
index用于选择数据系列。categories - valueFormatter:对于显示货币、百分比或单位的图表,务必提供。使用
valueFormatter处理数字。Intl.NumberFormat - 深色模式:所有组件都支持深色模式。对于Tremor Raw,使用标准前缀;对于NPM版本,使用
dark:令牌。dark-tremor-* - "use client":图表组件使用浏览器API(Recharts)。在Next.js App Router中,需标记包含图表的页面或组件为。
"use client"
Common Data Shape
通用数据格式
ts
// All charts expect this pattern
const chartdata = [
{ date: "Jan 23", Revenue: 2890, Costs: 2338 },
{ date: "Feb 23", Revenue: 2756, Costs: 2103 },
// ...
]
// index="date" → x-axis
// categories={["Revenue", "Costs"]} → data seriests
// All charts expect this pattern
const chartdata = [
{ date: "Jan 23", Revenue: 2890, Costs: 2338 },
{ date: "Feb 23", Revenue: 2756, Costs: 2103 },
// ...
]
// index="date" → x-axis
// categories={["Revenue", "Costs"]} → data seriesQuick Reference: Chart Selection
快速参考:图表选择
| Use Case | Component |
|---|---|
| Trends over time | |
| Category comparison | |
| Part-of-whole | |
| Rankings | |
| Budget/threshold | |
| Combined metrics | |
| Inline sparkline | |
| Progress toward goal | |
| Uptime/status history | |
| 使用场景 | 组件 |
|---|---|
| 随时间变化的趋势 | |
| 类别对比 | |
| 占比情况 | |
| 排名展示 | |
| 预算/阈值展示 | |
| 组合指标 | |
| 内联迷你图 | |
| 目标进度展示 | |
| 可用性/状态历史 | |
Formatting Conventions
格式化约定
- Use for US number formatting
Intl.NumberFormat("us") - Currency: $${Intl.NumberFormat("us").format(n)}``
(n) => \ - Percentage: ${n}%``
(n) => \ - Compact: ${Intl.NumberFormat("us", { notation: "compact" }).format(n)}``
(n) => \
- 使用实现美国数字格式
Intl.NumberFormat("us") - 货币格式化:$${Intl.NumberFormat("us").format(n)}``
(n) => \ - 百分比格式化:${n}%``
(n) => \ - 紧凑格式:${Intl.NumberFormat("us", { notation: "compact" }).format(n)}``
(n) => \
References
参考资料
- Full component API and props: references/component-catalog.md
- Dashboard composition patterns: references/dashboard-patterns.md
- 完整组件API和属性:references/component-catalog.md
- 仪表盘组合模式:references/dashboard-patterns.md