Layout von Websiten mit Bootstrap und Foundation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_functions.scss 4.0KB

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