Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get luminosity info from array of color #171

Closed
florentsorel opened this issue Jan 13, 2020 · 2 comments
Closed

Get luminosity info from array of color #171

florentsorel opened this issue Jan 13, 2020 · 2 comments
Labels

Comments

@florentsorel
Copy link

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

@vyushin
Copy link
Contributor

vyushin commented Mar 3, 2020

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' ]

@Qix-
Copy link
Owner

Qix- commented Mar 3, 2020

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

@Qix- Qix- closed this as completed Mar 3, 2020
@Qix- Qix- added the question label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants