|
4 | 4 | @use 'breakpoints' as *; |
5 | 5 | @use 'themes' as *; |
6 | 6 |
|
7 | | -@mixin mq($size) { |
| 7 | +@function check-size($size, $name: 'breakpoint') { |
8 | 8 | @if (map.has-key($breakpoints, $size)) { |
9 | | - $breakpoint: map.get($breakpoints, $size); |
10 | | - @media screen and (min-width: $breakpoint) { |
11 | | - @content; |
12 | | - } |
| 9 | + @return map.get($breakpoints, $size); |
13 | 10 | } @else if (meta.type-of($size) == number) { |
14 | 11 | @if (math.is-unitless($size)) { |
15 | | - @error 'Provided value of #{$size} has no unit'; |
| 12 | + @return 'The value of #{$size} you provided for #{$name} is a number but has no unit. Please use a unit'; |
16 | 13 | } @else { |
17 | | - $breakpoint: $size; |
18 | | - @media screen and (min-width: $breakpoint) { |
19 | | - @content; |
20 | | - } |
| 14 | + @return $size; |
| 15 | + } |
| 16 | + } @else { |
| 17 | + @return 'The value of #{$size} you provided for #{$name} is not a key in the map. Please use a key from the map or a number with a unit'; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +@mixin mq($breakpoint-1, $min-or-max: min-width, $breakpoint-2: 0em) { |
| 22 | + $check-1: check-size($breakpoint-1, 'breakpoint-1'); |
| 23 | + @if (meta.type-of($check-1) == string) { |
| 24 | + @error $check-1; |
| 25 | + } |
| 26 | + |
| 27 | + $size-1: $check-1; |
| 28 | + @if ($min-or-max == min-width) { |
| 29 | + @media screen and (min-width: $size-1) { |
| 30 | + @content; |
| 31 | + } |
| 32 | + } @else if ($min-or-max == max-width) { |
| 33 | + @media screen and (max-width: $size-1) { |
| 34 | + @content; |
| 35 | + } |
| 36 | + } @else if ($min-or-max == between) { |
| 37 | + $check-2: check-size($breakpoint-2, 'breakpoint-2'); |
| 38 | + @if (meta.type-of($check-2) == string) { |
| 39 | + @error $check-2; |
| 40 | + } |
| 41 | + |
| 42 | + $size-2: $check-2; |
| 43 | + @media screen and (min-width: $size-1) and (max-width: $size-2) { |
| 44 | + @content; |
21 | 45 | } |
22 | 46 | } @else { |
23 | | - @error 'Provided value of #{$size} is not in the $breakponts map. Use a value from $breakpoints map or a number with a unit'; |
| 47 | + @error 'The value of #{$min-or-max} you provided for $min-or-max is invalid. Please use min-width, max-width or between'; |
24 | 48 | } |
25 | 49 | } |
26 | 50 |
|
|
0 commit comments