Open dwighthouse opened 5 years ago
If I had to guess, I suspect that the parser being used doesn't expect parens in mixin params.
@dwighthouse - thanks for this observation. I ran into this problem as well, but was able to use the following workaround: pass the variable name without var
and then use var
within my mixin. Picking pieces of the example...
@mixin heading-text($color: --my-default-color, $font-size: 4em) {
color: var($color); /* Use `var` within the mixin */
font-size: $font-size;
}
.color-variable {
--my-color: #555;
@include heading-text(--my-color); /* Pass variable name, no `var` */
background-color: var(--my-color);
}
It's not the nicest as it passes variable names instead of variables, but it worked for me in the mean-time. It also makes a non-variable default harder. In my case, I didn't need a default value.
Would like a real fix for this though, doubt we'll get one since the last release for this package was February 2018.
Passing CSS variable values to a mixin results in corrupted output. Both color and size type values were tested, with the resulting output of both always being a substring of the input from the start of the string to one character before the paran that is part of the CSS variable syntax. If I had to guess, I suspect that the parser being used doesn't expect parens in mixin params. You can see from the output, that CSS variables are being output correctly through the normal CSS usage, they only get corrupted when passed to a mixin.
Example, using mixin defined in the README:
Output:
I attempted to create a live code example on CodePen, as recommended, but I was unable to figure out how to tell CodePen to use PreCSS (or this plugin specifically) on top of PostCSS. However, my example compiles locally as described through PostCSS (version 7.0.16), which is using the PreCSS plugin (version 4.0.0, latest), which is using postcss-advanced-variables (version 3.0.0, latest). This is run via gulp-postcss (version 8.0.0, latest).