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

add a generic color class that we can use with different style classes

Klaus Zandersc3df2561ab6d
diff --git a/app/helpers/colors_helper.rb b/app/helpers/colors_helper.rb
index 96af0e1c73a..e19c8b33a20 100644
--- a/app/helpers/colors_helper.rb
+++ b/app/helpers/colors_helper.rb
@@ -48,6 +48,14 @@ module ColorsHelper
colored_thing.color_id
end
+ def concat(line)
+ if Rails.env.development?
+ super("#{line}\n")
+ else
+ super
+ end
+ end
+
#
# Styles to display colors itself (e.g. for the colors autocompleter)
##
@@ -71,7 +79,7 @@ module ColorsHelper
color = entry.color
if color.nil?
- concat ".#{hl_inline_class(name, entry)}::before { display: none }\n"
+ concat ".#{hl_inline_class(name, entry)}::before { display: none }"
return
end
@@ -82,6 +90,13 @@ module ColorsHelper
end
set_background_colors_for(class_name: ".#{hl_background_class(name, entry)}", color:)
+
+ # generic class for color
+ set_generic_color_for(class_name: ".#{hl_color_class(name, entry)}", color:)
+ end
+
+ def hl_color_class(name, model)
+ "__hl_#{name}_#{model.id}"
end
def hl_inline_class(name, model)
@@ -115,6 +130,13 @@ module ColorsHelper
DesignColor.find_by(variable:)&.hexcode
end
+ def set_generic_color_for(class_name:, color:)
+ mode = User.current.pref.theme.split("_", 2)[0]
+ mode_variables = mode == "dark" ? default_variables_dark : default_variables_light
+
+ concat "#{class_name} { #{default_color_styles(color.hexcode)} #{mode_variables} }"
+ end
+
def set_background_colors_for(class_name:, color:)
mode = User.current.pref.theme.split("_", 2)[0]
@@ -141,66 +163,82 @@ module ColorsHelper
end
end
- # rubocop:disable Layout/LineLength
def default_color_styles(hex)
color = ColorConversion::Color.new(hex)
rgb = color.rgb
hsl = color.hsl
- "--color-r: #{rgb[:r]};
- --color-g: #{rgb[:g]};
- --color-b: #{rgb[:b]};
- --color-h: #{hsl[:h]};
- --color-s: #{hsl[:s]};
- --color-l: #{hsl[:l]};
- --perceived-lightness: calc( ((var(--color-r) * 0.2126) + (var(--color-g) * 0.7152) + (var(--color-b) * 0.0722)) / 255 );
- --lightness-switch: max(0, min(calc((1/(var(--lightness-threshold) - var(--perceived-lightness)))), 1));"
+ <<~CSS.squish
+ --color-r: #{rgb[:r]};
+ --color-g: #{rgb[:g]};
+ --color-b: #{rgb[:b]};
+ --color-h: #{hsl[:h]};
+ --color-s: #{hsl[:s]};
+ --color-l: #{hsl[:l]};
+ --perceived-lightness: calc( ((var(--color-r) * 0.2126) + (var(--color-g) * 0.7152) + (var(--color-b) * 0.0722)) / 255 );
+ --lightness-switch: max(0, min(calc((1/(var(--lightness-threshold) - var(--perceived-lightness)))), 1));
+ CSS
end
def default_variables_dark
- "--lightness-threshold: 0.6;
- --background-alpha: 0.18;
- --lighten-by: calc(((var(--lightness-threshold) - var(--perceived-lightness)) * 100) * var(--lightness-switch));"
+ <<~CSS.squish
+ --lightness-threshold: 0.6;
+ --background-alpha: 0.18;
+ --lighten-by: calc(((var(--lightness-threshold) - var(--perceived-lightness)) * 100) * var(--lightness-switch));
+ CSS
end
def default_variables_light
- "--lightness-threshold: 0.453;"
+ <<~CSS.squish
+ --lightness-threshold: 0.453;
+ CSS
end
def highlighted_background_dark
- "color: hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%)) !important;
- background: rgba(var(--color-r), var(--color-g), var(--color-b), var(--background-alpha)) !important;
- border: 1px solid hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%)) !important;"
+ <<~CSS.squish
+ color: hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%)) !important;
+ background: rgba(var(--color-r), var(--color-g), var(--color-b), var(--background-alpha)) !important;
+ border: 1px solid hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%)) !important;
+ CSS
end
def highlighted_background_light
- style = "color: hsl(0deg, 0%, calc(var(--lightness-switch) * 100%)) !important;
- background: rgb(var(--color-r), var(--color-g), var(--color-b)) !important;"
+ style = <<~CSS.squish
+ color: hsl(0deg, 0%, calc(var(--lightness-switch) * 100%)) !important;
+ background: rgb(var(--color-r), var(--color-g), var(--color-b)) !important;
+ CSS
mode = User.current.pref.theme
- style +=
- if mode == "light_high_contrast"
- "border: 1px solid hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - 75) * 1%), 1) !important;"
- else
- "border: 1px solid hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - 15) * 1%)) !important;"
- end
+ style += if mode == "light_high_contrast"
+ <<~CSS.squish
+ border: 1px solid hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - 75) * 1%), 1) !important;
+ CSS
+ else
+ <<~CSS.squish
+ border: 1px solid hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - 15) * 1%)) !important;
+ CSS
+ end
style
end
def highlighted_foreground_dark
- "color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%), 1) !important;"
+ <<~CSS.squish
+ color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%), 1) !important;
+ CSS
end
def highlighted_foreground_light
mode = User.current.pref.theme
if mode == "light_high_contrast"
- "color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - (var(--color-l) * 0.5)) * 1%), 1) !important;"
+ <<~CSS.squish
+ color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - (var(--color-l) * 0.5)) * 1%), 1) !important;
+ CSS
else
- "color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - (var(--color-l) * 0.22)) * 1%), 1) !important;"
+ <<~CSS.squish
+ color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - (var(--color-l) * 0.22)) * 1%), 1) !important;
+ CSS
end
end
-
- # rubocop:enable Layout/LineLength
end
diff --git a/app/views/highlighting/styles.css.erb b/app/views/highlighting/styles.css.erb
index 2582f25c686..cfd9dc5e4b3 100644
--- a/app/views/highlighting/styles.css.erb
+++ b/app/views/highlighting/styles.css.erb
@@ -11,6 +11,9 @@
<%= color_css %>
+<%# usage classes %>
+.__hl_border_top { border-top: 4px solid hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - 15) * 1%)) !important; } }
+
<%# Overdue tasks %>
.__hl_date_due_today { color: #F76707 !important; }
.__hl_date_overdue { color: #C92A2A !important; font-weight: var(--base-text-weight-bold); }