Situation
I have a mixin like this:
@mixin flexbox($type: null, $direction: null) {
@if $type == null or $type == 'flex' {
(...)
display: flex;
}
@if $type == 'inline-flex' {
(...)
display: inline-flex;
}
@if $direction == null or $direction == 'row' {
(...)
flex-direction: row;
}
@if $direction == 'column' {
(...)
flex-direction: column;
}
}
Which I can now use like so:
@include flexbox(inline-flex, column);
However I can't do this:
@include flexbox(column);
Because now the mixin treats the "column" as an argument for "$direction".
Is there a way around that?
A way to make my arguments independent of their order?
E.g. I'd like to be able to use the mixin in any of these ways:
@include flexbox(column);
@include flexbox(column, inline-flex);
@include flexbox(row, flex);
@include flexbox(row);
Currently none of those are working, because of the arguments need to be in a specific order.
Why not use named arguments?
Update: I accept this solution as the best possible way.
As suggested by Hashem Qolami below "named arguments" would be an option to solve this:
@include flexbox($direction: column);
This is a perfectly acceptable solution. Thanks for that.
However I'm working on a framework that will be used by multiple people in my company.
Therefore I'd like to keep all mixins as foolproof and easy to use as possible.
In that case this:
@include flexbox(column);
Would be preferred over this:
@include flexbox($direction: column);
Because other devs know what flexbox can do, but not how I named my arguments.
It's a small thing, really. But the use of named arguments would mean that everyone would have to learn the argument-names of every mixin available.