-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Properties, maps and each. Trying to generate CSS custom properties #3368
Comments
A simplest workaround would be to use a mixin instead of a DR to define the map, e.g.: .vars() {
b: black;
c: contrast($b);
}
:root {
each(.vars(), {
--@{key}: @value;
});
} (you can define both if @vars: {.vars}
Yes, I guess it's pretty obvious - though I still would count this as a bug (not sure if there's already a corresponding ticket, but looks like P.S. Alternatively you can turn the DR<->mixin conversion upside-down and hide it within @vars: {
b: black;
c: contrast($b);
}
:root {
.-() {@vars()}
each(.-(), {
--@{key}: @value;
});
} |
I don't think we ever discussed this as a direct requirement. Are there any possible side-effects of doing this? As in, if that change were made, could that break any code relying on current |
Well, yes, in that sense it's more a like a feature request then (I was just assuming that w/o this change, it would make more sense to advertise mixins as a primary method to define maps ;)
I suppose it will change the behavior of code like: @vars: {
b: black;
c: $b;
}
div {
result: @vars[c]; // -> white
b: white;
} (i.e. the issue is not |
Awesome, Thanks! Is there any reason not to use a mixin instead of a map? |
First of all, strictly speaking it's confusing to word it like "mixin instead of a map". "Map" (as well as "namespace") is a logical concept. Rulesets, mixins and "detached-rulesets" become a map only when you throw the To be honest I started to test the feature only yesterday, so I don't have enough data. The 6th variation of map: |
I'm not sure why args were not being evaluated anyway, which they should be for functions-- wait, maybe it's because root functions don't have args evaluated? Or is it that root functions aren't evaluated after other rules? 🤔 In any case, this fixes it, but it's worth a review. #3546 |
So I'm trying to combine the power of preprocessing with the versatility of CSS Custom Properties. The use case is a theming tool where Less is used to generate the base styles and user tweaks can be handled in the browser.
However this example breaks with the each loop returning the following error
error evaluating function each: Property '$background-color' is undefined
. I kind of understand why this is happening though. Do someone know of a different way to solve this?Here is a Codepen demo
The text was updated successfully, but these errors were encountered: