Module: Playbook::FlexGrow

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

Constant Summary collapse

FLEX_GROW_VALUES =
%w[1 0].freeze
SCREEN_SIZES =
%w[xs sm md lg xl].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

def self.included(base)
  base.prop :flex_grow
end

Instance Method Details

#flex_grow_optionsObject



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

def flex_grow_options
  { flex_grow: "flex_grow" }
end

#flex_grow_propsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/playbook/flex_grow.rb', line 12

def flex_grow_props
  value = flex_grow
  return nil unless value

  if value.is_a?(::Hash)
    css = +""
    css << "flex_grow_#{value[:default]} " if value.key?(:default) && FLEX_GROW_VALUES.include?(value[:default].to_s)
    value.each do |media_size, grow_value|
      css << "flex_grow_#{media_size}_#{grow_value} " if SCREEN_SIZES.include?(media_size.to_s) && FLEX_GROW_VALUES.include?(grow_value.to_s)
    end
    css.strip unless css.empty?
  elsif FLEX_GROW_VALUES.include?(value.to_s)
    "flex_grow_#{value}"
  end
end

#flex_grow_valuesObject



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

def flex_grow_values
  FLEX_GROW_VALUES
end