Skip to content

Commit d0d392c

Browse files
authored
Merge pull request #8 from Jakobud/develop
Develop
2 parents c83f97b + 5c2dcb2 commit d0d392c

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Using Poly Fluid Sizing on `font-size` is an obvious use case. But it can be use
5454
section {
5555
@include poly-fluid-sizing('margin-right', (768px:40px, 1024px:60px));
5656
}
57+
58+
blockquote {
59+
@include poly-fluid-sizing('padding', (768px:30px 15px, 1024px:50px 25px));
60+
}
5761
```
5862

5963
## SASS map order
@@ -69,7 +73,6 @@ article {
6973
## Limitations
7074

7175
* You can't mix value types. For example, trying to use `2em` `font-size` @ `786px` viewport width. SASS just really won't know what to do mathematically when 1 value is using `em` and the other is using `px`.
72-
* You can't pass a CSS list of values. For example when specifying `padding: 50px 20px 30px 20px`. If you want different values like this, you need to break it out into individual properties `padding-top`, `padding-right`, etc... I'm pretty sure this could be solved.
7376

7477
## Coverage
7578

_poly-fluid-sizing.scss

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,55 @@
1414
/// @include poly-fluid-sizing('font-size', (576px: 22px, 768px: 24px, 992px: 34px));
1515
/// @author Jake Wilson <jake.e.wilson@gmail.com>
1616
@mixin poly-fluid-sizing($property, $map) {
17+
$result: ();
18+
1719
// Get the number of provided breakpoints
1820
$length: length(map-keys($map));
1921

2022
// Error if the number of breakpoints is < 2
2123
@if ($length < 2) {
22-
@error "poly-fluid-sizing() $map requires at least values"
24+
@error "poly-fluid-sizing() $map requires at least two values";
2325
}
2426

2527
// Sort the map by viewport width (key)
2628
$map: map-sort($map);
2729
$keys: map-keys($map);
2830

2931
// Minimum size
30-
#{$property}: map-get($map, nth($keys,1));
32+
#{$property}: map-get($map, nth($keys, 1));
3133

3234
// Interpolated size through breakpoints
3335
@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";
4250
}
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;
4366
}
4467
}
4568

0 commit comments

Comments
 (0)