Module: Playbook::FlexWrap

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

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

Instance Method Details

#flex_wrap_optionsObject

rubocop:enable Style/IfInsideElse



37
38
39
40
41
# File 'lib/playbook/flex_wrap.rb', line 37

def flex_wrap_options
  {
    flex_wrap: "flex_wrap",
  }
end

#flex_wrap_propsObject

rubocop:disable Style/IfInsideElse



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/playbook/flex_wrap.rb', line 10

def flex_wrap_props
  selected_props = flex_wrap_options.keys.select { |sk| try(sk) }
  return nil unless selected_props.present?

  screen_size_values = %w[xs sm md lg xl]

  selected_props.map do |k|
    flex_wrap_value = send(k)
    if flex_wrap_value.is_a?(Hash)
      class_result = []

      # Handle default value separately (generates base class without size prefix)
      class_result << "flex_wrap_#{flex_wrap_value[:default].underscore}" if flex_wrap_value.key?(:default) && flex_wrap_values.include?(flex_wrap_value[:default])

      # Handle responsive sizes (generates classes with size prefix)
      flex_wrap_value.each do |media_size, wrap_value|
        class_result << "flex_wrap_#{media_size}_#{wrap_value.underscore}" if screen_size_values.include?(media_size.to_s) && flex_wrap_values.include?(wrap_value)
      end

      class_result
    else
      "flex_wrap_#{flex_wrap_value}" if flex_wrap_values.include? flex_wrap_value
    end
  end.flatten.compact.join(" ")
end

#flex_wrap_valuesObject



43
44
45
# File 'lib/playbook/flex_wrap.rb', line 43

def flex_wrap_values
  %w[wrap nowrap wrapReverse]
end