mui / mui-toolpad

Toolpad Studio: Low-code admin builder. Open-source and powered by MUI.
https://mui.com/toolpad/
MIT License
895 stars 225 forks source link

[DashboardLayout] Add theme palette mode switcher #3586

Closed Janpot closed 2 days ago

Janpot commented 1 month ago

Summary

Currently the DashboardLayout component comes with a default light theme. We should add the possibility for different color schemes and if multiple are defined, we should add a theme switcher.

API proposal:

type AtLeastOne<T> = { [K in keyof T]: Pick<T, K> }[keyof T];

interface AppProviderProps {
  // ...
  themes?: AtLeastOne<{
    light: Theme;
    dark: Theme;
  }>;
  // unstable_adoptPaletteMode?: boolean;
}

Additional suggestion:

Add unstable_adoptPaletteMode, if it's true, we hide the theme switcher and we adopt the mode from the surrounding theme. This could be useful for the docs to remove the iframe from the demos.

Examples

No response

Motivation

No response

Search keywords: theme switcher

apedroferreira commented 1 month ago

Some benchmarking:

These were the first solutions that came to mind for me for this problem: https://github.com/mui/mui-toolpad/pull/3343#discussion_r1598691276

In conclusion, I think the initially proposed solution with

interface AppProviderProps {
  // ...
  themes?: AtLeastOne<{
    light: Theme;
    dark: Theme;
  }>;
  // unstable_adoptPaletteMode?: boolean;
}

seems fine and intuitive to use, and it's possibly the one that abstracts away the most / the simplest. It's very literal and would work with the theme switcher seamlessly.

themes defined, only one provided => use only the provided theme + remove theme switcher

What about passing just one theme directly? I feel like this would be more natural, but on the other hand it does create 2 quite different ways to define the theming (it's less consistent).

Add unstable_adoptPaletteMode, if it's true, we hide the theme switcher and we adopt the mode from the surrounding theme. This could be useful for the docs to remove the iframe from the demos.

This sounds good, we can try it!