After some trial and error, I finally cracked the code! My approach is similar to @Soroush's solution, with a twist - I opted to utilize custom classes on the MUI component.
This is how I tackled it:
AppTheme.js
The key lies within the h2 node
of the theme object, where I incorporated my unique class .page-title
. While I could have streamlined this for brevity, I've included additional properties to showcase the versatility at your disposal.
// Define device sizes and integrate them into your theme object
const allDevices = "@media (min-width:320px) and (max-width: 1024px)";
const allPhones = "@media (min-width:320px) and (max-width: 767px)";
const portraitPhones = "@media (min-width:320px) and (max-width: 480px)";
const landscapePhones = "@media (min-width:481px) and (max-width: 767px)";
const tablets = "@media (min-width:768px) and (max-width: 1024px)";
const MuiTheme = {
palette: {
primary: { main: "#E54E55" },
secondary: { main: "#26B1EF" },
},
typography: {
fontFamily: [
"Montserrat",
"Roboto",
'"Helvetica Neue"',
"Arial",
"sans-serif",
].join(","),
h1: {
fontSize: "4rem",
fontWeight: "700",
[allPhones]: {
fontSize: "3.2rem",
},
},
h2: {
fontSize: "3.5rem",
fontWeight: "700",
[allPhones]: {
fontSize: "2.75rem",
},
"&.page-title": {
marginBottom: "120px",
},
},
},
overrides: {
// Style sheet name ⚛️
MuiTypography: {
// Name of the rule
gutterBottom: {
marginBottom: "20px",
},
},
MuiTabs: {
flexContainer: {
borderBottom: "1px solid #ddd",
},
indicator: {
height: "3px",
borderRadius: "5px 5px 0 0",
},
},
MuiButton: {
sizeLarge: {
paddingTop: "15px",
paddingBottom: "15px",
},
},
},
};
export default MuiTheme;
App.js
To incorporate your custom theme in your application, simply follow these steps:
import { createTheme, ThemeProvider } from "@material-ui/core/styles";
import AppTheme from "./AppTheme";
<ThemeProvider theme={createTheme(AppTheme)}>
Route and stuff ...
</ThemeProvider>;