Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Change the font color of the primary action buttons depending on the chosen color brightness

Henriette Dargecfedf1c59dbd
diff --git a/app/models/colors/hex_color.rb b/app/models/colors/hex_color.rb
index 2d063c2e9b3..7825f306f1b 100644
--- a/app/models/colors/hex_color.rb
+++ b/app/models/colors/hex_color.rb
@@ -5,11 +5,11 @@ module Colors
# If the color is light, use a dark font.
# Otherwise, use a white font.
def color_styles(light_color: "#FFFFFF", dark_color: "#333333")
- if bright?
- { color: dark_color, "background-color": hexcode }
- else
- { color: light_color, "background-color": hexcode }
- end
+ { color: contrasting_font_color(light: light_color, dark: dark_color), "background-color": hexcode }
+ end
+
+ def contrasting_font_color(light: "#FFFFFF", dark: "#333333")
+ bright? ? dark : light
end
##
diff --git a/app/views/custom_styles/_inline_css.erb b/app/views/custom_styles/_inline_css.erb
index 68b6d948def..f824982bf09 100644
--- a/app/views/custom_styles/_inline_css.erb
+++ b/app/views/custom_styles/_inline_css.erb
@@ -42,6 +42,7 @@ See COPYRIGHT and LICENSE files for more details.
--primary-button-color--minor1: <%= design_color.lighten 0.8 %>;
--primary-button-color--minor2: <%= design_color.lighten 0.6 %>;
--primary-button-color--dark-mode: <%= design_color.lighten 0.4 %>;
+ --font-color-on-primary: <%= design_color.contrasting_font_color %>;
<% end %>
<% if design_color.variable == "accent-color" %>
--accent-color--major1: <%= design_color.darken 0.2 %>;