1

It is possible to achieve something like this in LESS?

.some-button(@className) {
  @className { .actionIcon; }
  tr:hover {
    @className { .actionButton; }
  }
}

When I call it:

.some-button(.edit-action);

The expected output should be :

.edit-action { .actionIcon; }
tr:hover { .edit-action { .actionButton; } }

Currently I'm getting this "Unrecognized input in @className { .actionIcon; }" error:

.some-button(@className) {
  @className { .actionIcon; }
  tr:hover {

EDIT

Another thing I would like to achieve is to use a mixin as mixin parameter:

.actionButton(@buttonClassName; @buttonType) {
  @{buttonClassName} { 
    .actionIcon; 
  }
  tr:hover {
    @{buttonClassName} { 
        .actionHoverIcon; 
        @buttonType();
    }
  }
}

and call is like this:

.actionButton(~'.row-edit', button-harmful);

where button-harmful is a mixin.

ScottS
  • 71,703
  • 13
  • 126
  • 146
dragonfly
  • 17,407
  • 30
  • 110
  • 219

2 Answers2

6

They call this "Selector Interpolation", the correct syntax is:

.some-button(@className) {
    @{className} { 
        /* ... */
    }
}

// usage:
.some-button(~'.edit-action');

Or alternatively (if you know you will use only classes, i.e. . prefixed selectors) like this:

.some-button(@className) {
    .@{className} {
        /* ... */
    }
}

// usage:
.some-button(edit-action);
seven-phases-max
  • 11,765
  • 1
  • 45
  • 57
1

To answer your second question (i.e. "use a mixin as mixin parameter"): in short, currently this is impossible in a straight forward way. There're a few workarounds that simulate this functionality though (You'll find a brief of those methods here and here).

For example:

.actionButton(@buttonClassName, @buttonType) {
    @{buttonClassName} {
        .actionIcon;
    }
    tr:hover {
        @{buttonClassName} {
            .actionHoverIcon;
            .call(@buttonType);
        }
    }
}

// usage:

.call(button-harmful) {.button-harmful}
.actionButton(~'.row-edit', button-harmful);
seven-phases-max
  • 11,765
  • 1
  • 45
  • 57
  • Btw., I recall I saw a great detailed answer about the "tagged callbacks" technique (e.g. "callback dispatching based on the pattern-matching") here at SO but I can't find it right now (@ScottS - probably it was yours?) – seven-phases-max Feb 06 '14 at 17:32
  • You are probably thinking of [this post](http://stackoverflow.com/questions/11551313/less-css-pass-mixin-as-a-parameter-to-another-mixin/11589227#11589227)? – ScottS Feb 06 '14 at 20:08
  • @ScottS I'm not sure. May be, may be not :) – seven-phases-max Feb 06 '14 at 20:09