Skip to content
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

Use a variable as a mixin lookup does not work #3370

Closed
lostkeys opened this issue Feb 27, 2019 · 3 comments
Closed

Use a variable as a mixin lookup does not work #3370

lostkeys opened this issue Feb 27, 2019 · 3 comments

Comments

@lostkeys
Copy link

I'm trying to make a IE comparability mode with Less, where a CSS Custom Prop is returned by default, or a static value if a flag is set to true. But I can't get it to work. I'm wondering if it's a bug or I'm doing something wrong?

I'm having a mixin act as a map, and then another mixin do the logic. But I cant get the "logic-mixin" to lookup the value in the "map-mixin".

Here is a simplified example without all the CSS Custom Props crap (codepen demo)

.vars() {
  background-color: #0000ff;
  color: contrast($background-color, #000, #fff);
}

.mixin(@val) {
  @return: .vars[@val]; // Does not work
  //@return: .vars[background-color]; // Removing the variable works 
}

div {
  display: inline-block;
  padding: 1rem;
  background-color: .mixin(background-color)[@return];
  color: .mixin(color)[@return];  
}

Here is a codepen with the complete use-case for context

@seven-phases-max
Copy link
Member

Docs:

One important thing to notice is that the value in [@lookup] is the key (variable) name @lookup, and is not evaluated as a variable.

I.e. .vars[@val]; will look for a variable named @val within .vars (obviously there's no).
To get to a property named by a value of the @val you'll need .vars[$@val] (Properties as Variables).

@seven-phases-max
Copy link
Member

Closing as not an issue (the documentation update request is open: less/less-docs#500)

@lostkeys
Copy link
Author

Ah that makes sense. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants