colord icon indicating copy to clipboard operation
colord copied to clipboard

How to generate contrast color?

Open artalar opened this issue 4 years ago • 5 comments

Hi! I have a color picker that should produce the main color and the opposite - contrast color. Right now I use "invert", but it is useless for gray colors and so on.

artalar avatar Feb 09 '22 20:02 artalar

Hi @artalar! colord doesn't have a method for that currently, but I can try to help you somehow if you provide more details and, maybe, some examples. I can't say it's clear for me what color should be "opposite" to gray. On my color picker website I always use black and white for text colors: https://omgovich.github.io/react-colorful/

omgovich avatar Feb 10 '22 09:02 omgovich

Hi @artalar! Maybe it's not exactly what you need, but maybe it will help you: https://gist.github.com/suhodolskiy/d14b74e183607bbb34eae3313bce7c80

suhodolskiy avatar Feb 21 '22 16:02 suhodolskiy

@suhodolskiy thx, will use it. Btw while(color.contrast(this) < 4.5) color = isLight ? color.darken(0.4) : color.lighten(0.4)

artalar avatar Feb 22 '22 15:02 artalar

You could check this out at the work: https://monocss.vercel.app/

artalar avatar Feb 25 '22 07:02 artalar

Helper function would be nice 👍🏻

jd-solanki avatar Jan 18 '23 09:01 jd-solanki