omgovich / colord

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

Add support for multiple types of color formats in single input. #67

Closed codergigachad closed 3 years ago

codergigachad commented 3 years ago

var color = colord({r: 255, g: 255, b: 255, a: 1, hex: "#ffffff"}) // not supported input If it's supported please tell me if I am doing something wrong here. I am using colord to make a color picker in react with react-colorful.

omgovich commented 3 years ago

Hi! Seems like your case is pretty specific (I don't know any color manipulation library that supports this kind of behavior). I also don't understand how the library should process conflicting colors like

colord({ r: 0, g: 0, b: 0, hex: "#ffffff" })

I would recommend you to pass the values of the last edited fields. For example, if a user just edited B field, pass to Colord values of R, G and B inputs (rgb object). If the user just edited the hex field, call colord(hexInput.value)

codergigachad commented 3 years ago

I am using it with react-colorful and I wanted to make multiple color inputs using a single state. But react states updates asynchronously that's why I can't get the value of that state in the same function because it updates after the execution of the whole function. Now I am trying class components hope it works thanks for your help!