Design tokens · Agent

Design tokens

用語義命名的 token,theme 切換只換 value,元件永遠不寫死。

互動示範(與本規範網站人類閱讀版相同):/docs/design-tokens

示範對應規則

以下章節與人類版頁面互動示範所涵蓋的規則一致(文字版,供 Agent 複製)。

A. 語意 token

設計時「選值」用的語意尺度。先在這段挑 token,元件只引用 token,不寫死。

Color

不要寫死顏色#3498DB),用語義 token:

Token用途Light valueDark value
bg-default主要背景#FFFFFF#0F1115
bg-subtle次要背景(卡片、區塊)#F7F8FA#1A1D23
bg-muted更次要的背景#EDF0F4#252830
text-default主要文字#1F2328#E6E8EB
text-muted次要文字#6E7681#A0A6AD
text-subtle三級文字#8B94A0#7A828B
text-on-primary在 primary 底色上的文字#FFFFFF#FFFFFF
border-default一般 border#E1E4E8#363B45
border-emphasis強調 border / divider#D0D7DE#444B57
interactive-primaryPrimary button、link#4F46E5#818CF8
interactive-primary-hoverhover#4338CA#A5B4FC
interactive-secondarySecondary button#6E7681#9CA3AF
status-successSuccess#16A34A#22C55E
status-warningWarning#CA8A04#EAB308
status-errorError / Destructive#DC2626#EF4444
status-infoInfo#4F46E5#818CF8
status-neutralNeutral / muted#6E7681#9CA3AF
semantic-ink文字/segment active#111111#E6E8EB
semantic-sustain永續/碳排(非 primary)#2D5A42#4ADE80
semantic-kraft輔助/圖表 accent#B8956A#C4A882

每個狀態色提供 3 階:

  • subtle(背景 / tag bg):淡色,不刺眼。
  • default(icon、文字、border):標準色。
  • emphasis(強調 button background):深色,對比強。
status-success-subtle: #E6F7EC
status-success-default: #16A34A
status-success-emphasis: #15803D

Typography

TokenSizeWeightLine-height用途
display36 / 487001.1行銷頁標題
heading-124–327001.2Page title
heading-2206001.3Section title
heading-3166001.4Section / 小卡標題
widget-title186001.3儀表板/後台白卡標題(dashboard widget)
body-large164001.5重要正文、詳情頁內文
body / ui-small144001.5預設正文、KPI 列名、可讀副標
body-small134001.5次要正文
detail-data206001.2詳情 aside 大數值
caption124001.4麵包屑、表頭 uppercase、meta(不可當 KPI 列名)
code134001.5等寬字

Dashboard 字級必守

  1. 儀表板/後台白卡標題必須 18pxwidget-title)。禁止body(14px)或 caption(12px)當 widget 主標題。
  2. 需使用者閱讀的「小字」必須 14pxui-small / body)。禁止把 KPI 列名、widget 副標設成 caption
  3. 12px(caption)僅用於麵包屑、表格欄位表頭(uppercase)、時間戳、hint 等不需長時間閱讀的 meta。
  4. 示範常數:GUIDE_WIDGET_TITLEGUIDE_KPI_LABEL(見 guide-dashboard-styles.ts)。
  • Line-height:Body 1.5、Heading 1.2–1.3、Code 1.5。
  • Letter spacing:大標題微負 -0.02em;全大寫小字(標籤)+0.05em。
  • Font family · Sans:System default 優先(San Francisco / Segoe UI / Roboto / -apple-system)→ Inter / Helvetica → sans-serif。
  • Font family · Mono:SF Mono / Menlo / Consolas / monospace。
  • Font family · 中文:PingFang TC / Noto Sans TC / 微軟正黑體。
  • 本指南網站字體Internext/font + --font-inter)。

Spacing

space-1  = 4px
space-2  = 8px
space-3  = 12px
space-4  = 16px
space-5  = 24px
space-6  = 32px
space-7  = 48px
space-8  = 64px

使用慣例:

  • icon ↔ text:8–12(space-2/3)。
  • input ↔ input 同欄:12–16(space-3/4)。
  • 同 section 內群組間距:16–24(space-4/5)。
  • section ↔ section:24–32(space-5/6)。
  • page padding(內邊距):24–32(space-5/6)。
  • card padding:16–24(space-4/5)。
  • button padding:水平 12–16、垂直 6–10。

Border Radius

radius-none = 0
radius-sm   = 4px     input、small card
radius-md   = 8px     card、modal、button
radius-lg   = 12px    large card
radius-xl   = 16px    feature card
radius-full = 9999px  pill、avatar

Icon System

icon-xs  = 12px   小 status dot 旁
icon-sm  = 16px   表格 row、inline
icon-md  = 20px   按鈕、nav item(常用)
icon-lg  = 24px   page header、空狀態
icon-xl  = 32px   feature highlight
icon-2xl = 48px+  empty state 插圖
  • Stroke / style:Outlined stroke 1.5–2px(跨 size 一致粗細);Filled 用在 active / selected 狀態;同產品不混 outline 跟 filled(除非有設計理由)。
  • Icon size 對應 text:16 / 20 icon → 配 14 / 16 body text;24 / 32 icon → 配標題或獨立使用。
  • 禁止:用 emoji(🎨 🔔 ✓ 等)作為導覽、按鈕、狀態、空狀態的結構性圖示
  • 必須:SVG 向量圖示(currentColor、固定 stroke 粗細);本指南網站示範使用 Untitled UI Icons@untitledui/icons)。
  • 推薦:Lucide / Heroicons / Phosphor / Tabler(outline-based);Material Symbols;Carbon / Atlassian / Polaris 官方 set。

Shadow / Elevation

shadow-xs : 0 1px 2px rgb(15 23 42 / 0.05)
shadow-sm : 0 1px 3px + 0 1px 2px -1px(卡片、示範框)
shadow-md : 0 4px 12px -2px(dropdown)
shadow-lg : 0 12px 28px -6px(modal、popover)
  • Light mode 用陰影;Dark mode 提高 opacity(見 styles/globals.css)。
  • Dark mode 亦可用「越高越亮」(surface tone)輔助層次(見 20-dark-mode-i18n.md)。

Z-index

由低到高(與 01-layout.md 同步):

z-base     = 0
z-sticky   = 100
z-dropdown = 1000
z-drawer   = 1100
z-modal    = 1200
z-toast    = 1300
z-tooltip  = 1400

Motion / Duration

duration-fast   = 150ms  hover、focus、按鈕
duration-base   = 220ms  開合 dropdown、tab 切換
duration-slow   = 300ms  modal、drawer
duration-slower = 500ms  page transition
  • Easing:ease-out 進場(cubic-bezier(0, 0, 0.2, 1))、ease-in 離場(cubic-bezier(0.4, 0, 1, 1))、ease-in-out 雙向。
  • 本指南網站:--duration-fast: 150ms--ease-standard: cubic-bezier(0.2, 0, 0, 1)
  • 須支援 prefers-reduced-motion(關閉非必要動效)。

延伸與補充

B. 套用:把語意 token 接到實作

A 段是「規範層」(要選哪些值);這段是「落地模式」(怎麼接到產品)。各產品把語意 token 綁到自己的 CSS 變數或 design-token 系統,變數命名隨產品慣例,元件只引用變數/utility,勿寫死色碼

Binding pattern(與框架無關)

  1. 定義:每個語意 token 建一個 CSS 變數,light / dark 各給值。
  2. 綁定:元件用 var() 或 utility 引用,不寫死 hex。
  3. 切主題:只換變數值,元件一行不動。

通用範例(變數名換成你產品的命名):

:root {
  --color-interactive-primary: #4f46e5; /* = 語意 interactive-primary */
  --color-text-default: #1f2328; /* = 語意 text-default */
}
[data-theme="dark"] {
  --color-interactive-primary: #818cf8;
  --color-text-default: #e6e8eb;
}
<!-- Tailwind 任意值;其他框架用 var() 同理 -->
<button class="bg-[var(--color-interactive-primary)] text-[var(--color-on-primary)]">Save</button>

底色 ↔ 文字配對(通用規則)

選前景色看「底是什麼」,不是沿用 body 預設灰階:

  • 品牌/飽和底色 → 用 text-on-primary(高對比白/淺),沿用 body 灰階字色。
  • 淺色品牌底(如 brand-subtle)→ 用品牌色系文字,用一般 text-muted 灰階。
  • 白底/一般 surface → 用標準文字灰階系(text-default / text-muted)。
  • 浮層(dropdown / popover)在帶色容器內展開時,須重設自身前景/背景,切斷父層色繼承。