使用emotion
(https://github.com/emotion-js/emotion)我知道我可以使用以下内容进行主题css
化styled
:
const carouselCss = ({ theme }) => css`
.. css properties etc
`;
const CarouselDiv = styled('div')`
${carouselCss};
`;
然后在 JSX 中:
<ThemeProvider theme={{ stuff: 'blah' }}>
<CarouselDiv>
..
</CarouselDiv>
</ThemeProvider>
但是有没有什么优雅的方式来主题化css
- 不喜欢使用组件styles
化,因为我想保留 JSX 中的语义 html 元素(也有大量的代码库,并且更容易从 sass 迁移到情感而无需使用styled
)
我知道我可以做类似的事情:
const carouselCss = (theme) => css`
.. css properties etc
`;
然后jsx:
<div className={carouselCss(this.props.theme)}>
..
</div>
但这意味着一直从组件传递一个主题道具——这有点麻烦
有一个更好的方法吗 ?以某种方式包装css
一些东西,以便注入主题变量?