|
14 | 14 | /// @include poly-fluid-sizing('font-size', (576px: 22px, 768px: 24px, 992px: 34px)); |
15 | 15 | /// @author Jake Wilson <jake.e.wilson@gmail.com> |
16 | 16 | @mixin poly-fluid-sizing($property, $map) { |
| 17 | + $result: (); |
| 18 | + |
17 | 19 | // Get the number of provided breakpoints |
18 | 20 | $length: length(map-keys($map)); |
19 | 21 |
|
20 | 22 | // Error if the number of breakpoints is < 2 |
21 | 23 | @if ($length < 2) { |
22 | | - @error "poly-fluid-sizing() $map requires at least values" |
| 24 | + @error "poly-fluid-sizing() $map requires at least two values"; |
23 | 25 | } |
24 | 26 |
|
25 | 27 | // Sort the map by viewport width (key) |
26 | 28 | $map: map-sort($map); |
27 | 29 | $keys: map-keys($map); |
28 | 30 |
|
29 | 31 | // Minimum size |
30 | | - #{$property}: map-get($map, nth($keys,1)); |
| 32 | + #{$property}: map-get($map, nth($keys, 1)); |
31 | 33 |
|
32 | 34 | // Interpolated size through breakpoints |
33 | 35 | @for $i from 1 through ($length - 1) { |
34 | | - @media (min-width:nth($keys,$i)) { |
35 | | - $value1: map-get($map, nth($keys,$i)); |
36 | | - $value2: map-get($map, nth($keys,($i + 1))); |
37 | | - // If values are not equal, perform linear interpolation |
38 | | - @if ($value1 != $value2) { |
39 | | - #{$property}: linear-interpolation((nth($keys,$i): $value1, nth($keys,($i+1)): $value2)); |
40 | | - } @else { |
41 | | - #{$property}: $value1; |
| 36 | + $result: (); |
| 37 | + $low-values: map-get($map, nth($keys, $i)); |
| 38 | + $high-values: map-get($map, nth($keys, ($i + 1))); |
| 39 | + $total: length($low-values); |
| 40 | + $low-separator: list-separator(nth($keys, $i)); |
| 41 | + $high-separator: list-separator(nth($keys, $i + 1)); |
| 42 | + |
| 43 | + @if ($low-separator != $high-separator) { |
| 44 | + @error "poly-fluid-sizing() values must use the same separator"; |
| 45 | + } |
| 46 | + |
| 47 | + @media (min-width:nth($keys, $i)) { |
| 48 | + @if (length($low-values) != length($high-values)) { |
| 49 | + @error "poly-fluid-sizing() values must have same number args"; |
42 | 50 | } |
| 51 | + |
| 52 | + @for $j from 1 through $total { |
| 53 | + $value1: nth($low-values, $j); |
| 54 | + $value2: nth($high-values, $j); |
| 55 | + $key1: nth($keys, $i); |
| 56 | + $key2: nth($keys, $i + 1); |
| 57 | + |
| 58 | + @if ($value1 != $value2) { |
| 59 | + $result: append($result, linear-interpolation(($key1: $value1, $key2: $value2)), $low-separator); |
| 60 | + } @else { |
| 61 | + $result: append($result, $value1, $low-separator); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + #{$property}: $result; |
43 | 66 | } |
44 | 67 | } |
45 | 68 |
|
|
0 commit comments