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

Mixin delegates #2331

Closed
kreopt opened this issue Dec 10, 2014 · 3 comments
Closed

Mixin delegates #2331

kreopt opened this issue Dec 10, 2014 · 3 comments

Comments

@kreopt
Copy link

kreopt commented Dec 10, 2014

Not sure if this feature is not implemented, but i don't find the way to do this and issues creaded earlier.

I'd like to write some generic mixins taking other mixins as parameters such this:

.clickable(@hoverEffect, @activeEffect){
   &:hover{.@{hoverEffect}();}
   &:active{.@{activeEffect}();}
}

.active_delegate(){background:#aaa;/* something more complicated here...*/}
.hover_delegate(){background:#ddd;/*...*/}
.active_delegate--dark(){background:#666;/*...*/}
.hover_delegate--dark(){background:#333;/*...*/}

.button{
  background: #fff;
  .clickable(hover_delegate, active_delegate);
}

.button--dark{
  background:#000;
  .clickable(hover_delegate--dark, active_delegate--dark);
}
@seven-phases-max
Copy link
Member

See #965 (and closely related discussion started at #1648 (comment)). Well, no, you can't call a mixin like that: .@{hoverEffect}();. The goal can be achieved with "detached rulesets" though, e.g.:

.clickable(@hoverEffect, @activeEffect) {
    &:hover  {@hoverEffect();}
    &:active {@activeEffect();}
}

@active_delegate:       {background: #aaa};
@hover_delegate:        {background: #ddd};
@active_delegate--dark: {background: #666};
@hover_delegate--dark:  {background: #333};

.button {
    background: #fff;
   .clickable(@hover_delegate, @active_delegate);
}

.button--dark {
    background: #000;
   .clickable(@hover_delegate--dark, @active_delegate--dark);
}

And if you still need those delegates to be available as mixins you can wrap them into DRs right at the point of passing into .clickable as parameters:

.clickable(@hoverEffect, @activeEffect) {
    &:hover  {@hoverEffect();}
    &:active {@activeEffect();}
}

.active_delegate()       {background: #aaa}
.hover_delegate()        {background: #ddd}
.active_delegate--dark() {background: #666}
.hover_delegate--dark()  {background: #333}

.button {
    background: #fff;
   .clickable({.hover_delegate}, {.active_delegate});
}

.button--dark {
    background: #000;
   .clickable({.hover_delegate--dark}, {.active_delegate--dark});
}

Alternatively you can use "tagged callbacks" (which are quite more verbose but may have their pros in certain more advanced cases, for instance when you need a delegate with parameters - this is what the "detached ruleset" is incapable of, at least directly (yet)).

@seven-phases-max
Copy link
Member

Closing as duplicate of #965.

@kreopt
Copy link
Author

kreopt commented Dec 11, 2014

Thanks. It is actually what I want

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