Skip to content

Commit

Permalink
properly handle hex string with alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
shyguy1412 committed Oct 16, 2024
1 parent 67e17df commit 7c50c14
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Themes/ui/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type OpenColorPickerButtonProps = {
};

function parseHEXtoRGB(hex: string): RGB {

if (hex.length == 4) {
return {
r: Number.parseInt(`${hex[1]}${hex[1]}`, 16),
Expand All @@ -44,7 +43,15 @@ function parseHEXtoRGB(hex: string): RGB {
};
}

if (hex.length == 7 || hex.length == 9) {
if (hex.length == 7) {
return {
r: Number.parseInt(`${hex[1]}${hex[2]}`, 16),
g: Number.parseInt(`${hex[3]}${hex[4]}`, 16),
b: Number.parseInt(`${hex[5]}${hex[6]}`, 16),
};
}

if (hex.length == 9) {
return {
r: Number.parseInt(`${hex[1]}${hex[2]}`, 16),
g: Number.parseInt(`${hex[3]}${hex[4]}`, 16),
Expand Down

0 comments on commit 7c50c14

Please sign in to comment.