【发布时间】:2021-11-13 19:17:24
【问题描述】:
我想使用自定义调色板,以便我的网站在所有组件中使用品牌颜色。我希望能够在全球范围内访问这些自定义颜色,包括在 makeStyles 中。
这是我的主题文件:
import { createMuiTheme } from '@material-ui/core/styles';
const theme = createMuiTheme({
palette: {
primary: {
main: '#467f0f'
},
},
});
export default theme;
这是我的组件:
import theme from './theme';
const useStyles = makeStyles(theme => ({
title: {
backgroundColor: theme.palette.common.white,
borderColor: theme.palette.primary.main,
borderRadius: theme.spacing(2),
borderStyle: 'solid',
borderWidth: theme.spacing(1),
color: theme.palette.primary.main,
fontSize: theme.spacing(4),
margin: theme.spacing(2, 'auto'),
padding: theme.spacing(1),
textAlign: 'center',
[theme.breakpoints.up('sm')]: {
fontSize: theme.spacing(8),
},
},
}));
function App(): JSX.Element {
const classes = useStyles();
return (
<ThemeProvider theme={theme}>
<Typography
className={classes.title}
variant='h1'
>
My App
</Typography>
</ThemeProvider>
);
}
export default App;
没有抛出错误或 linter 警告或任何东西。但是我的自定义调色板中的颜色没有被使用。在此过程中我可能错过了什么?
【问题讨论】:
标签: material-ui themes