Using MUI 5, I'm looking to use ThemeProvider and createTheme to set the font-family and color palette across all MUI components used.
I'm using this installation of mui:
npm install @mui/material @mui/styled-engine-sc styled-components
Using the Typography component, this did not work:
import { createTheme, ThemeProvider } from '@mui/material/styles';
const theme = createTheme({
typography: {
fontFamily: myFontFamily,
},
})
const MyComponent = () => (
<ThemeProvider theme={theme}>
<Typography>Hello, World</Typography>
</ThemeProvider>
)
while this did work:
const theme = createTheme({
typography: {
fontFamily: myFontFamily,
},
components: {
MuiTypography: {
defaultProps: {
fontFamily: myFontFamily,
},
},
},
});
Similarly, trying to globally override the background color of Chip, for example, setting theme.palette.primary did not get applied to <Chip color="primary" />.
const theme = createTheme({
palette: {
primary: {
main: myHexColor,
},
},
})
const MyComponent = () => (
<ThemeProvider theme={theme}>
<Chip label="Hello, World" color="primary" />
</ThemeProvider>
)
I am struggling to find a way to globally override these styles without having to apply them to every component and component variant we want to use. Is it possible to do this?