Detect current mode (dark/light) in custom page
As the title says, what's the best way to detect the current active mode (dark/light) in a custom Filament page?
I have something like this
But I wonder if there's a better way.
Thanks
Solution:Jump to solution
Yeah, what I'm going for right now is transform the existing classes. So from this (example code)
```css
/* light.css */
.foobar {
border: 1px solid red;...
8 Replies
What do you want to do with the information?
Haha that's an interesting question 😂
I'm trying to 'migrate' some old code, which imports different css files based on the 'theme'.
I plan to re-write the whole thing in the future, but for the time being, I'm looking at my options for a quick solution.
I'd like to do something like
I'm open to any suggestions ¯\_(ツ)_/¯
I’m not sure of a good way to do this. The color mode is handled by js, so there’s no real way to get it on the backend.
Yeah I guess I'll have to move all the classes. Hopefully there's an easy way to do this (maybe some sort of media query?) but I suck at css haha
anyway, thank you both for your time 🙇♂️
I would definitely look into css properties. That way you can have one stylesheet and just change the colors based on a high level class (like on the html element). That’s how tailwind works.
You could have an hook that on page load, check the color in use and send it back if different to whats in the session I suppose?
If you really don't want to change much stuff, you could probably conditionally load the CSS file via JS when you detect dark mode. But it would be better to handle this in CSS directly using the
.dark classSolution
Yeah, what I'm going for right now is transform the existing classes. So from this (example code)
to
which is more work but better than adding hacks imho.
Anyway, thank you all for your time, and if you have any suggestions or tips on how to improve this, I'd be happy to hear them