It seems that evaluated color strings are not working with some built-in LESS functions.
I have tried using e()
and ~""
and any combination of both.
I might find a workaround for my particular case, I’m just asking if this is this expected behaviour, or if there is a fault in my reasoning? Any insight appreciated.
For example here, the color is created from an evaluated string; note the 'missing' #
in the hex value that gets added later :
.broken-mixin(@hexcode: '9719e1') {
@color: e("#@{hexcode}");
// this works as expected
background-color: @color;
// this does work too
.very-simple-mixin(@color);
// Undefined_methodError: error evaluating function `fade`:
// Object #<Object> has no method 'toHSL'
background-color: fade(@color,30%);
// SyntaxError: error evaluating function `red`:
// Cannot read property '0' of undefined
background-color: rgba(red(@color), green(@color), blue(@color), 0.5);
}
Otherwise built-in functions work normally work with variables in mixins, for example :
.mixin-works(@myColor: #00ff00) {
// works just fine
background-color: fade(@myColor,30%);
// or this, works too
background-color: rgba(red(@myColor), green(@myColor), blue(@myColor), 0.5);
}
What am I missing ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…