Skip to content

pantoken-root / design/swatches/src / toSwatches

函数: toSwatches() ​

toSwatches(tokens, mode?): Swatch[]

实验性

将代币 IR 缩减为平面颜色样本列表:解析引用,选择模式,仅保留 值为十六进制颜色的代币(图标和非颜色代币将被丢弃)。

参数 ​

tokens ​

只读 Token[]

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

mode? ​

Mode = "light"

要解析为哪种颜色模式(默认 "light")。

返回值 ​

Swatch[]

样本列表,按代币命名(不含 --instui- 前缀)。

示例 ​

将代币 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");