Commit e7838c3e authored by Sean McGivern's avatar Sean McGivern

Merge branch '208229-haml-scoped-labels-incorrect-text-color' into 'master'

Fix scoped label text color when background is light

See merge request gitlab-org/gitlab!26037
parents 3ba168f2 1527fd7b
......@@ -115,13 +115,7 @@ module LabelsHelper
end
def text_color_class_for_bg(bg_color)
if bg_color.length == 4
r, g, b = bg_color[1, 4].scan(/./).map { |v| (v * 2).hex }
else
r, g, b = bg_color[1, 7].scan(/.{2}/).map(&:hex)
end
if (r + g + b) > 500
if light_color?(bg_color)
'gl-label-text-dark'
else
'gl-label-text-light'
......@@ -129,17 +123,21 @@ module LabelsHelper
end
def text_color_for_bg(bg_color)
if bg_color.length == 4
r, g, b = bg_color[1, 4].scan(/./).map { |v| (v * 2).hex }
if light_color?(bg_color)
'#333333'
else
r, g, b = bg_color[1, 7].scan(/.{2}/).map(&:hex)
'#FFFFFF'
end
end
if (r + g + b) > 500
'#333333'
def light_color?(color)
if color.length == 4
r, g, b = color[1, 4].scan(/./).map { |v| (v * 2).hex }
else
'#FFFFFF'
r, g, b = color[1, 7].scan(/.{2}/).map(&:hex)
end
(r + g + b) > 500
end
def labels_filter_path_with_defaults(only_group_labels: false, include_ancestor_groups: true, include_descendant_groups: false)
......
......@@ -17,6 +17,7 @@ module EE
bg_color: label.color
) + render_label_text(
label.scoped_label_value,
css_class: ('gl-label-text-dark' if light_color?(label.color)),
suffix: suffix
)
end
......
......@@ -20,6 +20,18 @@ describe LabelsHelper do
it 'does not include link to scoped label documentation for common labels' do
expect(render_label(label)).to match(%r(<span.+><span.+>#{label.name}</span></span>$)m)
end
it 'right text span does not have .gl-label-text-dark class if label color is dark' do
scoped_label.color = '#D10069'
expect(render_label(scoped_label)).not_to match(%r(<span.*gl-label-text-dark.*>#{scoped_label.scoped_label_value}</span>)m)
end
it 'right text span has .gl-label-text-dark class if label color is light' do
scoped_label.color = '#FFECDB'
expect(render_label(scoped_label)).to match(%r(<span.*gl-label-text-dark.*>#{scoped_label.scoped_label_value}</span>)m)
end
end
context 'with scoped labels disabled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment