default values for mixins parameters [duplicate]
-
29-04-2021 - |
Question
I am using a mixin for font like this:
#font {
.trebuchet(@weight: normal, @size: 12px, @lineHeight: 20px, @style:normal) {
font-family: "Trebuchet MS", arial, verdana, sans-serif;
font-size: @size;
font-weight: @weight;
line-height: @lineHeight;
font-style: @style;
}
}
I want to call this changing only the last parameter, style, but leave the other values to their defaults. For example, instead of writing:
#font > .trebuchet(normal, 12px, 20px, italic);
I would write something like:
#font > .trebuchet(false, false, false, italic);
(which actually works, but I suspect for the wrong reasons -or anyway it doesn't seem proper syntax) What's the best way to achieve this?
Solution
You can use pattern matching. You should clone your .trebuchet class like this:
.trebuchet when (@weight=false) and (not(ispixel(@size)) and (not(ispixel(@lineHeight)) {
font-style: @style;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow