| 1 |
/* stylelint-disable scss/at-if-no-null */ |
| 2 |
@use "sass:map"; |
| 3 |
@use "sass:list"; |
| 4 |
@use "sass:string"; |
| 5 |
|
| 6 |
// Bootstrap functions |
| 7 |
// Utility mixins and functions for evalutating source code across our variables, maps, and mixins. |
| 8 |
|
| 9 |
// Ascending |
| 10 |
// Used to evaluate Sass maps like our grid breakpoints. |
| 11 |
@mixin _assert-ascending($map, $map-name) { |
| 12 |
$prev-key: null; |
| 13 |
$prev-num: null; |
| 14 |
@each $key, $num in $map { |
| 15 |
@if $prev-num == null { |
| 16 |
// Do nothing |
| 17 |
} @else if not comparable($prev-num, $num) { |
| 18 |
@warn "Potentially invalid value for #{$map-name}: This map must be in ascending order, but key '#{$key}' has value #{$num} whose unit makes it incomparable to #{$prev-num}, the value of the previous key '#{$prev-key}' !"; |
| 19 |
} @else if $prev-num >= $num { |
| 20 |
@warn "Invalid value for #{$map-name}: This map must be in ascending order, but key '#{$key}' has value #{$num} which isn't greater than #{$prev-num}, the value of the previous key '#{$prev-key}' !"; |
| 21 |
} |
| 22 |
$prev-key: $key; |
| 23 |
$prev-num: $num; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
// Descending |
| 28 |
// Used to evaluate Sass maps like our grid breakpoints. |
| 29 |
@mixin _assert-descending($map, $map-name) { |
| 30 |
$prev-key: null; |
| 31 |
$prev-num: null; |
| 32 |
@each $key, $num in $map { |
| 33 |
@if $prev-num == null or $prev-num == 0 { |
| 34 |
// Do nothing |
| 35 |
} @else if not comparable($prev-num, $num) { |
| 36 |
@warn "Potentially invalid value for #{$map-name}: This map must be in ascending order, but key '#{$key}' has value #{$num} whose unit makes it incomparable to #{$prev-num}, the value of the previous key '#{$prev-key}' !"; |
| 37 |
} @else if $prev-num <= $num { |
| 38 |
@warn "Invalid value for #{$map-name}: This map must be in descending order, but key '#{$key}' has value #{$num} which isn't lesser than #{$prev-num}, the value of the previous key '#{$prev-key}' !"; |
| 39 |
} |
| 40 |
$prev-key: $key; |
| 41 |
$prev-num: $num; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
// Starts at zero |
| 46 |
// Another grid mixin that ensures the min-width of the lowest breakpoint starts at 0. |
| 47 |
@mixin _assert-starts-at-zero($map) { |
| 48 |
$values: map.values($map); |
| 49 |
$first-value: list.nth($values, 1); |
| 50 |
@if $first-value != 0 { |
| 51 |
@warn "First breakpoint in `$grid-breakpoints` must start at 0, but starts at #{$first-value}."; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
// Replace `$search` with `$replace` in `$string` |
| 56 |
// Used on our SVG icon backgrounds for custom forms. |
| 57 |
// @author Hugo Giraudel |
| 58 |
// @param {String} $string - Initial string |
| 59 |
// @param {String} $search - Substring to replace |
| 60 |
// @param {String} $replace ('') - New value |
| 61 |
// @return {String} - Updated string |
| 62 |
@function str-replace($string, $search, $replace: "") { |
| 63 |
$index: string.index($string, $search); |
| 64 |
|
| 65 |
@if $index { |
| 66 |
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace); |
| 67 |
} |
| 68 |
|
| 69 |
@return $string; |
| 70 |
} |
| 71 |
|