Open mdmoreau opened 5 years ago
As a workaround, we're currently using background-color: color-mod(--var-black)
, this results in the color output as a static value: background-color: rgb(0, 0, 0)
@homburg that's an interesting concept. Maybe this library can provide a way of specifically hinting a variable should be converted to a static value?
:root {
--fa-search: "\F00D";
}
.my-icon {
font-family: FontAwesome;
content: static(var(--fa-search));
}
Expected output (even when preserve=true
)
.my-icon {
font-family: FontAwesome;
content: "\F00D";
}
+1 for this feature
I have a situation where I need to modify something in a :before
and :after
pseudo-element from JS; inaccessible normally, but can be modified if a css variable on its parent is used.
however, this is the only use case for it; we accept that it doesn't work in IE11-, since it's a bell-and-whistle. We would love not to have the overhead of all the other css variables being written out due to the broad preserve: true
; and the knock-on effect that postcss-calc
can no longer be used.
I agree with the approach suggested in https://github.com/postcss/postcss-custom-properties/issues/101#issuecomment-395874705 to disable preserve with a comment.
There are two primary use cases in which we use CSS custom properties:
A comment to preserve some custom properties and not others would be ideal.
Ended up creating https://github.com/mdmoreau/postcss-root-var which works similarly to what @garygreen described.
Somewhat related to https://github.com/postcss/postcss-custom-properties/issues/101.
Would it be possible to disable preserve on a single variable? I'm thinking maybe
var()
could be wrapped in another function that forces it to always write the actual variable value.My use case is similar to the issue above, where I'm trying to use a var as a fill color in an SVG. Would something like
n(var(--color))
ornvar(--color)
be within the scope of this plugin?