I'm attempting to use two personal fonts in Material Ui 5.0 at the moment. I'd like to apply them globally by overwriting the theme.
My first issue is that I can't get the fonts to even load properly, and I can't change the typography at all.
Furthermore, with MUI 5.0, I am unable to have this custom font applied to the full body section.
So if use <Typography variant='h4'>. or <Box>...</Box> my custom fonts are not applying.
They way I did the global overwrite in Mui 4.0 is not working anymore in version 5.
I'm very annoyed because the MUI 5.0 documentation does not properly or at all explain this, and I have been sitting there for hours.
I would appreciate any help !
I am using React, Typescript.
font.d.ts
declare module '*.woff'
declare module '*.ttf'
cssBaseLine.ts
import CustomOneMediumWoff from '../fonts/CustomOne-Medium.woff'
import CustomOneTwomWoff from '../fonts/CustomOne-Twom.woff'
export const CssBaseline = {
MuiCssBaseline: {
// '@global': {
// html: {
// fontFamily: 'CustomOneTwomWoff',
// height: '100%',
// overflow: 'auto',
// },
// body: {
// fontFamily: 'CustomOneTwomWoff',
// height: '100%',
// overflow: 'auto',
// },
// '#root': {
// height: '100%',
// overflow: 'auto',
// },
// },
// I did that in MUI 4.0 and it does not work anymore
// Tho documentation is not explaining the global overwirte part anymore
styleOverrides: `
@font-face {
font-family: "CustomOne";
url(${CustomOneMediumWoff}) format("woff"),
font-weight: 500;
font-style: normal;
},
@font-face {
font-family: "CustomTwo";
url(${CustomTwoMediumWoff}) format("woff"),
font-weight: 500;
font-style: normal;
},
`,
},
}
export default CssBaseline
typography.ts fonts are not applying
export const typography = {
fontFamily: ['CustomOne', 'CustomtTwo'].join(','),
h1: {
fontFamily: 'CustomOne',
fontWeight: 500,
},
h2: {
fontFamily: 'CustomOne',
},
h3: {
fontFamily: 'CustomOne',
},
h4: {
fontFamily: 'CustomOne',
},
button: {
fontFamily: 'CustomtTwo',
},
}
export default typography
theme.ts
export const theme = createTheme({
palette:palette,
typography: typography,
components: {
...CssBaseline,
},
})
export default theme
Does not work and default browser fonts are loaded
<Typography variant='h4'>Test 4</Typography>
<Box mt={4}>test Boxssssss H</Box>
App.tsx
<ThemeProvider theme={theme}>
<CssBaseline />
....