-
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
Idea: Support declarative list expansion into selectors (syntax not decided yet) #1694
Comments
Well, personally I don't see anything "insane" there, "verbose" maybe. Actually we can get more syntax sugar by abstracting the whole thing into a generic mixin like this. Which can also be vastly improved if a feature like passing a block into a mixin via variable was added into LESS. So if it takes into considering of how this or similar (e.g. Regardless of all above, the last syntax you've proposed is actually quite heavy from an implementation point of view, notice that it not only introduces two new keywords ( |
I mostly agree with @seven-phases-max though I also don't mind the idea of
though having said that its a breaking change. it goes to
at the moment. |
Btw, I also like the idea of
But indeed there's not too much use of this in a real project since we cannot get these values into a variable/property (so it can only generate rulesets with the same content). But if we could, that also may open some interesting possibilities, taking certain selectors tricks into account (for example like this or this) |
I've been thinking about this and I would really like this in 2.0.0
along with
and some kind of selector parsing so you can do
and then a) any comma seperated list that gets passed to selector interpolation, it duplicates the ruleset n times and provides a variable "@listname-item". I think this is far more declarative and easy to use and worth the breaking change of people who maybe are doing
but I really don't think too many people will be doing that |
Agreed at least with the premise that we should eliminate more loop use cases and the general principle of this request. Not sure about syntax, though. |
Closing as duplicate of #1421. |
FYI - This is now supported by this PR - #3217 Works in the form of: @list: apple, satsuma, banana, pear;
@{list} {
.fruit-& {
content: "Just a test.";
}
} Outputs: .fruit-apple,
.fruit-satsuma,
.fruit-banana,
.fruit-pear {
content: "Just a test.";
} |
Looking at the new docs I see that list variables are supported.
@list: apple, satsuma, banana, pear;
I expect one of the most common use cases for lists is outputting a series of rules, such as these.
The current LESS syntax to do this however, is completely insane. ((Though I do understand it was an unintentional "feature"))
I think we should add some nice clean declarative syntaxes to handle the common cases where you'd think you want a for loop. ie: Something declarative like the
@when
idea was, rather than the if/else ideas which weren't.I haven't thought of the best syntax for this yet, and I'd like other ideas too.
The first and simplest possible syntax would be to auto-expand lists inside of selectors:
However this isn't that great because there's no obvious way to use the current value inside of the selector (ie: It would be an ugly hack to support
content: "Just a test @{item}";
orcontent: "Just a test @{fruit}";
) and it's rather non-obvious that this selector expands to four different rules instead of one.Another idea might be a syntax like this:
This one is rather straightforward, it properly supports an item variable, while also becoming flexible enough to do more than just
.fruit-@{fruit}
. Though it needs a bit of bike-shedding over whether to call it@expand
or something like@for
,@foreach
, or@each
, whether it should be@fruit in @list
or@list as @fruit
.Or maybe given the current style of when() maybe a syntax like this:
You could also make it a little more like
when (...)
by putting it directly on the.fruit-*
selector though that might read a little backwards (since the variable in the selector is declared in the each that comes 'after'.The text was updated successfully, but these errors were encountered: