Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I solve this sass interpolation issue

Tags:

css

sass

angular

WARNING: You probably don't mean to use the color value white in interpolation here. It may end up represented as white, which will likely produce invalid CSS. Always quote color names when using them as strings or map keys (for example, "white"). If you really want to use the color value here, use '"" + $colorName'.

   ╷
93 │       .text-#{$colorName}-#{$shade} {
   │               ^^^^^^^^^^
   ╵
    src\assets\styles\scss\_palette.scss 93:15  @import
    stdin 44:9  

I tried something like this as recommended,

.text-#{'"" + $colorName'}-#{$shade} {

But just adding the quotes didn't work. I am using angular cli.

like image 649
LearnToday Avatar asked Aug 12 '19 03:08

LearnToday


People also ask

How do you use interpolation in sass?

Interpolation can be used almost anywhere in a Sass stylesheet to embed the result of a SassScript expression into a chunk of CSS. Just wrap an expression in #{} in any of the following places: Selectors in style rules. Property names in declarations.

What is CSS interpolation?

Linear interpolation is a formula used to find a value between two points on a line. In our case those two points are CSS values, like font-sizes, margins or widths, that we want to interpolate between over a set of viewport widths.


2 Answers

Recently upgraded to the Angular9 and was facing the same issue. In my case updting this

.#{$colorName}#{$hue}-bg {
        background-color: $color !important;
}

to

.#{"" + $colorName}#{$hue}-bg {
        background-color: $color !important;
}

worked.

like image 95
Sunil Garg Avatar answered Oct 12 '22 12:10

Sunil Garg


Found this post in a GitHub issue (https://github.com/sass/libsass/issues/2409#issuecomment-311932161). The underlying issue are unquoted map keys.

(Credits to @xzyfer.)

$testMap: (
-    white: (color: white) // white is a Color object
+    "white": (color: white) // "white" is a String object
);

@each $key in map-keys($testMap) {
    .test-btn-#{$key} {
        $colors: map_get($testMap, $key);

        color: map-get($colors, color);
    }
}
like image 10
strarsis Avatar answered Oct 12 '22 12:10

strarsis