Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom properties (--*): CSS variables #4

Closed
moehoward opened this issue Sep 19, 2021 · 6 comments
Closed

Custom properties (--*): CSS variables #4

moehoward opened this issue Sep 19, 2021 · 6 comments

Comments

@moehoward
Copy link

Installed product versions

  • Visual Studio: [2022 Community]
  • This extension: [example 1.13.4]

Description

Compilation fails when a custom CSS properties uses a variable.

Steps to recreate

  1. Create a SCSS file.
  2. Create a style within a SCSS file that uses a custom CSS property with a variable.

Current behavior

The "variable name" rather than the "value" gets compiled into the CSS file.

Expected behavior

The CSS should display:
.my-class {
--mdc-theme-primary: #4caf50;
}

But instead displays:
.my-class {
--mdc-theme-primary: $medium-green;
}

@failwyn
Copy link
Owner

failwyn commented Sep 20, 2021

Do you know if this worked on the 2019 version?

also, purely out of curiosity, is there an advantage to using custom properties instead of sass properties?

@moehoward
Copy link
Author

It worked perfectly well in VS 2019 (for years).
Hence, I noticed the error when I upgraded.

Go to https://jsonformatter.org/scss-to-css and type:

$var-name: green;
p {
--my-custom-color: $var-name;
}

See the result to the right.
See the result in WebCompiler2019 (a.k.a. WebCompiler)
See the result in WebCompiler2022.

More good info here:
https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
https://developer.mozilla.org/en-US/docs/Web/CSS/--*

Sass has advantages over css and that's the whole point using WebCompiler - right?
:<)

@failwyn
Copy link
Owner

failwyn commented Sep 20, 2021

I'll take a look to see if I can identify what changed during the upgrade, it makes it easier to track down the issue knowing if it worked in 2019.

I was wondering about the mixing of variable types, the custom properties with the sass variables; I haven't used custom properties and was just wondering if I was missing something with them.

@failwyn
Copy link
Owner

failwyn commented Sep 20, 2021

It looks like this was caused by a change to node-sass

sass/node-sass#2627
sass/libsass#2621
https://sass-lang.com/documentation/style-rules/declarations#custom-properties

Can you try the following and let me know if it works?

$var-name: green;
p {
--my-custom-color: #{$var-name};
}

@moehoward
Copy link
Author

Pingo that was it!
But dang, they moved my cheese!

So instead of using (which worked in Web Compiler 2019):
$var-name: green;
p {
--my-custom-color: $var-name;
}

I now have to use (in Web Compiler 2022):
$var-name: green;
p {
--my-custom-color: #{$var-name};
}

Well, it's obvious I suck at keeping current with Sass.
https://sass-lang.com/documentation/interpolation

Thanks a Million!

@failwyn
Copy link
Owner

failwyn commented Sep 20, 2021

I hate when they move the cheese!

// I'm not gonna lie, I haven't been keeping current with it either, I should go peruse the documentation to see what I'm missing out on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants