Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. In this file, make two new objects, one calledmyThemeLightand the other calledmyThemeDark. We will use these to separate out light and dark mode colours.

...

Code Block
languagetypescript
// Light palette
const myThemeLight = {

};

// Dark palette
const myThemeDark = {

};

export { myThemeLight, myThemeDark }
  1. Import the createTheme function from@mui/material/styles. This will generate a theme based on the options received.

...

Code Block
languagetypescript
import { createTheme } from "@mui/material/styles";

// Light palette
const myThemeLight = {

};

// Dark palette
const myThemeDark = {

};

export { myThemeLight, myThemeDark }

...

  1. Import baseTheme, and use the spread operator to gain all styles from the base file.

...

Code Block
languagetypescript
import { createTheme } from "@mui/material/styles";
import baseTheme from "./baseTheme";

// Light palette
const myThemeLight = {
  ...baseTheme
};

// Dark palette
const myThemeDark = {
  ...baseTheme
};

export { myThemeLight, myThemeDark }
  1. Define a colour palette, and specify what mode this colour palette is for:“light"or“dark"

...

Code Block
languagetypescript
const myThemeLight = createTheme({
  ...baseTheme
  palette: {
    main: "#.....",
  },
})
  1. Repeat for the other mode.

  2. For adding styles to typography or components, import the mergeThemeStyleshelper 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
languagetypescript
import { mergeThemeStyles } from "src/helpers/mergeThemeStyles";

typography: mergeThemeStyles(baseTheme.typography, {
  h1: {
    // specify styles here...
  }
})

Adding colours to components

...

  1. Find the CSS to target through the Material UI docs, or the CSS inspector

  2. Add colour within relevant class

...

Code Block
languagetypescript
MuiButton: {
  styleOverrides: {
    root: {
      backgroundColor: "purple"
    }
  }
}

Custom CSS classes for increased specificity

...