Skip to content

pantoken / design/swatches/src / toSwatches

函式: toSwatches()

toSwatches(tokens, mode?): Swatch[]

實驗性

將 token IR 縮減為平面色票列表:解析參照,選擇模式,僅保留值為十六進位顏色的 tokens(圖示與非顏色 tokens 會被移除)。

參數

tokens

唯讀 Token[]

IR(例如來自 @pantoken/tokens)。

mode?

Mode = "light"

要解析為哪種顏色模式(預設為 "light")。

回傳

Swatch[]

色票列表,名稱由 token 指定(不含 --instui- 前綴)。

範例

將 token IR 縮減為淺色模式色票

ts
import { toSwatches } from "@pantoken/swatches";
import { tokens } from "@pantoken/tokens";

const swatches = toSwatches(tokens); // [{ name: "color-background-brand", hex: "#…" }, …]

深色模式

ts
import { toSwatches } from "@pantoken/swatches";
import { byTheme } from "@pantoken/tokens";

const swatches = toSwatches(byTheme("canvas"), "dark");