Skip to content

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

Hàm: toStyledTheme()

toStyledTheme(tokens, options?): StyledTheme

Thử nghiệm

Xây dựng một đối tượng theme CSS-in-JS từ token IR.

Tham số

tokens

chỉ đọc Token[]

IR (ví dụ: từ @pantoken/tokens).

options?

ToStyledThemeOptions = {}

ToStyledThemeOptions.

Trả về

StyledTheme

Đối tượng theme, được đánh khóa bởi tên token ở dạng camelCase.

Các ví dụ

Dựa trên var(), các luồng sáng/tối thông qua @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)"

Sinh trước các giá trị chế độ đơn cụ thể (cho SSR khi không dùng biến CSS)

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()