question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request for conditional values

See original GitHub issue

I 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:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeapagecommented, Feb 23, 2014

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)

@myvar: #edba1d;

// current way

.my-callout-box when ( lightness(@myvar) >= 60%) {
    background: black;
}
.my-callout-box when ( lightness(@myvar) < 60%) {
    background: white;
}
0reactions
matthew-deancommented, Jan 16, 2017
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found