| 1 |
@use "sass:list"; |
| 2 |
@use "sass:map"; |
| 3 |
|
| 4 |
// Breakpoint viewport sizes and media queries. |
| 5 |
// Breakpoints are defined as a map of (name: minimum width), order from small to large: |
| 6 |
// (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px) |
| 7 |
// The map defined in the `$grid-breakpoints` global variable is used as the `$breakpoints` argument by default. |
| 8 |
|
| 9 |
// Name of the next breakpoint, or null for the last breakpoint. |
| 10 |
// >> breakpoint-next(sm) |
| 11 |
// md |
| 12 |
// >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) |
| 13 |
// md |
| 14 |
// >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl)) |
| 15 |
// md |
| 16 |
@function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) { |
| 17 |
$n: list.index($breakpoint-names, $name); |
| 18 |
@return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null); |
| 19 |
} |
| 20 |
|
| 21 |
// Minimum breakpoint width. Null for the smallest (first) breakpoint. |
| 22 |
// >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) |
| 23 |
// 576px |
| 24 |
@function breakpoint-min($name, $breakpoints: $grid-breakpoints) { |
| 25 |
$min: map.get($breakpoints, $name); |
| 26 |
@return if($min != 0, $min, null); |
| 27 |
} |
| 28 |
|
| 29 |
// Maximum breakpoint width. Null for the largest (last) breakpoint. |
| 30 |
// The maximum value is calculated as the minimum of the next one less 0.02px |
| 31 |
// to work around the limitations of `min-` and `max-` prefixes and viewports with fractional widths. |
| 32 |
// See https://www.w3.org/TR/mediaqueries-4/#mq-min-max |
| 33 |
// Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari. |
| 34 |
// See https://bugs.webkit.org/show_bug.cgi?id=178261 |
| 35 |
// >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) |
| 36 |
// 767.98px |
| 37 |
@function breakpoint-max($name, $breakpoints: $grid-breakpoints) { |
| 38 |
$next: breakpoint-next($name, $breakpoints); |
| 39 |
@return if($next, breakpoint-min($next, $breakpoints) - 0.02px, null); |
| 40 |
} |
| 41 |
|
| 42 |
// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash infront. |
| 43 |
// Useful for making responsive utilities. |
| 44 |
// >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) |
| 45 |
// "" (Returns a blank string) |
| 46 |
// >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) |
| 47 |
// "-sm" |
| 48 |
@function breakpoint-infix($name, $breakpoints: $grid-breakpoints) { |
| 49 |
@return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}"); |
| 50 |
} |
| 51 |
|
| 52 |
// Media of at least the minimum breakpoint width. No query for the smallest breakpoint. |
| 53 |
// Makes the @content apply to the given breakpoint and wider. |
| 54 |
@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) { |
| 55 |
$min: breakpoint-min($name, $breakpoints); |
| 56 |
@if $min { |
| 57 |
@media (min-width: $min) { |
| 58 |
@content; |
| 59 |
} |
| 60 |
} @else { |
| 61 |
@content; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
// Media of at most the maximum breakpoint width. No query for the largest breakpoint. |
| 66 |
// Makes the @content apply to the given breakpoint and narrower. |
| 67 |
@mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) { |
| 68 |
// NOTE: Changed $max to $min to change 'mobile first' to 'desktop first' |
| 69 |
$min: breakpoint-min($name, $breakpoints); |
| 70 |
@if $min { |
| 71 |
@media (max-width: $min) { |
| 72 |
@content; |
| 73 |
} |
| 74 |
} @else { |
| 75 |
@content; |
| 76 |
} |
| 77 |
} |
| 78 |
|