stylex.create
接收一个样式对象的映射,并返回一个编译后的 StyleX 样式对象。编译后的 StyleX 样式是一个键值对映射,键对应类名。
function create<T extends {[key: string]: RawStyles | (...any[]) => RawStyles}>(
styles: T,
): {[Key in keyof T]: StyleXStyles<T[Key]>};
使用示例:
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
root: {
backgroundColor: 'red',
padding: '1rem',
paddingInlineStart: '2rem',
},
dynamic: (r, g, b) => ({
color: `rgb(${r}, ${g}, ${b})`,
}),
});