Module: Playbook::Spacing
- Included in:
- KitBase
- Defined in:
- lib/playbook/spacing.rb
Class Method Summary collapse
Instance Method Summary collapse
- #break_method_values ⇒ Object
- #filter_classname(value) ⇒ Object
- #max_width_options ⇒ Object
- #max_width_props ⇒ Object
- #max_width_values ⇒ Object
- #min_width_options ⇒ Object
- #min_width_props ⇒ Object
- #min_width_values ⇒ Object
- #screen_size_values ⇒ Object
- #spacing_options ⇒ Object
- #spacing_props ⇒ Object
- #spacing_values ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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 :min_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_values ⇒ Object
71 72 73 |
# File 'lib/playbook/spacing.rb', line 71 def break_method_values %w[on at] end |
#filter_classname(value) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/playbook/spacing.rb', line 101 def filter_classname(value) if value.include?("%") value.gsub("%", "_percent") else value end end |
#max_width_options ⇒ Object
24 25 26 27 28 |
# File 'lib/playbook/spacing.rb', line 24 def { max_width: "mw", } end |
#max_width_props ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/playbook/spacing.rb', line 119 def max_width_props selected_mw_props = .keys.select { |sk| try(sk) } return nil unless selected_mw_props.present? selected_mw_props.map do |k| width_value = send(k) "max_width_#{filter_classname(width_value)}" if max_width_values.include? width_value end.compact.join(" ") end |
#max_width_values ⇒ Object
36 37 38 |
# File 'lib/playbook/spacing.rb', line 36 def max_width_values %w[0% xs sm md lg xl xxl 0 none 100%] end |
#min_width_options ⇒ Object
30 31 32 33 34 |
# File 'lib/playbook/spacing.rb', line 30 def { min_width: "minw", } end |
#min_width_props ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/playbook/spacing.rb', line 109 def min_width_props selected_minw_props = .keys.select { |sk| try(sk) } return nil unless selected_minw_props.present? selected_minw_props.map do |k| width_value = send(k) "min_width_#{filter_classname(width_value)}" if min_width_values.include? width_value end.compact.join(" ") end |
#min_width_values ⇒ Object
40 41 42 |
# File 'lib/playbook/spacing.rb', line 40 def min_width_values %w[0% xs sm md lg xl xxl 0 none 100%] end |
#screen_size_values ⇒ Object
67 68 69 |
# File 'lib/playbook/spacing.rb', line 67 def screen_size_values %w[xs sm md lg xl default] end |
#spacing_options ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/playbook/spacing.rb', line 44 def { 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_props ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/playbook/spacing.rb', line 75 def spacing_props selected_props = .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 = [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_values ⇒ Object
63 64 65 |
# File 'lib/playbook/spacing.rb', line 63 def spacing_values %w[none xxs xs sm md lg xl auto initial inherit] end |