Module: Playbook::Hover

Included in:
KitBase
Defined in:
lib/playbook/hover.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
# File 'lib/playbook/hover.rb', line 5

def self.included(base)
  base.prop :hover
  base.prop :group_hover, type: Playbook::Props::Boolean, default: false
end

Instance Method Details

#hover_attributesObject



36
37
38
# File 'lib/playbook/hover.rb', line 36

def hover_attributes
  %w[background shadow scale color]
end

#hover_background_valuesObject



24
25
26
# File 'lib/playbook/hover.rb', line 24

def hover_background_values
  []
end

#hover_color_valuesObject



28
29
30
# File 'lib/playbook/hover.rb', line 28

def hover_color_values
  []
end

#hover_optionsObject



10
11
12
13
14
# File 'lib/playbook/hover.rb', line 10

def hover_options
  {
    hover: "hover",
  }
end

#hover_propsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/playbook/hover.rb', line 40

def hover_props
  selected_props = hover_options.keys.select { |sk| try(sk) }

  return nil if selected_props.nil? && group_hover.nil?

  responsive = selected_props.present? && try(selected_props.first).is_a?(::Hash)
  css = ""
  selected_props.each do |prop|
    value = send(prop)
    prefix = hover_options[prop]
    if responsive
      value.each do |key, val|
        if %i[background color].include?(key)
          css += "#{prefix}_#{key}-#{val} " if hover_attributes.include?(key.to_s)
        elsif hover_attributes.include?(key.to_s) && send("hover_#{key}_values").include?(val.to_s)
          css += "#{prefix}_#{key}_#{val} "
        end
      end
    elsif send("hover_#{prop}_values").include?(value)
      css += "#{prefix}_#{value} "
    end
  end

  css += "group_hover " if group_hover
  css.strip unless css.blank?
end

#hover_scale_valuesObject



20
21
22
# File 'lib/playbook/hover.rb', line 20

def hover_scale_values
  %w[sm md lg]
end

#hover_shadow_valuesObject



16
17
18
# File 'lib/playbook/hover.rb', line 16

def hover_shadow_values
  %w[deep deeper deepest]
end

#hover_valuesObject



32
33
34
# File 'lib/playbook/hover.rb', line 32

def hover_values
  hover_options.keys.select { |sk| try(sk) }
end