Any suggestion how to create a conditional mixin based on parameter existence? For example I need to to verify that all the parameters are passed in order to perform something or not, for example:
.margin (@margintop:0,@marginbottom:0,@marginright:0,@marginleft:0) {
// if @marginright:0 or @marginleft:0 are passed do that...
// else...
}
1:
In general, when you need to generate different things for different number of arguments passed you don't need to use default argument values at all, e.g.:
Note that each of these mixins can reuse the others, for example
.margin(@top, @bottom)
can do something special for the "no right and left case" and then call.margin(@top, @bottom, 0, 0)
to perform the main job.2:
But if you still need these defaults for some reason you can use some special default value that can't be a valid margin, e.g. something like this:
3:
And the third option would be to use variadic arguments and test their count, but this one is the most verbose and dumb I guess:
Though it may probably have its pros in some special use-cases.