Commit 9ae820ad authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-issue-12677' into 'master'

Update text_color_for_bg helper to support RGB triplet color codes

Closes #12677

See merge request !2587
parents 28e2d214 2e911721
...@@ -83,7 +83,11 @@ module LabelsHelper ...@@ -83,7 +83,11 @@ module LabelsHelper
end end
def text_color_for_bg(bg_color) def text_color_for_bg(bg_color)
r, g, b = bg_color.slice(1,7).scan(/.{2}/).map(&:hex) 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 (r + g + b) > 500
'#333333' '#333333'
......
...@@ -66,5 +66,10 @@ describe LabelsHelper do ...@@ -66,5 +66,10 @@ describe LabelsHelper do
it 'uses dark text on light backgrounds' do it 'uses dark text on light backgrounds' do
expect(text_color_for_bg('#EEEEEE')).to eq('#333333') expect(text_color_for_bg('#EEEEEE')).to eq('#333333')
end end
it 'supports RGB triplets' do
expect(text_color_for_bg('#FFF')).to eq '#333333'
expect(text_color_for_bg('#000')).to eq '#FFFFFF'
end
end end
end end
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