跳至主要内容

stylex.props

接收一个 StyleX 样式或 StyleX 样式数组,并返回一个 props 对象。值也可以是 nullundefinedfalse

返回值应该应用到元素上以直接应用样式。

对于 Solid、Svelte、Qwik、Vue 和其他框架:stylex.attrs

对于期望使用 class 而不是 className 的框架,请使用 style.attrs。使用方法与 stylex.props 完全相同。

function props(styles: StyleXStyles | StyleXStyles[]): {
className: string;
style: {[key: string]: string};
};

示例用法:

import * as stylex from '@stylexjs/stylex';

const styles = stylex.create({
root: {
backgroundColor: 'red',
padding: '1rem',
paddingInlineStart: '2rem',
},
conditional: {
backgroundColor: 'blue',
},
dynamic: (opacity) => ({
opacity,
}),
});

<div
{...stylex.props(
styles.root,
condition && styles.conditional,
props.style,
styles.dynamic(state.opacity),
)}
/>;