|
| 1 | +@import "../variables/root-variables"; |
| 2 | +@import "../functions/functions"; |
| 3 | +@import "../functions/map"; |
| 4 | + |
1 | 5 |
|
2 | 6 | @function get-expression-operator($expression) { |
3 | 7 | @each $operator in ('>=', '<=', '>', '<', '≥', '≤', '=') { |
4 | 8 | @if str-index($expression, $operator) { |
5 | 9 | @return $operator; |
6 | 10 | } |
7 | 11 | } |
| 12 | + |
| 13 | + @return ''; |
8 | 14 | } |
9 | 15 |
|
10 | 16 | @function get-expression-value($expression, $operator) { |
|
13 | 19 | @return $value; |
14 | 20 | } |
15 | 21 |
|
| 22 | +@function get-width-string($operator, $min: 0, $max: 0) { |
| 23 | + @if $operator == '≥' { $operator: '>='; } |
| 24 | + @if $operator == '≤' { $operator: '<='; } |
| 25 | + @if $operator == '=' { |
| 26 | + @if $max > 0 { |
| 27 | + @return ' (min-width: ' + $min + ') and (max-width: ' + $max + ')'; |
| 28 | + } @else { |
| 29 | + @return ' (min-width: ' + $min + ')'; |
| 30 | + } |
| 31 | + } @else if $operator == '<' { |
| 32 | + @return ' (max-width: ' + ($min - 1) + ')'; |
| 33 | + } @else if $operator == '>' { |
| 34 | + @return ' (min-width: ' + ($max + 1) + ')'; |
| 35 | + } @else if $operator == '<=' { |
| 36 | + @return ' (max-width: ' + $max + ')'; |
| 37 | + } @else if $operator == '>=' { |
| 38 | + @return ' (min-width: ' + $min + ')'; |
| 39 | + } |
| 40 | + |
| 41 | + @return ''; |
| 42 | +} |
| 43 | + |
16 | 44 | @function get-condition-string($viewport,$operator) { |
17 | 45 | @each $class, $min in $grid-breakpoints { |
18 | 46 | @if($class == $viewport) { |
19 | 47 | $max: map-get-next($grid-breakpoints,$class, 0); |
20 | | - @if $operator == '≥' { $operator: '>='; } |
21 | | - @if $operator == '≤' { $operator: '<='; } |
22 | | - @if $operator == '=' { |
23 | | - @if $max > 0 { |
24 | | - @return ' (min-width: ' + $min + ') and (max-width: ' + $max + ')'; |
25 | | - } @else { |
26 | | - @return ' (min-width: ' + $min + ')'; |
27 | | - } |
28 | | - } @else if $operator == '<' { |
29 | | - @return ' (max-width: ' + ($min - 1) + ')'; |
30 | | - } @else if $operator == '>' { |
31 | | - @return ' (min-width: ' + ($max + 1) + ')'; |
32 | | - } @else if $operator == '<=' { |
33 | | - @return ' (max-width: ' + $max + ')'; |
34 | | - } @else if $operator == '>=' { |
35 | | - @return ' (min-width: ' + $min + ')'; |
36 | | - } |
| 48 | + @return get-width-string($operator,$min,$max); |
37 | 49 | } |
38 | 50 | } |
39 | 51 |
|
40 | 52 | @return ''; |
41 | 53 | } |
42 | 54 |
|
43 | | -// Used with @include media("<sm",">xs") etc. |
44 | | -@mixin media($conditions...) { |
45 | | - $condition-string: ''; |
| 55 | +@function _media($conditions...) { |
| 56 | + $conditions-string: ""; |
46 | 57 | @each $condition in $conditions { |
47 | | - $operator: get-expression-operator($condition); |
48 | | - $value: get-expression-value($condition, $operator); |
49 | | - $condition-string: $condition-string + get-condition-string($value,$operator); |
50 | | - } |
51 | | - @media screen and #{$condition-string} { |
52 | | - @content |
| 58 | + // Basic String Conditions |
| 59 | + @if map-has-key($condition-map, $condition) { |
| 60 | + $conditions-string: $conditions-string + map-get($condition-map,$condition); |
| 61 | + } @else { |
| 62 | + $operator: get-expression-operator($condition); |
| 63 | + $value: get-expression-value($condition,$operator); |
| 64 | + // Breakpoint Based Conditions |
| 65 | + @if map-has-key($grid-breakpoints, $value) { |
| 66 | + $conditions-string: $conditions-string + get-condition-string($value,$operator); |
| 67 | + } @else { |
| 68 | + $conditions-string: $conditions-string + get-width-string($operator,$value,$value); |
| 69 | + } |
| 70 | + } |
53 | 71 | } |
54 | | -} |
55 | 72 |
|
56 | | -@mixin media-breakpoint-up($bp) { |
57 | | - @include media(">=#{$bp}") { |
58 | | - @content; |
59 | | - } |
| 73 | + @return $conditions-string; |
60 | 74 | } |
61 | 75 |
|
62 | | -@mixin media-breakpoint-down($bp) { |
63 | | - @include media("<=#{$bp}") { |
| 76 | +// Used with @include media("<sm",">xs") etc. |
| 77 | +@mixin media($conditions...) { |
| 78 | + @media #{_media($conditions)} { |
64 | 79 | @content; |
65 | 80 | } |
66 | 81 | } |
67 | 82 |
|
68 | 83 | @mixin touch() { |
69 | | - html.touch { |
| 84 | + @media #{_media("screen", "touch")} { |
70 | 85 | @content; |
71 | 86 | } |
72 | 87 | } |
|
0 commit comments