-
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
Feature request: support checking html element in guards #833
Comments
Although now that I think of it I could add an argument to the mixin to specify the element. It will require more declarations still though |
I think your suggestion sounds better - otherwise we open ourselves to having to add quite complex tests for the context of the mixin call just to save passing something to pattern match against,, |
as in #1174 it might be useful to be able to reference the current selectors in guards |
I don't get how this would work? How is it applied to that element? What is the keyword |
I suppose .set-margins(@font-size) when (& = ul) {
margin-left: @font-size * 2;
me: &;
}
ul {
.set-margins(33);
}
resulting in: ul {
margin-left: 66;
me: ul;
} I was pretty sure such FR (with |
What.... I don't get this at all.
... other than a very minute reduction in length of code, but that's traded for a much clearer explicit call, without unintended results of implementing this as a feature in general. So.... I say no, because the possible downsides are way greater than any possible benefit. |
Mmm... basically it's just regular "parent selector" (well, sort of) but also allowed to be used as property value (not just in selector string as it is now), e.g.: red {
color: &; // -> red
} |
@seven-phases-max o_O That wasn't the request. It was to guard against the selectors used by the calling block. |
It's basically the same thing, obviously any value in guard is a regular value so if it can be used in guards it also can be used anywhere... We don't have special "guard" values. :) |
@seven-phases-max ...Okay, but then there are even fewer cases where that would have any usefulness. |
Maybe. maybe not. Currently the only use-case I can imagine is something around #1694 (comment). |
Btw, this statement isn't true IMO:
A guard can have a detached ruleset, can it not? But a DR can't be used in place of a property's values, even though it's a value passed to a mixin. There are still rules about where that node type can be used, and |
It's artificially suppressed at the parsing stage. In fact if you assign a DR to a property within a plugin (i.e. bypassing the parsing stage) it will work (expanding to void though). Edit: |
@seven-phases-max Still, I think you're confusing the issue with your example. That's a whole other deal. Right now the only request is within mixin guards, and referencing I went through the thread in #1174, which IMO has a much better explanation / use case for this (that is: an actual use case - it would make sense to have closed this issue and left that one open, but nm). Similarly to my comment on that a while back, and what I noted again here, anything like h1, h2, h3, h4 {
// lots of shared less
& (when match(h1)) { // or however you would want to do this syntactically
color: blue;
}
& (when match(h2)) {
color: white;
}
& (when match(h3)) {
color: yellow;
}
& (when match(h4)) {
color: red;
}
} The reason why I say that is because Although, even |
Closing per discussion above (use-cases are welcome). |
It would be nice to be able to write a guard function for a mixin, that could check the html element that it is being declared for. It would look something like this:
This is part of a larger approach I am using to build a suite of typographic sizes and measures in to a kind of master mixin. It could be very powerful if there was a way of checking...
The text was updated successfully, but these errors were encountered: