mui / toolpad

Toolpad: Full stack components and low-code builder for dashboards and internal apps.
https://mui.com/toolpad/
MIT License
1k stars 259 forks source link

[core] Optimize Theme Mode Selector in Header #4151

Open douglaszaltron opened 2 weeks ago

douglaszaltron commented 2 weeks ago

Summary

When we have the ability in the theme to select mode (system, dark, and light), a toggle button is created in the header. However, this element occupies precious space in the header that could be used for other types of configurations. The proposal is to follow the MUI documentation style, where there is a gear button that contains configuration options, including the mode selector, along with other settings.

For example: language preferences, display preferences, among others.

Examples

Captura de Tela 2024-09-24 às 10 48 13 Captura de Tela 2024-09-24 às 10 48 17

Motivation

No response

Search keywords: theme

Janpot commented 2 weeks ago

Assuming there are going to be many different ways of how users would want this to be executed (*), perhaps step 1 should be to create the minimum API necessary to customize this in user land. It's already possible to build your own theme toggle with the useColorScheme hook. The one thing missing then is a way to hide the theme toggle in the header.

cc @apedroferreira Perhaps a quick win here could be to add a slot for the theme toggle?


(*) I'm imagining

apedroferreira commented 2 weeks ago

Assuming there are going to be many different ways of how users would want this to be executed (*), perhaps step 1 should be to create the minimum API necessary to customize this in user land. It's already possible to build your own theme toggle with the useColorScheme hook. The one thing missing then is a way to hide the theme toggle in the header.

cc @apedroferreira Perhaps a quick win here could be to add a slot for the theme toggle?

(*) I'm imagining

  • a toggle button
  • a drawer as per this issue
  • a button with popover
  • on a separate settings page
  • no toggle at all, just follow the system preference
  • ...

Sounds good, we have 2 slots in the header right now (account + additional actions), but the theme is outside of them. I guess we should have the minimum amount of slots in the header than can be completely overriden.

ebengtso commented 1 week ago

Hi, I would like to restore the user theme's choice when user logins back. Is it possible to provide a Slotprops for Theme's user action? Thanks

Janpot commented 1 week ago

@ebengtso Can you elaborate a bit more on what you're trying to do?

Are you storing the dark/light mode choice in the user record on the backend? You should be able to already achieve that functionality with mode and setMode returned by the useColorScheme hook.

ebengtso commented 1 week ago

@ebengtso Can you elaborate a bit more on what you're trying to do?

Are you storing the dark/light mode choice in the user record on the backend? You should be able to already achieve that functionality with mode and setMode returned by the useColorScheme hook.

Thanks. Two distinct issues:

1) I had a wrapping ThemeProvider. I removed it and it worked (as a cookie). It was disturbing the AppProvider.

2) In the below I was expecting debug to print, but it's not printing when I switch the theme. For this reason I cannot save the mode on user change.

const {mode, setMode} = useColorScheme();

useEffect(() => { console.debug(mode) }, [mode]);

Janpot commented 1 week ago

@ebengtso Here's a stackblitz that demonstrates useColorScheme. Make sure to call it in a component that's rendered under the DashboardLayout. I've opened a ticket to improve DX when it's not the case.