UNPKG

2.24 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 // Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0
25 // We can't update this yet since GitLab uses SassC, which doesn't support math.div
26 // See https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1954#note_1078281533
27 $converted: $value / $font-size-base;
28
29 @return strip-unit($converted) * 1rem;
30}
31
32@function multiple-units-rem($values, $font-size-base) {
33 $rem-values: ();
34
35 @each $value in $values {
36 $rem-values: append($rem-values, single-unit-rem($value, $font-size-base));
37 }
38
39 @return $rem-values;
40}
41
42@function px-to-rem($px, $font-size-base: 16px) {
43 @if type-of($px) == 'number' {
44 @return single-unit-rem($px, $font-size-base);
45 } @else if type-of($px) == 'list' {
46 @return multiple-units-rem($px, $font-size-base);
47 } @else {
48 @return $px;
49 }
50}
51
52@function if-important($important) {
53 @return #{if($important, '!important', '')};
54}
55
56@function clamp-between($min, $max, $min-width: $breakpoint-md, $max-width: $breakpoint-xl) {
57 $min-width: px-to-rem($min-width);
58 $max-width: px-to-rem($max-width);
59
60 // Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0
61 // We can't update this yet since GitLab uses SassC, which doesn't support math.div
62 // See https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1954#note_1078281533
63 $slope: ($max - $min) / ($max-width - $min-width);
64 $intersection: (-$min-width * $slope) + $min;
65
66 // Use calc() inside of clamp() function to work around SassC
67 // compilation failure.
68 // See https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/2972
69 @return clamp(#{$min}, calc(#{$intersection} + #{$slope * 100vw}), #{$max});
70}