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 0fee024
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Themes/ui/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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 0fee024

Please sign in to comment.