UNPKG

1.71 kBSCSSView Raw
1/*
2* SASS preserves units in arithmetic operations. For example:
3* 12em * 0 = 0em. This function return the unit of a numeric value.
4*
5* For more examples, see: https://codepen.io/paulgv/pen/XWrqMgQ
6*/
7@function extract-unit($number) {
8 @return $number * 0 + 1;
9}
10
11@function strip-unit($number) {
12 @if type-of($number) == 'number' and not unitless($number) {
13 @return $number / extract-unit($number);
14 }
15
16 @return $number;
17}
18
19@function single-unit-rem($value, $font-size-base) {
20 @if (extract-unit($value) != 1px) {
21 @return $value;
22 }
23
24 $converted: $value / $font-size-base;
25
26 @return strip-unit($converted) * 1rem;
27}
28
29@function multiple-units-rem($values, $font-size-base) {
30 $rem-values: ();
31
32 @each $value in $values {
33 $rem-values: append($rem-values, single-unit-rem($value, $font-size-base));
34 }
35
36 @return $rem-values;
37}
38
39@function px-to-rem($px, $font-size-base: 16px) {
40 @if type-of($px) == 'number' {
41 @return single-unit-rem($px, $font-size-base);
42 } @else if type-of($px) == 'list' {
43 @return multiple-units-rem($px, $font-size-base);
44 } @else {
45 @return $px;
46 }
47}
48
49@function if-important($important) {
50 @return #{if($important, '!important', '')};
51}
52
53@function clamp-between($min, $max, $min-width: $breakpoint-md, $max-width: $breakpoint-xl) {
54 $min-width: px-to-rem($min-width);
55 $max-width: px-to-rem($max-width);
56
57 $slope: ($max - $min) / ($max-width - $min-width);
58 $intersection: (-$min-width * $slope) + $min;
59
60 // Use calc() inside of clamp() function to work around SassC
61 // compilation failure.
62 // See https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/2972
63 @return clamp(#{$min}, calc(#{$intersection} + #{$slope * 100vw}), #{$max});
64}