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

Passing ruleset to mixin #1420

Closed
StreetStrider opened this issue Jul 12, 2013 · 3 comments
Closed

Passing ruleset to mixin #1420

StreetStrider opened this issue Jul 12, 2013 · 3 comments

Comments

@StreetStrider
Copy link

Is there any way to pass rulesets to mixins (in common, save rulesets in variables, makin them first-class citizens)?

For instance, I want to customize color of placeholder:

.placeholder (@color) {
  &::-webkit-input-placeholder { color: @color; }
  &:-moz-placeholder { color: @color; }
  &::-moz-placeholder { color: @color; }
  &:-ms-input-placeholder { color: @color; }
}

But what if we need to customize set of properties. It is possible but providing all of them by parameters. In common it would be useful to pass ruleset.

.placeholder (@ruleset) {
  &::-webkit-input-placeholder { /* expand @ruleset it here */ }
}
@SomMeri
Copy link
Member

SomMeri commented Jul 15, 2013

What you ask for is not currently possible. There is an open issue on similar topic #965 , feel free to add your opinions or +1 there.

However, there is a possible workaround: Each less mixin sees its caller scope. E.g. following will work

// This mixins requires ruleset to be defined in callers scope
.placeholder () {
  &::-webkit-input-placeholder { 
    // use ruleset - it is supposed to be defined in caller
    .ruleset(); 
 }
}

// usage example
#use-place{
  // ruleset defined in caller
  .ruleset(){
    color: red;
  }
  // call the mixin
  .placeholder();
}

and produce this:

#use-place::-webkit-input-placeholder {
  color: red;
}

@SomMeri
Copy link
Member

SomMeri commented Jul 15, 2013

I'm closing this as duplicate of #965 . Please, leave comment or re-open if you disagree.

@SomMeri SomMeri closed this as completed Jul 15, 2013
@StreetStrider
Copy link
Author

Thanks for help, got food for thought about scopes.

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