Friday, 9 August 2013

Building a variadic mixin in LESS

Building a variadic mixin in LESS

I am trying to make a variadic mixin in LESS. To this end I use the
following syntax for my mixin :
.mixin (@a; @rest...) {
// @rest is bound to arguments after @a
// @arguments is bound to all arguments
}
But I don't know how to manipulate @rest and read to the last parameters
of the mixin.
This is my code :
.color () { }
.color (@shade) {
#id {
background-color : rgb(@shade, @shade, @shade);
}
}
.color (@shade, @rest...) {
#id {
background-color : rgb(@shade, @shade, @shade);
}
.color(@rest);
}
.color(200, 160);
As you guess, this mixin should examinate the entire list of parameters,
and colour the background of my <div id="id"> with the shade of grey
corresponding to the last parameter of the mixin (in this case, rgb(160,
160, 160)).
But when I compile this code with less-1.4.1.js, I get the following error :
SyntaxError: error evaluating function `rgb`:
color functions take numbers as parameters
So how to access to the second, third, fourth... parameters of the mixin ?
Thanks a lot for your advices, and have a nice week-end !

No comments:

Post a Comment