我有一种情况,我想动态设置组件中元素的颜色和暗度/亮度,就像我使用md-color()一样。有没有办法做到这一点,还是我应该将我的主题颜色硬编码到我的组件代码中?
以下是硬编码方式:
if(val.className === "negative"){
if(val.p < .25){
color = "#b0bec5";
} else if ( val.p < .75){
color = "#78909c";
} else{
color = "#546e7a";
}
} else if(val.className === "positive"){
if(val.p < .25){
color = "#f48fb1";
} else if ( val.p < .75){
color = "#ec407a";
} else{
color = "#d81b60";
}
}
我想做的是:
if(val.className === "negative"){
color = accent;
else {
color = primary;
}
darkness = val.p * 800;
return md-color(color,darkness);