Module: Playbook::Spacing

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/playbook/spacing.rb', line 5

def self.included(base)
  base.prop :margin
  base.prop :margin_bottom
  base.prop :margin_left
  base.prop :margin_right
  base.prop :margin_top
  base.prop :margin_x
  base.prop :margin_y
  base.prop :max_width
  base.prop :padding
  base.prop :padding_bottom
  base.prop :padding_left
  base.prop :padding_right
  base.prop :padding_top
  base.prop :padding_x
  base.prop :padding_y
end

Instance Method Details

#break_method_valuesObject



60
61
62
# File 'lib/playbook/spacing.rb', line 60

def break_method_values
  %w[on at]
end

#max_width_optionsObject



23
24
25
26
27
# File 'lib/playbook/spacing.rb', line 23

def max_width_options
  {
    max_width: "mw",
  }
end

#max_width_propsObject



90
91
92
93
94
95
96
97
98
# File 'lib/playbook/spacing.rb', line 90

def max_width_props
  selected_mw_props = max_width_options.keys.select { |sk| try(sk) }
  return nil unless selected_mw_props.present?

  selected_mw_props.map do |k|
    width_value = send(k)
    "max_width_#{width_value}" if max_width_values.include? width_value
  end.compact.join(" ")
end

#max_width_valuesObject



29
30
31
# File 'lib/playbook/spacing.rb', line 29

def max_width_values
  %w[xs sm md lg xl xxl 0 none]
end

#screen_size_valuesObject



56
57
58
# File 'lib/playbook/spacing.rb', line 56

def screen_size_values
  %w[xs sm md lg xl default]
end

#spacing_optionsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/playbook/spacing.rb', line 33

def spacing_options
  {
    margin: "m",
    margin_bottom: "mb",
    margin_left: "ml",
    margin_right: "mr",
    margin_top: "mt",
    margin_x: "mx",
    margin_y: "my",
    padding: "p",
    padding_bottom: "pb",
    padding_left: "pl",
    padding_right: "pr",
    padding_top: "pt",
    padding_x: "px",
    padding_y: "py",
  }
end

#spacing_propsObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/playbook/spacing.rb', line 64

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

  css = ""
  selected_props.each do |prop|
    responsive = try(prop).is_a?(::Hash)
    spacing_value = send(prop)
    prefix = spacing_options[prop]

    if responsive
      default_value = spacing_value.delete(:default) || nil
      break_value = spacing_value.delete(:break) || break_method_values.first
      spacing_value.each do |key, value|
        css += "break_#{break_value}_#{key}\:#{prefix}_#{value} " if screen_size_values.include?(key.to_s) && spacing_values.include?(value.to_s)
      end

      css += "#{prefix}_#{default_value} " if spacing_values.include?(default_value)
    elsif spacing_values.include?(spacing_value)
      css += "#{prefix}_#{spacing_value} "
    end
  end

  css.strip unless css.blank?
end

#spacing_valuesObject



52
53
54
# File 'lib/playbook/spacing.rb', line 52

def spacing_values
  %w[none xxs xs sm md lg xl auto initial inherit]
end