I’m using accessible-colors
& react-color-palette
, and what I’m trying to do is use the suggestAAColorVariant
with the hexadecimal values of a foreground and background that also have alpha channels. (Ex. suggestAAColorVariant('#860f0fea', '#000000', true);
) When supplied with a 6 digit hex color code, it returns a color with a proper contrast value of 3.0, and same hue like #b21414
. But the issue I am having is that it does not function as intended with a value using an alpha channel. it returns a color like #3a3aef
with a wrong/different hue but proper contrast value of 3.0.
I think accessible-colors
lacks support for conversions with alpha hex colors. react-color-palette
handles conversions between rgb, hex, or hsv values. I found another package, rgba-to-rgb
, with support for converting rgba and rgb values. Is there something similar for hex colors or should i just use the rgb value through react-color-palette
and into rgba-to-rgb
? If I took that approach, how could I only perform the conversion if the hex value is 8 digits? If I used variables like (Ex. suggestAAColorVariant(F, B, true);
& F='#860f0fea'
& B='#000000'
) what code/function could perform a check if the string of F
has 6 digits or 8 and perform the conversion?
I see several relevant posts, but none with directly relevant answers.
How to convert 8-digit hex to the equivalent 6-digit hex code in php?