You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tl;dr: is there a hook or other means to get the state indicating if the app in currently in dark or light mode?
Before moving to Toolpad Core, I would use MUIs useTheme or useColorScheme to get the current color mode. But since migrating to Toolpad Core, neither of these methods work; they just reflect the mode the app was booted up in (i.e., if started in light mode, they will always return light mode and vice versa).
I know the SSR theme switch just switches the CSS color mode which just tells the components to use the light mode style sheets or the dark mode ones so nothing is really held in state. However, the <ThemeSwitcher> component render s different tooltip depending on the color mode, therefore, a state that knows the current color mode.
Looking at the code of <ThemeSwitcher> reveals that there is a context called PaletteModeContext which holds the current color mode state. But this context isn't exposed by the library and therefore cannot use it.
For context, I am drawing to a canvas therefore I cannot use the CSS variables. I want to adapt the color palette I am drawing with depending on the current color mode.
If anyone has any way to get the current color mode theme in Toolpad, that would be fantastic!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
tl;dr: is there a hook or other means to get the state indicating if the app in currently in dark or light mode?
Before moving to Toolpad Core, I would use MUIs
useThemeoruseColorSchemeto get the current color mode. But since migrating to Toolpad Core, neither of these methods work; they just reflect the mode the app was booted up in (i.e., if started in light mode, they will always return light mode and vice versa).I know the SSR theme switch just switches the CSS color mode which just tells the components to use the light mode style sheets or the dark mode ones so nothing is really held in state. However, the
<ThemeSwitcher>component render s different tooltip depending on the color mode, therefore, a state that knows the current color mode.Looking at the code of
<ThemeSwitcher>reveals that there is a context calledPaletteModeContextwhich holds the current color mode state. But this context isn't exposed by the library and therefore cannot use it.For context, I am drawing to a canvas therefore I cannot use the CSS variables. I want to adapt the color palette I am drawing with depending on the current color mode.
If anyone has any way to get the current color mode theme in Toolpad, that would be fantastic!
Beta Was this translation helpful? Give feedback.
All reactions