stylex.props
接收一个 StyleX 样式或 StyleX 样式数组,并返回一个 props 对象。值也可以是 null
、undefined
或 false
。
返回值应该应用到元素上以直接应用样式。
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),
)}
/>;