Qix-/color

Get luminosity info from array of color #171

rtransat posted onGitHub

Hi,

I need to know if a color is dark or light to display a text in black or white but it seems that is not worked if the color is an array:

const colors = ['#ffffff', '#ffffff', '#ffffff'];
return Color(colors).isLight() ? '#000000' : '#ffffff';

The value returned is #ffffff


Color() makes an instance of Color. To work with few colors need make own instance for each one.

const colors = ['#FFF', '#FFF', '#FFF'];
const result = colors.map(color => Color(color).isLight() ? '#000' : '#FFF');
console.log(result); // [ '#000', '#000', '#000' ]
posted by vyushin about 5 years ago

Not sure how I missed this. @vyushin is correct.

posted by Qix- about 5 years ago

Fund this Issue

$0.00
Funded

Pull requests