Home:ALL Converter>Mixin property as an argument of another mixin?

Mixin property as an argument of another mixin?

Ask Time:2014-01-11T18:51:53         Author:DreaMTT

Json Formatter

How could I create a mixin that uses as an argument a nested mixin property?

I explain myself with the next example.

I have a 'transition-property' mixin:

.transition-property (@props){
  -webkit-transition-property: @props;
  -moz-transition-property: @props;
  -o-transition-property: @props;
  transition-property: @props;
}

From this mixin I want to use a 'transform' mixin property, so I tried to call this like:

 .transition-property(~"opacity, .transform");

The '.transform' mixin should return one of the next values:

 transform
 -ms-transform
 -webkit-transform

The thing is that I don't find the way to inject these property names to the 'transition-property' mixin, could someone shed some light on this?

FINAL DESIRED CSS

element {
  -webkit-transition-property: opacity, -webkit-transform;
  -moz-transition-property: opacity, -moz-transform;
  -o-transition-property: opacity, -o-transform;
  transition-property: opacity, transform;
}

Author:DreaMTT,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/21061361/mixin-property-as-an-argument-of-another-mixin
seven-phases-max :

OK, so first of all, a general remark: using a CSS preprocessor (e.g. LESS, SASS or whatever) to generate vendor prefixes is actually one of the greatests misuses these days (really, there's no need to bloat your code with prefixes and waste your time writing such mixins since tools like Autoprefixer, -prefix-free and similar came in).\n\nEither way here's a (sort of) generic solution (but considering amount of code and its complexity I think it's actually an overkill, here I will use LESS 1.6.0 example because in earlier versions it would be even more verbose and hackish):\n\n// usage:\n\nelement1 {\n .vendorize(transition-property; opacity, transform);\n}\n\nelement2 {\n .vendorize(transition-property; width, box-shadow, color);\n}\n\nelement3 {\n .vendorize(transition-property; height);\n}\n\n// implementation:\n\n// prefixes we want to be used:\n@prefixes: -webkit-, -moz-, -o-, ~'';\n\n// here we specialize what values are to be prefixed:\n.vendorize-value(transform) {.true}\n.vendorize-value(box-shadow) {.true}\n// etc.\n.vendorize-value(...) when (default()) {.false} // to handle not prefixed values\n\n// and now the mixin that can apply all of above specializations:\n.vendorize(@property, @values) {\n\n .-1();\n .-1(@i: length(@prefixes)) when (@i > 0) {\n .-1((@i - 1));\n @prefix: extract(@prefixes, @i);\n .-2();\n }\n\n .-2(@j: length(@values)) when (@j > 0) {\n .-2((@j - 1));\n @value: extract(@values, @j);\n .vendorize-value(@value);\n }\n\n .false() {@{prefix}@{property}+: @value}\n .true() {@{prefix}@{property}+: ~'@{prefix}@{value}'}\n}\n\n\n(Of course it can be simplified a bit if you need only transform to be prefixed but still looks too crazy).\n\nupd: fixed some errors.",
2014-01-11T22:00:59
yy