-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_mixins.scss
347 lines (272 loc) · 10.3 KB
/
_mixins.scss
1
2
3
4
5
6
7
8
9
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// =============================
// Core REM Sizing Mixin
// =============================
//
// Calculate the REM unit, and return both REMs and pixels to support older browsers.
//
// Parameter Description:
//
// $property - A string value which contains the property which you want to set a REM unit value for. // "font-size"
// $value - The value (in pixels) of the elements property you are setting the REM value for. // 12px
// $context - This value is mapped back to the $font-size-base variable set within the _settings.scss partial.
//
// Example Use:
//
// @include rem-sizing("font-size", 32px);
//
@mixin rem-sizing($property, $value, $context: $base-font-size) {
#{$property}: to-pixel($value);
#{$property}: calc-rem($value, $context);
}
// =============================
// Core Media Query Mixin
// =============================
//
// Add a media query which allows for multiple conditions.
//
// Parameter Description:
//
// $from - A integer value which relates to the min-width you would like the query to cover.
// $to - A integer value which relates to the max-width you would like the query to cover.
// $and - A string value containing additional conditions which may be required for the query.
//
// Example Use:
//
// @include media-query($from: 480, $to: 640, $and: '(orientation: landscape)') {
// color: red;
// }
//
// Example Use with Viewport Map:
//
// @include media-query($from: nth(map-get($viewport-values, lap), 1),
// $to: nth(map-get($viewport-values, lap), 2)) {
// .box {
// color: red;
// }
// }
//
@mixin media-query($from: false, $to: false, $and: false) {
$_from : 0;
$_to : 0;
$_and : $and or null;
$_query : null;
@if($from) {
$_from: calc-em($from);
}
@if($to) {
$_to: calc-em($to);
}
@if($_from or $_to or $_and) {
@if ($_from != 0) { $_query: '#{$_query} and (min-width: #{$_from})'; }
@if ($_to != 0) { $_query: '#{$_query} and (max-width: #{$_to})'; }
@if ($_and) { $_query: '#{$_query} and #{$_and}'; }
}
$_query: unquote(#{$_query});
@media all #{$_query} {
@content;
}
}
// =============================
// Core Generate Spacing Single Mixin
// =============================
//
// A singular instance of spacing properties. Can be used in individual classes to
// generate the calculated properties.
// Parameter Description:
//
// $property - A String of the CSS proprty that you would like to target.
// $units - A String of a unit that you would to output.
// $directions - A Map of directions that you would like to output ("top", "right", "bottom", "left").
//
// Example Use:
//
// @include generate-spacing-single("margin", "1/2", (top, bottom));
//
@mixin generate-spacing-single($property: 'padding', $unit: "1x", $directions: false) {
$operator: str-slice($unit, 2, 2);
@if map-count($directions) > 0 {
@each $position in $directions {
@if $operator == 'x' {
$amount: str-slice($unit, 1, 1);
@include rem-sizing(#{$property}-#{$position}, $base-spacing-unit * to-number($amount));
} @else if $operator == '/' {
$amount: str-slice($unit, -1, -1);
@include rem-sizing(#{$property}-#{$position}, $base-spacing-unit / to-number($amount));
} @else {
$amount: str-slice($unit, 1, 1);
#{$property}-#{$position}: to-number($amount);
}
}
} @else {
$amount: str-slice($unit, 1, 1);
@include rem-sizing(#{$property}, $base-spacing-unit * to-number(amount));
}
}
// =============================
// Core Generate Spacing Mixin
// =============================
//
// Generates the output for any spacing properties such as margin and padding.
// Parameter Description:
//
// $property - A String of the CSS proprty that you would like to target.
// $units - A Map of units that you would to output.
// $namespace - A String for optional class name.
//
// Example Use:
//
// @include generate-spacing("padding", ("1/2", "2x", "3x", "0"), "desk");
//
@mixin generate-spacing-batch($property: 'padding', $units: $global-spacing-values, $namespace: null) {
@each $unit in $units {
$_prop-namespace: str-slice($property, 1, 3);
@if $namespace != null {
@if $property == "margin" {
[data-#{$namespace}~="#{$_prop-namespace}-#{$unit}"] {
@include generate-spacing-single($property, $unit, ('right', 'bottom'));
}
} @else {
[data-#{$namespace}~="#{$_prop-namespace}-#{$unit}"] {
@include generate-spacing-single($property, $unit, ('top', 'right', 'bottom', 'left'));
}
}
} @else {
@if $property == "margin" {
[class~="#{$_prop-namespace}-#{$unit}"] {
@include generate-spacing-single($property, $unit, ('right', 'bottom'));
}
} @else {
[class~="#{$_prop-namespace}-#{$unit}"] {
@include generate-spacing-single($property, $unit, ('top', 'right', 'bottom', 'left'));
}
}
}
@each $direction, $positions in $global-spacing-directions {
@if $direction == false {
$direction: '';
} @else {
$direction: "-#{$direction}";
}
@if $namespace != null {
[data-#{$namespace}~="#{$_prop-namespace}#{$direction}-#{$unit}"] {
@include generate-spacing-single($property, $unit, $positions);
}
} @else {
[class~="#{$_prop-namespace}#{$direction}-#{$unit}"] {
@include generate-spacing-single($property, $unit, $positions);
}
}
}
}
}
// =============================
// Generate Grid Percentage Single Mixin
// =============================
//
// Generates grid percentages based classes/attributes based on the given viewport values passed.
// Parameter Description:
//
// $viewport-map - Map of viewport values to create.
// $property - String the element property to create.
// $namespace - String for the optional namespace of created attributes.
// $viewport - String for the viewport namespace of created attributes.
//
// Example Use:
//
// Generate Pull Utility Values:
//
// @include generate-grid-percentage-single(map-get($viewport-values, palm), 'pull', 'right', 'palm');
//
@mixin generate-grid-percentage-single($viewport-map, $namespace: null, $property: 'width', $viewport: null) {
$_cols: nth($viewport-map, 3);
$current-attribute: null;
$_namespace: if($namespace, '#{$namespace}-', null);
//
// Store columns in a map as processed, with global columns added first.
// Width is the Map key due to Sass limitations and allows is to easily find if it's a
// pre-existing class to avoid duplicates.
//
$length-storage: ();
// Once created a complete Map of existing columns, loop and output.
@while $_cols > 0 {
@for $i from 1 through ($_cols) {
// Generate the length.
$col-width: (100 / $_cols * $i);
$length: (percentage($col-width / 100));
// Generate the data attribute or class attribute dependent on if $viewport is set.
@if ($viewport) {
$current-attribute: "[data-#{$viewport}~='#{$_namespace}#{$i}/#{$_cols}']";
} @else {
$current-attribute: "[class~='#{$_namespace}#{$i}/#{$_cols}']";
}
@if $i == $_cols {
@if ($viewport) {
$current-attribute: "[data-#{$viewport}~='#{$_namespace}1x']";
} @else {
$current-attribute: "[class~='#{$_namespace}1x']";
}
} @else {
@if ($viewport) {
$current-attribute: "[data-#{$viewport}~='#{$_namespace}#{$i}/#{$_cols}']";
} @else {
$current-attribute: "[class~='#{$_namespace}#{$i}/#{$_cols}']";
}
}
// Empty class for scoping.
$new-attribute: "";
//
// Check if $length is not in $length-storage as a key.
// Note: Unquote on insert otherwise $current-attribute will be quoted by default
// and will cause output to also be quoted.
//
@if not map-has-key($length-storage, $length) {
$new-attribute: ($length: unquote($current-attribute));
} @else {
// Get list of matched attributes.
$attributes: map-get($length-storage, $length);
// Append $current-attribute to the $attributes as a comma-seperated list.
$new-attribute: ($length: append(unquote($current-attribute), $attributes, comma));
}
// Merge the $new-class into the $length-storage.
$length-storage: map-merge($length-storage, $new-attribute);
}
$_cols: $_cols - 1;
}
// Output all our created attributes held in $length-storage.
@each $length, $attributes in $length-storage {
#{$attributes} {
#{$property}: unquote($length);
}
}
}
// =============================
// Core Generate Grid Percentage Batch Mixin
// =============================
//
// Generates batches of grid percentages based classes/attributes based on the given viewport values passed.
// Parameter Description:
//
// $viewport-map - Map of viewport values to create.
// $property - String the element property to create.
// $namespace - String for the optional namespace of created classes.
//
// Example Use:
//
// Generate Pull Utility Values:
//
// @include generate-grid-percentage-batch($namespace: 'pull', $property: 'right');
//
// Generate Width Utility Values:
//
// @include generate-grid-percentage-batch();
//
@mixin generate-grid-percentage-batch($viewport-map: $viewport-values, $property: 'width', $namespace: null) {
$viewport-no-query: null;
@include generate-grid-percentage-single(map-get($viewport-values, desk), $namespace, $property);
@each $viewport, $viewport-val in $viewport-map {
@include media-query($from: nth($viewport-val, 1),
$to: nth($viewport-val, 2)) {
@include generate-grid-percentage-single($viewport-val, $namespace, $property, $viewport);
}
}
}