Module: Sass::Extras::Contrast::Functions

Defined in:
lib/sass/extras/contrast.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



37
38
39
40
41
# File 'lib/sass/extras/contrast.rb', line 37

def self.included(base)
  base.declare :contrast_color, [:color]
  base.declare :contrast_color, [:color, :seed_color]
  base.declare :contrast_color, [:color, :seed_color, :wcag20_level]
end

Instance Method Details

#contrast_color(color, seed_color = nil, wcag20_level = Sass::Script::String.new("aa")) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sass/extras/contrast.rb', line 43

def contrast_color(color, seed_color = nil, wcag20_level = Sass::Script::String.new("aa"))
  seed_color ||= color
  assert_type color, :Color, :color
  assert_type seed_color, :Color, :seed_color
  assert_type wcag20_level, :String, :wcag20_level
  direction = color.brightness > 127 ? darken_method : lighten_method
  new_color = seed_color
  percentage = 0.0
  until conform(new_color, color, wcag20_level.value) || percentage > 100.0
    amount = Sass::Script::Number.new percentage, ['%']
    new_color = send(direction, seed_color, amount)
    percentage += 0.1
  end
  new_color
end