Module: Playbook::Spacing
- Included in:
- KitBase
- Defined in:
- lib/playbook/spacing.rb
Constant Summary collapse
- MAX_WIDTH_VALUES =
%w[0% xs sm md lg xl xxl 0 none 100%].freeze
- MIN_WIDTH_VALUES =
%w[0% xs sm md lg xl xxl 0 none 100%].freeze
- WIDTH_VALUES =
%w[0% xs sm md lg xl xxl 0 none 100%].freeze
- GAP_VALUES =
%w[none xxs xs sm md lg xl].freeze
- SPACING_VALUES =
%w[none xxs xs sm md lg xl auto initial inherit].freeze
- SCREEN_SIZE_VALUES =
%w[xs sm md lg xl default].freeze
- BREAK_METHOD_VALUES =
%w[on at].freeze
- SCREEN_SIZES =
%w[xs sm md lg xl].freeze
- SPACING_HASH_SKIP_KEYS =
%i[default break].freeze
- SPACING_PROP_MAP =
{ 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", }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #break_method_values ⇒ Object
- #column_gap_options ⇒ Object
- #column_gap_props ⇒ Object
- #filter_classname(value) ⇒ Object
- #gap_options ⇒ Object
- #gap_props ⇒ Object
- #gap_values ⇒ 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
- #row_gap_options ⇒ Object
- #row_gap_props ⇒ Object
- #screen_size_values ⇒ Object
- #spacing_options ⇒ Object
- #spacing_props ⇒ Object
- #spacing_values ⇒ Object
- #width_options ⇒ Object
- #width_props ⇒ Object
- #width_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 23 24 25 26 |
# File 'lib/playbook/spacing.rb', line 5 def self.included(base) base.prop :gap base.prop :column_gap base.prop :row_gap 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 :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
122 123 124 |
# File 'lib/playbook/spacing.rb', line 122 def break_method_values BREAK_METHOD_VALUES end |
#column_gap_options ⇒ Object
87 88 89 |
# File 'lib/playbook/spacing.rb', line 87 def { column_gap: "column_gap" } end |
#column_gap_props ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/playbook/spacing.rb', line 193 def column_gap_props value = column_gap return nil unless value if value.is_a?(::Hash) css = +"" css << "column_gap_#{value[:default].underscore} " if value.key?(:default) && GAP_VALUES.include?(value[:default].to_s) value.each do |media_size, column_gap_spacing_value| css << "column_gap_#{media_size}_#{column_gap_spacing_value.underscore} " if SCREEN_SIZES.include?(media_size.to_s) && GAP_VALUES.include?(column_gap_spacing_value.to_s) end css.strip unless css.empty? elsif GAP_VALUES.include?(value.to_s) "column_gap_#{value.underscore}" end end |
#filter_classname(value) ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/playbook/spacing.rb', line 148 def filter_classname(value) if value.include?("%") value.gsub("%", "_percent") else value end end |
#gap_options ⇒ Object
83 84 85 |
# File 'lib/playbook/spacing.rb', line 83 def { gap: "gap" } end |
#gap_props ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/playbook/spacing.rb', line 177 def gap_props value = gap return nil unless value if value.is_a?(::Hash) css = +"" css << "gap_#{value[:default].underscore} " if value.key?(:default) && GAP_VALUES.include?(value[:default].to_s) value.each do |media_size, gap_spacing_value| css << "gap_#{media_size}_#{gap_spacing_value.underscore} " if SCREEN_SIZES.include?(media_size.to_s) && GAP_VALUES.include?(gap_spacing_value.to_s) end css.strip unless css.empty? elsif GAP_VALUES.include?(value.to_s) "gap_#{value.underscore}" end end |
#gap_values ⇒ Object
79 80 81 |
# File 'lib/playbook/spacing.rb', line 79 def gap_values GAP_VALUES end |
#max_width_options ⇒ Object
55 56 57 |
# File 'lib/playbook/spacing.rb', line 55 def { max_width: "mw" } end |
#max_width_props ⇒ Object
163 164 165 166 167 168 |
# File 'lib/playbook/spacing.rb', line 163 def max_width_props value = max_width return nil unless value "max_width_#{filter_classname(value)}" if MAX_WIDTH_VALUES.include?(value) end |
#max_width_values ⇒ Object
67 68 69 |
# File 'lib/playbook/spacing.rb', line 67 def max_width_values MAX_WIDTH_VALUES end |
#min_width_options ⇒ Object
59 60 61 |
# File 'lib/playbook/spacing.rb', line 59 def { min_width: "minw" } end |
#min_width_props ⇒ Object
156 157 158 159 160 161 |
# File 'lib/playbook/spacing.rb', line 156 def min_width_props value = min_width return nil unless value "min_width_#{filter_classname(value)}" if MIN_WIDTH_VALUES.include?(value) end |
#min_width_values ⇒ Object
71 72 73 |
# File 'lib/playbook/spacing.rb', line 71 def min_width_values MIN_WIDTH_VALUES end |
#row_gap_options ⇒ Object
91 92 93 |
# File 'lib/playbook/spacing.rb', line 91 def { row_gap: "row_gap" } end |
#row_gap_props ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/playbook/spacing.rb', line 209 def row_gap_props value = row_gap return nil unless value if value.is_a?(::Hash) css = +"" css << "row_gap_#{value[:default].underscore} " if value.key?(:default) && GAP_VALUES.include?(value[:default].to_s) value.each do |media_size, row_gap_spacing_value| css << "row_gap_#{media_size}_#{row_gap_spacing_value.underscore} " if SCREEN_SIZES.include?(media_size.to_s) && GAP_VALUES.include?(row_gap_spacing_value.to_s) end css.strip unless css.empty? elsif GAP_VALUES.include?(value.to_s) "row_gap_#{value.underscore}" end end |
#screen_size_values ⇒ Object
118 119 120 |
# File 'lib/playbook/spacing.rb', line 118 def screen_size_values SCREEN_SIZE_VALUES end |
#spacing_options ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/playbook/spacing.rb', line 95 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
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/playbook/spacing.rb', line 126 def spacing_props css = +"" SPACING_PROP_MAP.each do |prop_name, prefix| spacing_value = send(prop_name) next unless spacing_value if spacing_value.is_a?(::Hash) default_value = spacing_value[:default] break_value = spacing_value[:break] || BREAK_METHOD_VALUES.first spacing_value.each do |key, value| next if SPACING_HASH_SKIP_KEYS.include?(key) 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.empty? end |
#spacing_values ⇒ Object
114 115 116 |
# File 'lib/playbook/spacing.rb', line 114 def spacing_values SPACING_VALUES end |
#width_options ⇒ Object
63 64 65 |
# File 'lib/playbook/spacing.rb', line 63 def { width: "w" } end |
#width_props ⇒ Object
170 171 172 173 174 175 |
# File 'lib/playbook/spacing.rb', line 170 def width_props value = width return nil unless value "width_#{filter_classname(value)}" if WIDTH_VALUES.include?(value) end |
#width_values ⇒ Object
75 76 77 |
# File 'lib/playbook/spacing.rb', line 75 def width_values WIDTH_VALUES end |