如何使用样式化的组件创建上下文样式? (零选择器)

时间:2018-11-21 20:15:13

标签: css reactjs react-native styled-components

我想知道是否可以在没有任何CSS选择器的情况下创建上下文样式。

类似的东西:

<Button primary>
    <Text>BUTTON</Text> // if the button is primary then have 20px padding else 0
    <Icon/> // if the button is primary then have red background
</Button>

我实际上不想使用CSS的原因是,我想在React Native(您没有任何选择器或CSS)中共享我的组件

1 个答案:

答案 0 :(得分:0)

CSS是必经之路。不知道为什么您不想使用它。

button {
    padding: 0;
}

button[primary] {
    padding: 20px;
}

button[primary] icon {
    background-color: red;
}

如果您不想使用CSS,也许可以指定您的原因,我也许可以改善我的答案。