_functions.less 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Bootstrap functions
  2. //
  3. // Utility mixins and functions for evaluating source code across our variables, maps, and mixins.
  4. @plugin "plugins/index.js";
  5. // LESS PORT: This plugin implements a function for returning a list of keys in a map, like Sass’
  6. // [`map-keys()`](http://sass-lang.com/documentation/Sass/Script/Functions.html#map_keys-instance_method)
  7. // function.
  8. @plugin "plugins/map-keys.js";
  9. // LESS PORT: This plugin implements `warn()` and `error()` functions like Sass’ `@warn` and
  10. // `@error`.
  11. @plugin "plugins/logger.js";
  12. // Ascending
  13. // Used to evaluate Sass maps like our grid breakpoints.
  14. //@mixin _assert-ascending($map, $map-name) {
  15. // $prev-key: null;
  16. // $prev-num: null;
  17. // @each $key, $num in $map {
  18. // @if $prev-num == null or unit($num) == "%" or unit($prev-num) == "%" {
  19. // // Do nothing
  20. // } @else if not comparable($prev-num, $num) {
  21. // @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}' !";
  22. // } @else if $prev-num >= $num {
  23. // @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}' !";
  24. // }
  25. // $prev-key: $key;
  26. // $prev-num: $num;
  27. // }
  28. //}
  29. // Starts at zero
  30. // Another grid mixin that ensures the min-width of the lowest breakpoint starts at 0.
  31. //@mixin _assert-starts-at-zero($map) {
  32. // $values: map-values($map);
  33. // $first-value: nth($values, 1);
  34. // @if $first-value != 0 {
  35. // @warn "First breakpoint in `$grid-breakpoints` must start at 0, but starts at #{$first-value}.";
  36. // }
  37. //}
  38. // Replace `$search` with `$replace` in `$string`
  39. // Used on our SVG icon backgrounds for custom forms.
  40. //
  41. // @author Hugo Giraudel
  42. // @param {String} $string - Initial string
  43. // @param {String} $search - Substring to replace
  44. // @param {String} $replace ('') - New value
  45. // @return {String} - Updated string
  46. //@function str-replace($string, $search, $replace: "") {
  47. // $index: str-index($string, $search);
  48. //
  49. // @if $index {
  50. // @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
  51. // }
  52. //
  53. // @return $string;
  54. //}
  55. // See https://codepen.io/kevinweber/pen/dXWoRw
  56. //@function escape-svg($string) {
  57. // @if str-index($string, "data:image/svg+xml") {
  58. // @each $char, $encoded in $escaped-characters {
  59. // $string: str-replace($string, $char, $encoded);
  60. // }
  61. // }
  62. //
  63. // @return $string;
  64. //}
  65. @plugin "plugins/escape-svg.js";
  66. // Color contrast
  67. //@function color-yiq($color) {
  68. // $r: red($color);
  69. // $g: green($color);
  70. // $b: blue($color);
  71. //
  72. // $yiq: (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
  73. //
  74. // @if ($yiq >= 150) {
  75. // @return #111;
  76. // } @else {
  77. // @return #fff;
  78. // }
  79. //}
  80. @plugin "plugins/color-yiq.js";
  81. // Retreive color Sass maps
  82. //@function color($key: "blue") {
  83. // @return map-get($colors, $key);
  84. //}
  85. @plugin "plugins/color.js";
  86. //@function theme-color($key: "primary") {
  87. // @return map-get($theme-colors, $key);
  88. //}
  89. @plugin "plugins/theme-color.js";
  90. //@function gray($key: "100") {
  91. // @return map-get($grays, $key);
  92. //}
  93. @plugin "plugins/gray.js";
  94. // Request a theme color level
  95. //@function theme-color-level($color-name: "primary", $level: 0) {
  96. // $color: theme-color($color-name);
  97. // $color-base: if($level > 0, #000, #fff);
  98. // $level: abs($level);
  99. //
  100. // @return mix($color-base, $color, $level * $theme-color-interval);
  101. //}
  102. @plugin "plugins/theme-color-level.js";
  103. // Return valid calc
  104. //@function add($value1, $value2, $return-calc: true) {
  105. // @if $value1 == null {
  106. // @return $value2;
  107. // }
  108. //
  109. // @if $value2 == null {
  110. // @return $value1;
  111. // }
  112. //
  113. // @if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) {
  114. // @return $value1 + $value2;
  115. // }
  116. //
  117. // @return if($return-calc == true, calc(#{$value1} + #{$value2}), $value1 + unquote(" + ") + $value2);
  118. //}
  119. //
  120. //@function subtract($value1, $value2, $return-calc: true) {
  121. // @if $value1 == null and $value2 == null {
  122. // @return null;
  123. // }
  124. //
  125. // @if $value1 == null {
  126. // @return -$value2;
  127. // }
  128. //
  129. // @if $value2 == null {
  130. // @return $value1;
  131. // }
  132. //
  133. // @if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) {
  134. // @return $value1 - $value2;
  135. // }
  136. //
  137. // @return if($return-calc == true, calc(#{$value1} - #{$value2}), $value1 + unquote(" - ") + $value2);
  138. //}
  139. @plugin "plugins/valid-calc.js";