Skip to content

Commit 8d4baeb

Browse files
committed
refactor: replace unit() with math.unit()
1 parent d72a556 commit 8d4baeb

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

scss/forms/_form-control.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "sass:math";
12
@use "../variables" as *;
23
@use "../mixins/border-radius" as *;
34
@use "../mixins/box-shadow" as *;
@@ -63,7 +64,7 @@
6364
// https://github.com/twbs/bootstrap/issues/23307
6465
// TODO: we can remove this workaround once https://bugs.webkit.org/show_bug.cgi?id=198959 is resolved
6566
// Multiply line-height by 1em if it has no unit
66-
height: if(unit($input-line-height) == "", $input-line-height * 1em, $input-line-height);
67+
height: if(math.unit($input-line-height) == "", $input-line-height * 1em, $input-line-height);
6768

6869
// Android Chrome type="date" is taller than the other inputs
6970
// because of "margin: 1px 24px 1px 4px" inside the shadow DOM

scss/functions/_assert.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
@use "sass:math";
2+
13
// Ascending
24
// Used to evaluate Sass maps like our grid breakpoints.
35
@mixin assert-ascending($map, $map-name) {
46
$prev-key: null;
57
$prev-num: null;
68
@each $key, $num in $map {
7-
@if $prev-num == null or unit($num) == "%" or unit($prev-num) == "%" {
9+
@if $prev-num == null or math.unit($num) == "%" or math.unit($prev-num) == "%" {
810
// Do nothing
911
} @else if not comparable($prev-num, $num) {
1012
@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}' !";

scss/functions/_math.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:math";
2+
13
// Return valid calc
24
@function add($value1, $value2, $return-calc: true) {
35
@if $value1 == null {
@@ -67,8 +69,8 @@
6769
}
6870
}
6971
$result: $result * $factor * $sign;
70-
$dividend-unit: unit($dividend);
71-
$divisor-unit: unit($divisor);
72+
$dividend-unit: math.unit($dividend);
73+
$divisor-unit: math.unit($divisor);
7274
$unit-map: (
7375
"px": 1px,
7476
"rem": 1rem,

scss/vendor/_rfs.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// stylelint-disable scss/dimension-no-non-numeric-values
2+
@use "sass:math";
23

34
// SCSS RFS mixin
45
//
@@ -50,7 +51,7 @@ $rfs-safari-iframe-resize-bug-fix: false !default;
5051
$enable-rfs: true !default;
5152

5253
// Cache $rfs-base-value unit
53-
$rfs-base-value-unit: unit($rfs-base-value);
54+
$rfs-base-value-unit: math.unit($rfs-base-value);
5455

5556
@function divide($dividend, $divisor, $precision: 10) {
5657
$sign: if($dividend > 0 and $divisor > 0 or $dividend < 0 and $divisor < 0, 1, -1);
@@ -80,8 +81,8 @@ $rfs-base-value-unit: unit($rfs-base-value);
8081
}
8182
}
8283
$result: $result * $factor * $sign;
83-
$dividend-unit: unit($dividend);
84-
$divisor-unit: unit($divisor);
84+
$dividend-unit: math.unit($dividend);
85+
$divisor-unit: math.unit($divisor);
8586
$unit-map: (
8687
"px": 1px,
8788
"rem": 1rem,
@@ -103,7 +104,7 @@ $rfs-base-value-unit: unit($rfs-base-value);
103104
}
104105

105106
// Cache $rfs-breakpoint unit to prevent multiple calls
106-
$rfs-breakpoint-unit-cache: unit($rfs-breakpoint);
107+
$rfs-breakpoint-unit-cache: math.unit($rfs-breakpoint);
107108

108109
// Remove unit from $rfs-breakpoint for calculations
109110
@if $rfs-breakpoint-unit-cache == px {
@@ -201,7 +202,7 @@ $rfs-mq-property-height: if($rfs-mode == max-media-query, max-height, min-height
201202
}
202203
@else {
203204
// Cache $value unit
204-
$unit: if(type-of($value) == "number", unit($value), false);
205+
$unit: if(type-of($value) == "number", math.unit($value), false);
205206

206207
@if $unit == px {
207208
// Convert to rem if needed
@@ -234,7 +235,7 @@ $rfs-mq-property-height: if($rfs-mode == max-media-query, max-height, min-height
234235
$val: $val + " 0";
235236
} @else {
236237
// Cache $value unit
237-
$unit: if(type-of($value) == "number", unit($value), false);
238+
$unit: if(type-of($value) == "number", math.unit($value), false);
238239

239240
// If $value isn't a number (like inherit) or $value has a unit (not px or rem, like 1.5em) or $ is 0, just print the value
240241
@if not $unit or $unit != px and $unit != rem {

0 commit comments

Comments
 (0)