Closed estelle closed 1 year ago
I added opacity * 1
to force it to a number so I could do opacity === 1
. HTML form controls return strings, hence the == 1
@teoli2003 We went with
function hexOpacity(color, opacity) {
let char = "00";
if (opacity > 0) {
char = Math.floor(opacity * 255).toString(16);
}
return `${color}${char}`;
}
Is it also ok to go with the following way of declaring a function (the first line), or against our best practices guidelines?
const hexOpacity = (color, opacity) => {
let char = "00";
if (opacity > 0) {
char = Math.floor(opacity * 255).toString(16);
}
return `${color}${char}`;
}
@teoli2003 We went with
function hexOpacity(color, opacity) { let char = "00"; if (opacity > 0) { char = Math.floor(opacity * 255).toString(16); } return `${color}${char}`; }
Is it also ok to go with the following way of declaring a function (the first line), or against our best practices guidelines?
const hexOpacity = (color, opacity) => { let char = "00"; if (opacity > 0) { char = Math.floor(opacity * 255).toString(16); } return `${color}${char}`; }
When possible, I prefer to have a function
definition. I don't see what the longest syntax brings to readability.
(I'm not a fan of setting the else value before the if, but that's not against our rules and a matter of taste)
Example for new CSS color module page.