omgovich / colord

👑 A tiny yet powerful tool for high-performance color manipulations and conversions
https://colord.omgovich.ru
MIT License
1.63k stars 48 forks source link

How to generate contrast color? #85

Open artalar opened 2 years ago

artalar commented 2 years ago

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.

omgovich commented 2 years ago

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/

suhodolskiy commented 2 years ago

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

artalar commented 2 years ago

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

artalar commented 2 years ago

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

jd-solanki commented 1 year ago

Helper function would be nice 👍🏻