HOME
SERVICES
WORKABOUT US

Part II — Implementation

🌈  Setting up a centralized theme

notion image
notion image
 

💡 Why a centralized theme?
  

➡️  Design system

 

Configuration [ Docs ]

App configuration

// src/index.js 
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { red } from '@mui/material/colors';

const theme = createTheme({
  palette: {
    primary: {
      main: red[500],
    },
  },
});

...

root.render(
  <React.StrictMode>
    <ThemeProvider theme={theme}>
      <App />
    </ThemeProvider>
  </React.StrictMode>
);
 

🤢  Our button is ugly!

notion image
 

Let’s make it blue 500 and Nunito Sans as typography:

const theme = createTheme({
	palette: {
		primary: {
			main: blue[500],
		},
	},
	typography: {
    fontFamily: "Nunito Sans",
  }
});
 

Storybook configuration

  • Inject MUI theme into Storybook (Docs ⇒ ⛔️ Add-on doesn’t work for MUI v5)
  • Move theme to its own file under src/theme/index.js
 
  • Need to add a new decorator into preview.js
// .storybook/preview.js 
import theme from "../src/theme";

export const decorators = [
  (Story) => (
    <ThemeProvider theme={theme}>
      <Story />
    </ThemeProvider>
  ),
];
 

Add theme stories

 

🎸  Injecting icons to our components

Icon Library [ Docs ]

🌟 Over 2K icons ready to use!

Installation

yarn add @mui/icons-material

Exercise ✍️

Enable ability to add icons in our Button component
 
 

✍️  Writing our first components

 

Avatar [ Docs ]

notion image

Menu [ Docs ]

notion image
 

Alert [ Docs ]

notion image
 
💡 What is the `argTypes` control?
notion image
 

🎨  Writing custom styles to inject to our components

Supported styles [ Docs ]


❓ Is our `css` currently working in our components?

 

styled() and the sx prop

  • Quick comparison styled-components vs MUI systemLink
notion image

☀️ Time to write custom styles

// src/components/ButtonStyles.js
export default {
  root: {
    px: 3,
    textTransform: "capitalize",
    letterSpacing: 1,
    fontWeight: "bold",
  },
};
 

➡️  Material Design Baseline Grid — Link

 

Exercise ✍️

Change the bgColor of our button using the secondary color using the `sx prop`.
 
 

 

⬇️  Download code [ Link ]