From 6939bf8aed8514cc5a9e8bc28a97ea90c61b7ebe Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 13 Sep 2023 10:56:03 -0400 Subject: [PATCH] Fixes #12219: Ensure dashboard widget heading text has sufficient contrast (#13753) * Fixes #12219: Ensure dashboard widget heading text has sufficient contrast in both light & dark modes * Change foreground color for teal background --- netbox/extras/dashboard/widgets.py | 17 +++++++++++++++++ netbox/templates/extras/dashboard/widget.html | 10 +++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index dcf83bc14..0b185d432 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -16,6 +16,7 @@ from django.utils.translation import gettext as _ from extras.choices import BookmarkOrderingChoices from extras.utils import FeatureQuery +from utilities.choices import ButtonColorChoices from utilities.forms import BootstrapMixin from utilities.permissions import get_permission_for_model from utilities.templatetags.builtins.filters import render_markdown @@ -115,6 +116,22 @@ class DashboardWidget: def name(self): return f'{self.__class__.__module__.split(".")[0]}.{self.__class__.__name__}' + @property + def fg_color(self): + """ + Return the appropriate foreground (text) color for the widget's color. + """ + if self.color in ( + ButtonColorChoices.CYAN, + ButtonColorChoices.GRAY, + ButtonColorChoices.GREY, + ButtonColorChoices.TEAL, + ButtonColorChoices.WHITE, + ButtonColorChoices.YELLOW, + ): + return ButtonColorChoices.BLACK + return ButtonColorChoices.WHITE + @property def form_data(self): return { diff --git a/netbox/templates/extras/dashboard/widget.html b/netbox/templates/extras/dashboard/widget.html index 1559363d3..b8dec3de2 100644 --- a/netbox/templates/extras/dashboard/widget.html +++ b/netbox/templates/extras/dashboard/widget.html @@ -9,14 +9,16 @@ gs-id="{{ widget.id }}" >
-
+
+ > + +
+ > + +
{% if widget.title %} {{ widget.title }}