Skip to content

pantoken / renderers/css-in-js/src / toStyledTheme

函数: toStyledTheme()

toStyledTheme(tokens, options?): StyledTheme

实验性

从令牌 IR 构建一个 CSS-in-JS 主题对象。

参数

tokens

只读 Token[]

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

options?

ToStyledThemeOptions = {}

ToStyledThemeOptions.

返回值

StyledTheme

主题对象,键为 camelCased 令牌名称。

示例

由 var() 支持的亮/暗模式流通过 @pantoken/css

ts
import { toStyledTheme } from "@pantoken/css-in-js";
import { tokens } from "@pantoken/tokens";

const theme = toStyledTheme(tokens);
// theme.colorBackgroundBrand → "var(--instui-color-background-brand)"

烘焙具体的单模式值(用于在没有 CSS 变量 的 SSR 中)

ts
import { toStyledTheme } from "@pantoken/css-in-js";
import { tokens } from "@pantoken/tokens";

const dark = toStyledTheme(tokens, { resolve: "dark" });
// dark.colorBackgroundBase → a concrete value, not a var()