Skip to content

Feature request for conditional values #1894

@skyshab

Description

@skyshab

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions