Feature request for conditional values
See original GitHub issueI often find myself needing to apply one style if an argument is x, and another style if y .
The addition of CSS Guards in 1.5.0 made it easy to wrap a group of styles like so:
.my-thing {
& when (@my-option = true) {
color: white;
background: black;
display: block
}
}
However, the syntax seem excessive when it’s just one or two attributes in a style block. In PHP and JS, I am accustomed to the ternary operator syntax, and it seemed like it might easily fit into the Less language. Some examples:
@my-value: true;
.my-thing {
// if @my-value evaluates to true, then black. else, white.
color: (@my-value = true) ? black : white;
}
@my-other-value: false;
@my-color: (@my-other-value = true) ? black : white;
.my-other-thing {
color: @my-color;
}
// outputs
.my-thing {
color: black;
}
.my-other-thing {
color: white;
}
Any thoughts?
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:19 (10 by maintainers)
Top Results From Across the Web
Feature Request: conditionals | WordPress.org
Hello, Unsure of where to put feature requests, so here I am. Forminator is great (coming from Caldera ... 1) I would love...
Read more >Feature Request - I would love it if we could use variables in ...
Hi,. I believe that such functionality is already in place in Test Studio - the verification used in the conditional step can be...
Read more >HTTP conditional requests - MDN Web Docs - Mozilla
HTTP conditional requests are requests that are executed differently, depending on the value of specific headers. These headers define a ...
Read more >Feature Request: How to apply conditional logic to certain rows on ...
Feature Request : How to apply conditional logic to certain rows on configurable list? · Shorten the length of your form · Let...
Read more >Feature request: Form Maker: Allowing for conditional statements to ...
When I populate a dropdown list from a database table source, in the conditional fields I cannot populate the condition field that has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
also note: your current example is probably a bad use-case for using
&
e.g. this is shorter (though I do admit it duplicates the selector in the less)
Closing in favor of: https://github.com/less/less.js/issues/3019