forked from necolas/griddle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgriddle-build.scss
74 lines (58 loc) · 2.21 KB
/
griddle-build.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
// =============================================================================
// Griddle functions
// =============================================================================
// Find the greatest common factor of two integers
@function gcf($a, $b) {
@if $b == 0 { @return $a; }
@else { @return gcf($b, $a % $b) }
}
// Check if a list contains a value
@function contains($list, $value) {
@if type-of($list) == list { @return not not index($list, $value); }
@else { @return $list == $value; }
}
// Fluid grid units
// USAGE: provide a space-separated list of integers, each of which represents
// the number of parts that make up a grid component. Optionally provide a
// modifier suffix that can be used to adjust grids in different contexts (e.g.
// viewport dimensions).
@mixin griddle-build($units, $modifier: '') {
/* Proportional units
========================================================================== */
/*
* Specify the proportional width of an object.
* Primarily for, but not limited to, use with `.grid__cell` components.
* Intentional redundancy build into each set of unit classes.
*/
@each $n in $units {
// Avoid creating rules like `.unit-12-12 {}`
$x: $n - 1;
@for $i from 1 through $x {
// Initialize variables
$i-r: 0;
$n-r: 0;
// Find the greatest common factor
$g: gcf($i, $n);
@if $g > 1 {
// Reduced value of $i
$i-r: $i/$g;
// Reduced value of $n
$n-r: $n/$g;
}
// Check if the reduced value of $n was also supplied in the list
// of units to be built
$canreduce: contains($units, $n-r);
// Create units based on fractions
.unit-#{$i}-#{$n}#{$modifier} {
// If this unit can be reduced then extend the previous rule
@if $canreduce {
@extend .unit-#{$i-r}-#{$n-r}#{$modifier};
}
// Otherwise create a new % width
@else {
width: percentage($i / $n);
}
}
}
}
}