Get dark/light mode state #5128
Unanswered
George-Madeley
asked this question in
Help and support
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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