I'm trying to pass some CSS Custom Properties to a SASS Mixin. I'm able use the variables when applied directly in the styling I want. But when I try to use a variable in an If statement, it doesn't work.
Mixin Example:
@mixin bg-color($hue, $status) {
background: hsl($hue, 50%, 50%); // $hue works as expected
@if $status == 'danger' { // doesn't work!
color: 'red';
} @else if $status == 'warning' { // doesn't work!
color: 'orange';
} @else { // always enters the else branch
color: 'black';
}
}
CSS:
:root {
--hue: 195;
--status: 'default';
}
.demo {
@include bg-color(var(---hue), var(---status));
}
If I manually add the status value to the mixin, it works:
.demo {
@include bg-color(var(---hue), 'danger');
}
Any idea what might be the issue?
UPDATE: As @temani-afif mentioned, this approach isn't possible because SASS files are compiled before CSS variables are used.