Dark Mode Configuration for Widgets #14477
Replies: 2 comments 2 replies
-
Haven't used it yet, but i noticed the HasDarkMode trait. Filament::getCurrentPanel()->hasDarkMode()
||
Filament::getCurrentPanel()->hadDarkModeForced() In your situation i'd use a helper to get the right colors. Something on the line of. But use it whatever you like <?php
class MyBrandTheme {
public static function getPrimaryColor(): string
{
return Filament::getCurrentPanel()->hasDarkMode() ? "#darkPrimaryColor" : "#lightPrimaryColor";
}
} return [
'labels' => $labels,
'datasets' => [
[
'type' => 'bar',
'label' => 'Created',
'data' => $data,
// Here is where I am trying to pivot based on dark mode status
'borderColor' => MyBrandTheme::getPrimaryColor(),
'backgroundColor' => '#FAF1FE',
],
],
]; |
Beta Was this translation helpful? Give feedback.
-
Hey @herrwalter - this is really cool, I hadn't seen that yet! Thank you for putting together an example and everything, super helpful! I think this almost completely solves my problem, except there is no way to properly calculate it completely with just I didn't see a similar set of getters for light mode, so I am kind of back to square one. |
Beta Was this translation helpful? Give feedback.
-
Package
Widgets
Package Version
v3.2
How can we help you?
Hello there 👋 .
I am trying to find a good way to change the colors of a Chart in a Widget in Filament based on the current Dark Mode setting.
Here is the return for my
getData
function:Things I have tried/thought about
Pivot colors on server side
I can't seem to find any server-side representation of that setting so that I can set the configuration value that way.
Inject Javascript into the widget
Is there a way to do this without making your own view for the widget? I can't seem to find a way to add a specific file or set of javascript to a widget. Then, I could just dig in on the ChartJS side of things.
Let me know if there are any other options as well!
Thanks
Beta Was this translation helpful? Give feedback.
All reactions