Intro
μλ νμΈμ. μ΄λ² μκ°μλ MUI Typography Component μμ variant μμ±μ 컀μ€ν νλ λ°©λ²μ λν΄ μμλ³΄κ² μ΅λλ€.
MUI Typography variant
Typography μ κΈ°λ³Έ variant μμ±μ λ€μκ³Ό κ°μ΅λλ€. h1, h2, h3, h4, h5, h6, subtitle1, subtitle2, body1, body2 κ° μμ΅λλ€. μ΄ μΈμλ μ§μ 컀μ€ν νμ¬ variantλ₯Ό μΆκ°νκ³ μΆμ λκ° μμ κ²λλ€.
const theme = createTheme({
components: {
MuiTypography: {
defaultProps: {
variantMapping: {
h1: 'h2',
h2: 'h2',
h3: 'h2',
h4: 'h2',
h5: 'h2',
h6: 'h2',
subtitle1: 'h2',
subtitle2: 'h2',
body1: 'span',
body2: 'span',
},
},
},
},
});
How to do
Step 1. Update the theme's typography object
μΆκ°νκ³ μ νλ variant nameκ³Ό μ€νμΌ μμ±μ μΆκ°ν©λλ€.
const theme = createTheme({
typography: {
poster: {
fontSize: '4rem',
color: 'red',
},
// Disable h3 variant
h3: undefined,
},
});
Step 2. (Optional) Set the default semantic element for your new variant
const theme = createTheme({
typography: {
poster: {
fontSize: 64,
color: 'red',
},
// Disable h3 variant
h3: undefined,
},
components: {
MuiTypography: {
defaultProps: {
variantMapping: {
// Map the new variant to render a <h1> by default
poster: 'h1',
},
},
},
},
});
Step 3. Update the necessary typings (if you are using TypeScript)
νμ μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νλ€λ©΄, μλμ μ μΈμ κΌ μΆκ°ν΄μ€μΌ ν©λλ€. μΆκ° μνλ©΄ μ€λ₯κ° λλλΌκ³ μ.
declare module '@mui/material/styles' {
interface TypographyVariants {
poster: React.CSSProperties;
}
// allow configuration using `createTheme`
interface TypographyVariantsOptions {
poster?: React.CSSProperties;
}
}
// Update the Typography's variant prop options
declare module '@mui/material/Typography' {
interface TypographyPropsVariantOverrides {
poster: true;
h3: false;
}
}
Step 4. You can now use the new variant
μΆκ°ν variantκ° μ λλ‘ μ μ©λμλμ§ νμΈν΄λ΄ λλ€.
<Typography variant="poster">poster</Typography>;
/* This variant is no longer supported. If you are using TypeScript it will give an error */
<Typography variant="h3">h3</Typography>;
Conclusion
μ²μμλ μ΄λ»κ² 컀μ€ν μ ν΄μΌ νλμ§ λ§λ§νλλ°, μμ μ λ΅μ 곡μ λ¬Έμμ λμ μμμ΅λλ€ :-) !!
https://mui.com/material-ui/customization/typography/#adding-amp-disabling-variants