🎨

Overview of Material Design and MUI

Aug 22, 2024

Introduction to Material Design and Material UI

  • Material Design: A design system developed by Google that includes guidelines for various design elements such as typography, shapes, shadows, colors, spacing, icons, and components.
  • Material UI (MUI): A popular React library based on Material Design.
    • Over 2,500 contributors and 83,000 stars on GitHub.
    • Great for bootstrapping React projects, allowing developers to focus on business logic.

Getting Started with Material UI

  1. Installation:

    • Open your React project and run the command to install MUI and Emotion (for styling components).
  2. Creating a Container:

    • Use the Container component from MUI for basic page structure.
    • Ensure to import from Material, not System.
    • The Container is responsive by default.
  3. Adding Background Color:

    • Use the SX prop to set background color and other styles.
    • Example: Set background color to "tomato" and height to 100vh to visualize the container better.
  4. Typography Component:

    • Replace raw text with the Typography component to adhere to Material Design guidelines.
    • Use variant prop to change the tag (e.g., H1).
  5. Box Component:

    • Box is a flexible component that allows for styling using the SX prop.
    • Enables shorthand styling, such as P for padding, M for margin, etc.
    • Provides built-in spacing (8px units).
  6. Hover Styles and Responsive Design:

    • The SX prop supports hover styling and breakpoint-based styling for responsiveness.
    • Performance benefits as MUI converts values to normal CSS classes using Emotion.

Creating a Theme

  1. Theme Provider:

    • Import ThemeProvider and wrap your application to apply a custom theme.
    • Use createTheme to define typography, colors, spacing, breakpoints, etc.
  2. Customizing Styles:

    • Set header styles and primary/secondary colors in the theme.

Building a Service Page with Cards

  1. Creating the Page Structure:

    • Use Typography for page title and headers, utilizing the defined theme.
  2. Creating Cards:

    • Use an array to map services and create cards.
    • Paper component can be used for cards, with elevation for shadows.
    • Set styles using Box for layout and spacing.
  3. Adding Call to Action (CTA):

    • Utilize MUI Button component, which can be styled (contained, outline).
    • Automatic color adjustments based on primary/secondary theme colors.
  4. Making the Page Responsive:

    • Apply responsive styles using breakpoints (e.g., change flex direction based on screen size).
    • Fix card width and adjust for different screen sizes using shorthand properties.

Conclusion

  • Extensive components and customization options are available in MUI.
  • Refer to MUI documentation for more examples and TypeScript support.
  • Encouragement to start projects using Material UI.