【发布时间】:2021-11-04 20:45:04
【问题描述】:
我有一个 MUI 5 按钮变体,我想在其上使用现有的主题调色板颜色。我的appTheme.ts 设置如下:
import { createTheme, Theme } from '@mui/material/styles';
import { alpha } from '@mui/material/styles';
declare module '@mui/material/Button' {
interface ButtonPropsVariantOverrides {
light: true;
}
}
export const theme: Theme = createTheme({
palette: {
primary: {
main: 'black',
light: 'white',
},
secondary: {
main: 'gray',
light: 'white',
},
info: {
main: 'white',
},
warning: {
main: 'red',
},
},
typography: {
fontFamily: 'Lato',
},
components: {
MuiButton: {
variants: [
{
props: { variant: 'light', color: 'primary' },
style: {
textTransform: 'none',
border: 'none',
backgroundColor: 'primary.light',
color: 'primary',
borderRadius: 8,
'&:hover': {
backgroundColor: alpha('primary.main', 0.16),
'&:active': {
backgroundColor: alpha('primary.main', 0.32),
},
},
},
},
],
},
},
});
这有效,除了&:hover 状态属性,它对主题声明一无所知,因此MUI: Unsupported 'primary.main' color. 出错
有没有办法可以在主题声明中使用这样的主题颜色,或者我是否在主题包装级别上覆盖它?我发誓我在某处的一些文档中看到了这个,但找不到它。
【问题讨论】:
标签: javascript reactjs typescript material-ui