stylex.props
採用一種 StyleX 樣式或 StyleX 樣式陣列,並傳回屬性物件。數值也可以是 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),
)}
/>;