Skip to content

Commit 87b1d57

Browse files
committed
Refactor Sass inline if() to @if blocks to get ready for native CSS if()
After this change, there should be no more warnings in the console about the `if()` syntax.
1 parent fce2ee6 commit 87b1d57

3 files changed

Lines changed: 40 additions & 24 deletions

File tree

src/styles/_utilities.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
@each $breakpoint in map.keys(breakpoint-settings.$values) {
99
@include breakpoint.up($breakpoint) {
10-
$infix: if(map.get(breakpoint-settings.$values, $breakpoint) == 0, "", "-#{$breakpoint}");
10+
$infix: "";
11+
12+
@if map.get(breakpoint-settings.$values, $breakpoint) != 0 {
13+
$infix: "-#{$breakpoint}";
14+
}
1115

1216
@each $key, $utility in utility-settings.$map {
1317
@if meta.type-of($utility) == "map" and (map.get($utility, responsive) == true or $infix == "") {

src/styles/tools/_collections.scss

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,29 @@
6363
$properties,
6464
) {
6565
@each $property in $properties {
66-
$modifier: if($modifier-value, "--" + $modifier-value, "");
67-
$state: if($interaction-state, "--" + $interaction-state, "");
66+
$fallback-custom-property: "";
67+
$modifier: "";
68+
$state: "";
69+
70+
@if $interaction-state and $interaction-state == "disabled" {
71+
$fallback-custom-property: ", var(--"
72+
+ $prefix
73+
+ $component-name
74+
+ $modifier
75+
+ "--"
76+
+ $variant-value
77+
+ "--default__"
78+
+ $property
79+
+ ")";
80+
}
81+
82+
@if $modifier-value {
83+
$modifier: "--" + $modifier-value;
84+
}
85+
86+
@if $interaction-state {
87+
$state: "--" + $interaction-state;
88+
}
6889

6990
// 1.
7091
--#{$prefix}local-#{$property}:
@@ -80,19 +101,7 @@
80101
+ "__"
81102
+ $property
82103
}
83-
#{if(
84-
$interaction-state and $interaction-state == "disabled",
85-
", var(--"
86-
+ $prefix
87-
+ $component-name
88-
+ $modifier
89-
+ "--"
90-
+ $variant-value
91-
+ "--default__"
92-
+ $property
93-
+ ")",
94-
""
95-
)}
104+
#{$fallback-custom-property}
96105
); // 2.
97106
}
98107
}
@@ -202,14 +211,15 @@
202211
$inherit-link-color: false,
203212
$properties,
204213
) {
205-
$modifier-class-name:
206-
if(
207-
$modifier-name and $modifier-value,
208-
".isRoot#{rui-string.capitalize($modifier-name)}#{rui-string.capitalize($modifier-value)}",
209-
""
210-
);
214+
$modifier-class-name: "";
211215
$variant-class-name: ".isRoot#{rui-string.capitalize($variant-name)}#{rui-string.capitalize($variant-value)}";
212216

217+
@if $modifier-name and $modifier-value {
218+
$modifier-class-name: ".isRoot"
219+
+ #{rui-string.capitalize($modifier-name)}
220+
+ #{rui-string.capitalize($modifier-value)};
221+
}
222+
213223
#{$modifier-class-name}#{$variant-class-name} {
214224
@if $generate-interaction-states {
215225
$interaction-state-selector-map: (

src/styles/tools/_utilities.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
@each $key, $value in $values {
1717
$properties: map.get($utility, property);
1818
$property-class: map.get($utility, class);
19+
$property-class-modifier: "";
1920

20-
// Don't prefix if value key is null (e.g. with shadow class)
21-
$property-class-modifier: if($key, "-" + $key, "");
21+
@if $key {
22+
$property-class-modifier: "-" + $key;
23+
}
2224

2325
.#{$property-class + $infix + $property-class-modifier} {
2426
@each $property in $properties {

0 commit comments

Comments
 (0)