material-ui - 在深色/浅色样式覆盖之间切换
问题描述
我想覆盖一些基于theme.type
原生的图标的颜色PaletteColor
。我可以type
像这样检查并有条件地设置颜色:
const useStyles = makeStyles((theme: Theme) =>
createStyles({
someIcon: {
color:
theme.palette.type === "dark"
? theme.palette.warning.dark
: theme.palette.warning.light,
},
})
);
每次我想覆盖某些东西时,这都非常冗长,因此可以将其重构为themeColor
以下内容:
const themeColor = (theme: Theme, color: PaletteColor) =>
theme.palette.type === "dark"
? color.dark
: color.light;
const useStyles = makeStyles((theme: Theme) =>
createStyles({
someIcon: {
color: themeColor(theme, theme.palette.warning)
},
})
);
现在让我想,Material-UI 是否有一些已经这样做的本机助手?
解决方案
推荐阅读
- excel - 是否有一个 Excel 公式可以在组内提供第 n 次出现
- python - 在线性数组openCV python livestream中查找特定像素
- kubernetes - 使用接入点时 EFS-CSI 无法挂载路径
- racket - 在球拍中使用三个参数实现reduce过程:函数、基数和列表
- server-side-rendering - svelte svelte-adapter-firebase 功能设置
- flutter - 尝试从文档中读取字段时,Future 返回 null
- c# - C# - MVC - 将类库项目引用到主项目的问题
- html - 图像右放置
- apache-spark - 在 PySpark 中将完整文件路径转换为多行父级绝对路径
- haskell - haskell如何打破头部功能模式中的列表