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

Is it possible to customize the contrast threshold? #16

Closed
marcodevsquad opened this issue Oct 31, 2018 · 5 comments
Closed

Is it possible to customize the contrast threshold? #16

marcodevsquad opened this issue Oct 31, 2018 · 5 comments

Comments

@marcodevsquad
Copy link

marcodevsquad commented Oct 31, 2018

In bootstrap 4 we have a variable called $yiq-contrasted-threshold: were has a value of 150 by default and this variable ajusts the threshold to decide if the color should be black or white in components. Is there something similar to this?

I thought something like this:

invert('#d9534f', { threshold: 155 }); // #ffffff

And congrats for this awesome project! Thank you very much!

@onury
Copy link
Owner

onury commented Oct 31, 2018

Thanks.

The default threshold of this library is gathered from the formula given for contrast in the W3C Recommendations. There is an inner constant for luminance threshold but currently there is no option to customize this with exposed API.

The threshold value is in a scale of 0.0 (lowest) to 1.0 (highest). The default threshold is calculated with Math.sqrt(1.05 * 0.05) - 0.05 which is approx. ~0.179. I don't know the scale of that bootstrap variable. You would need to convert it to 0.0-1.0 scale or vice-versa.

I'll mark this to be implemented.

@onury
Copy link
Owner

onury commented Oct 31, 2018

Notes for implementation:

  • Add optional property threshold?: number to BlackWhite interface.
  • Expose default threshold calculated value as defaultThreshold property. Remove BW_THRESHOLD constant.
  • Update related methods.

@marcodevsquad
Copy link
Author

marcodevsquad commented Nov 1, 2018

Thank you for your fast reply! Just to complement, this feature IMHO will make your package perfect and complete!

Congratulations for this project!! Keep on moving! 😉 👍

@onury
Copy link
Owner

onury commented Nov 9, 2018

Added this in v2.0.0 (unreleased).
Hope this works for you.
I'll release as soon as #17 fix is confirmed.

@onury
Copy link
Owner

onury commented Nov 11, 2018

released.

@onury onury closed this as completed Nov 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants