Lightweight CSS Framework for Building Apps and Websites https://crispy-css.com
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.

101 lines
1.9 KiB

5 years ago
  1. /**
  2. * functions
  3. *
  4. *
  5. *
  6. *
  7. * @author Björn Hase
  8. * @license http://opensource.org/licenses/MIT The MIT License
  9. * @link https://gitlab.tentakelfabrik.de/tentakelfabrik/crispy
  10. *
  11. */
  12. /**
  13. * px to em, wrapper of toRelatives
  14. *
  15. * @param {mixed} $values
  16. * @param {mixed} $base
  17. * @return {rem}
  18. */
  19. @function toEm($values, $base: $crispy__font-size) {
  20. @return toRelatives($values, 1em, $base);
  21. }
  22. /**
  23. * px to rem, wrapper of toRelatives
  24. *
  25. * @param {mixed} $values
  26. * @param {mixed} $base
  27. * @return {rem}
  28. */
  29. @function toRem($values, $base: $crispy__font-size) {
  30. @return toRelatives($values, 1rem, $base);
  31. }
  32. /**
  33. * values to relative
  34. *
  35. * @param {mixed} $values
  36. * @param {mixed} $unit
  37. * @param {mixed} $base
  38. * @return {number}
  39. */
  40. @function toRelatives($values, $unit, $base: $crispy__font-size) {
  41. $results: 0;
  42. @if type-of($values) == 'number' {
  43. $results: toRelative($values, $base) * $unit;
  44. } @else {
  45. $results: ();
  46. @each $value in $values {
  47. @if $value == 0 {
  48. $results: append($results, $value);
  49. }
  50. @else {
  51. $results: append($results, toRelative($value, $base) * $unit);
  52. }
  53. }
  54. }
  55. @return $results;
  56. }
  57. /**
  58. * to relative
  59. *
  60. * @param {mixed} $value
  61. * @param {mixed} $base
  62. * @return {number}
  63. */
  64. @function toRelative($value, $base: $crispy__font-size) {
  65. @return stripUnit($value) / stripUnit($base);
  66. }
  67. /**
  68. * strip unit from value
  69. *
  70. * @param {mixed} $value
  71. * @return {number}
  72. */
  73. @function stripUnit($value) {
  74. @return $value / ($value * 0 + 1);
  75. }
  76. /**
  77. * function: z-index
  78. *
  79. * uses map $crispy__z-index to get value by key
  80. *
  81. * @author Björn Hase
  82. *
  83. */
  84. @function zIndex($name) {
  85. @if map-has-key($crispy__z-index, $name) {
  86. @return map-get($crispy__z-index, $name);
  87. } @else {
  88. @warn 'There is no item "#{$name}" in this list; choose one of: #{$crispy__z-index}';
  89. @return null;
  90. }
  91. }