In sass custom-properties are unfortunately just treated as a string, it doesn't associat a value.
However there are workarounds:
@function get($var) {
@return map-get($custom-properties, $var);
}
$custom-properties: ();
@each $key, $value in $custom-properties {
:root {
--#{$key}: #{$value};
}
}
Add any variable, you want to use within your Sass project and also be compiled to a custom-property, to this map: $custom-properties: ();
.
$custom-properties: (
'navbar-transparent': true,
//...
);
Now use get($var)
to acces said variables within your Sass project.
@function get($var) {
@return map-get($custom-properties, $var);
}
$custom-properties: (
'navbar-transparent': true,
);
@each $key, $value in $custom-properties {
:root {
--#{$key}: #{$value};
}
}
@if (get(navbar-transparent)) {
.nav-booking {
position: absolute;
width: 100%;
background: transparent;
padding-top: 20px;
}
} @else {
.nav-booking{
border-bottom: 2px solid #d6d1d180;
}
}
This will compile to:
:root {
--navbar-transparent: true;
}
.nav-booking {
position: absolute;
width: 100%;
background: transparent;
padding-top: 20px;
}
https://codepen.io/LudwigGeorgImmanuel/pen/dypaXyE