Planner should support color keywords, not just hex
rachelnabors opened this issue · 5 comments
rachelnabors commented
Example
Assigning a CSS color keyword like black instead of #000000 to color throws error:
Expected Behavior
- If
color's value doesn't begin with a#, compare it to a dictionary of CSS colors. - If not in the dictionary, either throw error or use "transparent" (your choice).
- If in the dictionary, use that keyword for the color.
bvaughn commented
Totally understand why this would be a nice convenience feature- but it’s a hard limitation currently because of how my color highlighting (on hover) and contrast (foreground vs background color determination) works. Both require converting between hex and rgb values. I’d like to avoid having to hardcode a long list of CSS color names. (I think there are well over 100 of them?)
rachelnabors commented
The browser itself could confirm whether or not the keyword is a valid color like so:
https://stackoverflow.com/questions/48484767/javascript-check-if-string-is-valid-css-color
bvaughn commented
It’s not about confirmation- but rather, how to covert a color name to an rgb value (so I can calculate contrast).
rachelnabors commented
What about getComputedStyle()?
bvaughn commented
Oh, nice! That looks like it could work then as a fallback for non-hex colors.
