Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Add support for Material You (alter the existing components) #34622

Closed
wants to merge 15 commits into from

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Oct 5, 2022

What's the PR about

This PR is a proof of concept of how we can add support for Material You incrementally without introducing breaking changes (see #29345). This would mean that we would support both Material Design 2 and Material Design 3 in parallel. In a future major release, we can then drop the support for MD2. The implementation is inspired by flutter/flutter#103537

👉 Playground link (inspired by #29345 (comment))

Implementation details

This POC uses a new factory for creating a Material Design 3 theme. It adds behind the scenes a new useMaterialYou flag, and adds the necessary design tokens for the new design systems (the palette values are added under under palette.md3 so that we can avoid conflicts with the existing theme).

The new useMaterialYou flag is then used in the component's styles generation. If the flag is set then the MD3 styles are being added on the component, otherwise the default MD2 styles are added. I've decided for this implementation so that we can make the components customization easier.

The new design tokens is available in both the standard theme usage, as well as the new CSS variables approach.

Usage

ThemeProvider

import { experimental_createMD3Theme as createMD3Theme } from '@mui/material/styles';

// light theme 
const lightTheme = createMD3Theme();
// dark theme
const darkTheme = createMD3Theme({
  palette: { mode: "dark" }
});

// Or with custom palette
const customTonalPalette = { ... };

const lightTheme = createMD3Theme({
  palette: { md3: customTonalPallette }
});

const darkTheme = createMD3Theme({
  palette: { mode: "dark", md3: customTonalPalette }
});

CssVarsProvider

import { experimental_extendMD3Theme as extendMD3Theme } from '@mui/material/styles';
const cssVarsTheme = extendMD3Theme();

// Or with custom palette

const cssVarsTheme = extendMD3Theme({
    colorSchemes: {
      light: {
        palette: { md3: palette }
      },
      dark: {
        palette: { md3: palette }
      }
    }
  });

TODOs:

@mnajdova mnajdova added design: material This is about Material Design, please involve a visual or UX designer in the process proof of concept Studying and/or experimenting with a to be validated approach labels Oct 5, 2022
@mui-bot
Copy link

mui-bot commented Oct 5, 2022

Details of bundle changes

@material-ui/core: parsed: +4.11% , gzip: +2.65%
@material-ui/lab: parsed: +2.71% , gzip: +1.53%

Generated by 🚫 dangerJS against 9e436c0

@mnajdova mnajdova changed the title [POC] Add useMaterialYou flag in the theme [POC] Add createMD3Theme creator Oct 7, 2022
@mnajdova mnajdova changed the title [POC] Add createMD3Theme creator [POC] Add support for Material You (alter the existing components) Oct 12, 2022
@mnajdova
Copy link
Member Author

@mnajdova mnajdova closed this Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design: material This is about Material Design, please involve a visual or UX designer in the process proof of concept Studying and/or experimenting with a to be validated approach
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants