Format toString as hex if original string was hex? #510
Replies: 3 comments
-
I think your approach is fine. And to answer your question, Color.js does not currently track or care about how a color was serialized before parsing, so there is currently no way to extract that information from the color object (that I am aware of). It may be possible to gain insight on how a color was serialized by digging into the parsing function of the library, or simply by doing what you are already doing. CSS only has a couple of serialization approaches: hex, |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I opened this as I ran into a similar issue myself: #515 |
Beta Was this translation helpful? Give feedback.
-
I need to do these steps:
Here is a simplified example: https://codesandbox.io/p/sandbox/wandering-browser-forked-z5yg57?file=%2Fsrc%2FApp.js%3A2%2C1-29%2C1
This works unless you pass a hex value eg
#ef9700
. If you do the returned string is rgb not hex.I've got a workaround by checking if the string starts with "#" and specifying the hex format if it does.
https://codesandbox.io/p/sandbox/wandering-browser-5nfp73?file=%2Fsrc%2FApp.js%3A2%2C1-33%2C2
Is this the correct approach? I was wondering if the library can handle this without the need for a workaround.
Beta Was this translation helpful? Give feedback.
All reactions