javascript - 将主题插入到 styled() 方法中
问题描述
我在材质 ui 上遇到了这个示例,可以在其中插入theme
对象并利用theme
来自的所有属性styled-component
。
但是,当我尝试使用styled()
来自material-ui/core/styles
包的方法时,我无法让它工作。
有人可以解释如何使以下示例与来自@material-ui/core/styles
package 的 styled() 方法一起工作吗?
例子
const StyledButton = styled(Button)`
${({ theme }) => `
background-color: ${theme.palette.primary.main};
color: #fff;
box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
padding: 4px 10px;
font-size: 13px;
&:hover {
background-color: ${darken(theme.palette.primary.main, 0.2)};
}
${theme.breakpoints.up('sm')} {
font-size: 14px;
padding: 7px 14px;
}
`}
`;
解决方案
推荐阅读
- r - 如何使用传播/枢轴或重塑来转换分层数据框
- python - 如何将字符串的每个其他字母向左移动一个?
- reactjs - StackNavigator 的 goBack 与嵌套的 BottomTabNavigator
- performance - 使用 LINQ 代替 foreach
- azure - 如何为 linux 诊断设置 azurerm_virtual_machine_extension
- python - 如何不允许用户从私人电报频道转发消息
- python - 是否可以为行为中的单个场景设置“before_all”?
- reactjs - 我在 mapStateToProps 和 render 方法中没有正确重做的错误是什么?以及要解决什么问题?
- javascript - React Router Switch 路由不匹配
- r - 如何更改多列中的数值?