如何解决Emotion React 主题功能
有没有办法在根主题级别添加到emotion/react
api?我看到 shouldForwardProps
,但在文档中找不到用于修改根 API 的信息。
我有兴趣稍微抽象一下主题对象的形状,例如而不是
const StyledButton = styled(MyButton)`
background: ${props => props.theme.colors.primary};
`
应该是这样的
const StyledButton = styled(MyButton)`
background: ${props => props.getColor('primary')};
`
我尝试按照 the example in the docs
嵌套提供程序
const theme = {
backgroundColor: 'green',color: 'red'
}
const adjustedTheme = ancestorTheme => ({ ...ancestorTheme,getColor: (k) => ancestorTheme.colors[k] })
class Container extends React.Component {
render() {
return (
<ThemeProvider theme={theme}>
<ThemeProvider theme={adjustedTheme}>
<Text>Boom shaka laka!</Text>
</ThemeProvider>
</ThemeProvider>
)
}
}
但是emotion
filters out unrecognized props。
我知道我可以导入一个 util 函数,但想知道是否有某种方法可以在主题本身上做到这一点。欣赏任何见解!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。