-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Calculating color lightness with YIQ #224
Comments
Hi @ravinggenius I believe we already have a solution about to be released for this using the W3C spec for contrast. Take a look at #185 and to #163 and let me know if that handles your use case. Hoping to get those finished up and merged in this week. |
I don't think #192 is using the same algorithm (YIQ), but the goal appears to be the same. Really what I'm after is the ability to pass in a background color and know if I should use dark or light text. I'm closing this with the assumption #192 will work for me, though I would prefer arguments to customize the return value. |
@ravinggenius Are you wanting to customize the color format you want returned? |
Not really. I was thinking it might be useful to accept optional values to return instead of always const readableColor = (backgroundColor) => {
// ...
return isLight ? 'black' : 'white';
}; Allow passing (optional) dark/light colors, but default to const readableColor = (backgroundColor, dark = 'white', light = 'black') => {
// ...
return isLight ? light : dark;
}; |
@ravinggenius I thought about that implementation (I normally use gray instead of black), but given how easy it is to write a wrapper function, I think the simplicity of black or white is clearer.
|
** This is a feature request. **
polished
version: anyJSS-in_CSS
library and version: naI have found YIQ to be an excellent algorithm for calculating the apparent lightness of a color. I would like to have a function
isLight(color)
which implements YIQ (just returnstrue
orfalse
). A second function would also be helpful for picking an appropriate contrast for a given color, maybeifIsLight(color, light = '#000', dark = '#FFF')
.I'm happy to provide the implementation if there is interest. I find myself having to implement this in nearly every project I'm on these days.
The text was updated successfully, but these errors were encountered: