How can I get the trigger of the filament's dark-light toggle button?
Hey, need help. how can I get the trigger of the filament's dark-light toggle button?
I've created a custom page. So over there, based on the dark mode I want to update css of a specific div. That's why I need to catch the dark mode toggle.
27 Replies
You can use the
.dark
tailwind classYes, that's a way to get the current state. But dark mode toggle button can't trigger using this strategy, cat it?
If you do something like
.dark .custom-class
you can add css in that way
So that css will only be visible in darkmode
Because that is what you want right? Custom css in darkmode?I like your name
Daar heeft die veel aan π
.a{ color: black; }
.b{ color: red; }
<p>Hello World</p>
In here, I want to add class 'a' in light mode, and add class 'b' in dark mode. And this class-add and class-remove will do when the dark mode button triggers.
This is my issue actually!
if you do
<p class="a dark:b">
it should work
Make make the css in b
important
But i think that is the best way to handle this
Have a look at the filament classes to see how they handle different style in darkmodeJij bent hier voor de support, ik voor de small talk
Ieder zo z'n taak
Prima verdeling
<span class="text-red dark:text-blue">Welcome</span>
just tried like this, not working.
Did the css show up in inspect?
Build the css
Class probably isnt compiled by tailwind
Do you have a custom theme?
And custom css file should be registered in boot method with
FilamentAsset::
i believenope
Then css isnt building
custom css
working on the light mode. actually developed keeping that in mind. but changing has become challenging.
How did you register the css file?
just below the <x-filament::page> tag of the page, then like this-
<link rel="stylesheet" href="{{ asset('css/style.css') }}">
just like how we do in a regular blade page
I don't think you can use the dark class then
Because tailwind needs to load that
So you should add that file to tailwind too
how can I then?
If you are going to use custom classes best way is to create a theme
understood
but I want thinking that if I can get the trigger of the dark mode toggle button, that would be easier to manage the classes.
Adding that class to the dark class is way easier then looking at the toggle
I suggest looking if the document has the dark class
But that is exactly what the
.dark
class doesyeah, searched and searching.
couldn't find that yet.
The best if I able to get the id of the color mode toggle button.
Just create a theme and start using the
.dark
classFound solution-
window.addEventListener('dark-mode-toggled', (event) => {
console.log(event.detail);
});