| @use "sass:list"; |
| @use "sass:map"; |
| @use "../config" as *; |
| |
| // Breakpoint viewport sizes and media queries. |
| // |
| // Breakpoints are defined as a map of (name: minimum width), order from small to large: |
| // |
| // (xs: 0, sm: 576px, md: 768px, lg: 1024px, xl: 1280px, 2xl: 1536px) |
| // |
| // The map defined in the `$grid-breakpoints` global variable is used as the `$breakpoints` argument by default. |
| |
| // Name of the next breakpoint, or null for the last breakpoint. |
| // |
| // >> breakpoint-next(sm) |
| // md |
| // >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 1024px, xl: 1280px, 2xl: 1536px)) |
| // md |
| // >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl 2xl)) |
| // md |
| @function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map.keys($breakpoints)) { |
| $n: list.index($breakpoint-names, $name); |
| @if not $n { |
| @error "breakpoint `#{$name}` not found in `#{$breakpoint-names}`"; |
| } |
| @return if($n < list.length($breakpoint-names), list.nth($breakpoint-names, $n + 1), null); |
| } |
| |
| // Minimum breakpoint width. Null for the smallest (first) breakpoint. |
| // |
| // >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 1024px, xl: 1280px, 2xl: 1536px)) |
| // 576px |
| @function breakpoint-min($name, $breakpoints: $grid-breakpoints) { |
| $min: map.get($breakpoints, $name); |
| @return if($min != 0, $min, null); |
| } |
| |
| // Maximum breakpoint width for range media queries. |
| // Returns the breakpoint value to use as an upper bound in range queries. |
| // |
| // >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 1024px, xl: 1280px, 2xl: 1536px)) |
| // 576px |
| // >> breakpoint-max(xxl, (xs: 0, sm: 576px, md: 768px, lg: 1024px, xl: 1280px, 2xl: 1536px)) |
| // null |
| @function breakpoint-max($name, $breakpoints: $grid-breakpoints) { |
| @if $name == null { |
| @return null; |
| } |
| $max: map.get($breakpoints, $name); |
| @return if($max and $max > 0, $max, null); |
| } |
| |
| // Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front. |
| // Useful for making responsive utilities. |
| // |
| // >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 1024px, xl: 1280px, 2xl: 1536px)) |
| // "" (Returns a blank string) |
| // >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 1024px, xl: 1280px, 2xl: 1536px)) |
| // "-sm" |
| @function breakpoint-infix($name, $breakpoints: $grid-breakpoints) { |
| @return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}"); |
| } |
| |
| // Media of at least the minimum breakpoint width. No query for the smallest breakpoint. |
| // Makes the @content apply to the given breakpoint and wider. |
| @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) { |
| $min: breakpoint-min($name, $breakpoints); |
| @if $min { |
| @media (width >= $min) { |
| @content; |
| } |
| } @else { |
| @content; |
| } |
| } |
| |
| // Media of at most the maximum breakpoint width. No query for the largest breakpoint. |
| // Makes the @content apply to the given breakpoint and narrower. |
| @mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) { |
| $max: breakpoint-max($name, $breakpoints); |
| @if $max { |
| @media (width < $max) { |
| @content; |
| } |
| } @else { |
| @content; |
| } |
| } |
| |
| // Media that spans multiple breakpoint widths. |
| // Makes the @content apply between the min and max breakpoints |
| @mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) { |
| $min: breakpoint-min($lower, $breakpoints); |
| $max: breakpoint-max($upper, $breakpoints); |
| |
| @if $min != null and $max != null { |
| @media (width >= $min) and (width < $max) { |
| @content; |
| } |
| } @else if $max == null { |
| @include media-breakpoint-up($lower, $breakpoints) { |
| @content; |
| } |
| } @else if $min == null { |
| @include media-breakpoint-down($upper, $breakpoints) { |
| @content; |
| } |
| } |
| } |
| |
| // Media between the breakpoint's minimum and maximum widths. |
| // No minimum for the smallest breakpoint, and no maximum for the largest one. |
| // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower. |
| @mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) { |
| $min: breakpoint-min($name, $breakpoints); |
| $next: breakpoint-next($name, $breakpoints); |
| $max: breakpoint-max($next, $breakpoints); |
| |
| @if $min != null and $max != null { |
| @media (width >= $min) and (width < $max) { |
| @content; |
| } |
| } @else if $max == null { |
| @include media-breakpoint-up($name, $breakpoints) { |
| @content; |
| } |
| } @else if $min == null { |
| @include media-breakpoint-down($next, $breakpoints) { |
| @content; |
| } |
| } |
| } |