跳至主要内容

stylex.createTheme

接收使用 defineVars() 创建的变量集,以及用于覆盖这些变量值的 对象。它返回一个 StyleXStyles 对象,该对象可以传递给 props() 以将主题应用于元素根。

function createTheme(
vars: Vars,
overrides: {
[key: keyof Vars]: string;
},
): StyleXStyles;

示例用法:

import * as stylex from '@stylexjs/stylex';
import { colors } from './vars.stylex.js';

const theme = stylex.createTheme(colors, {
accentColor: 'red',
backgroundColor: 'gray',
lineColor: 'purple',
textPrimaryColor: 'black',
textSecondaryColor: 'brown',
});

function App() {
return (
<div {...stylex.props(theme /* , ... */)}>
<ContentToBeThemed />
</div>
);
}