...
In this file, make two new objects, one called
myThemeLight
and the other calledmyThemeDark
. We will use these to separate out light and dark mode colours.
...
Code Block | ||
---|---|---|
| ||
// Light palette const myThemeLight = { }; // Dark palette const myThemeDark = { }; export { myThemeLight, myThemeDark } |
Import the
createTheme
function from@mui/material/styles
. This will generate a theme based on the options received.
...
Code Block | ||
---|---|---|
| ||
import { createTheme } from "@mui/material/styles"; // Light palette const myThemeLight = { }; // Dark palette const myThemeDark = { }; export { myThemeLight, myThemeDark } |
...
Import
baseTheme
, and use the spread operator to gain all styles from the base file.
...
Code Block | ||
---|---|---|
| ||
import { createTheme } from "@mui/material/styles"; import baseTheme from "./baseTheme"; // Light palette const myThemeLight = { ...baseTheme }; // Dark palette const myThemeDark = { ...baseTheme }; export { myThemeLight, myThemeDark } |
Define a colour palette, and specify what mode this colour palette is for:
“light"
or“dark"
...
Code Block | ||
---|---|---|
| ||
const myThemeLight = createTheme({
...baseTheme
palette: {
main: "#.....",
},
}) |
Repeat for the other mode.
For adding styles to typography or components, import the
mergeThemeStyles
helper function. This can be used to add on to existing typography styles in thebaseTheme
. It can also be used to add new colour styles without specifying them in thebaseTheme
.
...
Code Block | ||
---|---|---|
| ||
import { mergeThemeStyles } from "src/helpers/mergeThemeStyles";
typography: mergeThemeStyles(baseTheme.typography, {
h1: {
// specify styles here...
}
}) |
Adding colours to components
...
Find the CSS to target through the Material UI docs, or the CSS inspector
Add colour within relevant class
...
Code Block | ||
---|---|---|
| ||
MuiButton: {
styleOverrides: {
root: {
backgroundColor: "purple"
}
}
} |
Custom CSS classes for increased specificity
...