From 7c50c1440a13806f206c52f0df2a95ff535ed0c8 Mon Sep 17 00:00:00 2001 From: Shy Date: Wed, 16 Oct 2024 15:51:19 +0200 Subject: [PATCH] properly handle hex string with alpha --- src/Themes/ui/ColorPicker/index.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Themes/ui/ColorPicker/index.tsx b/src/Themes/ui/ColorPicker/index.tsx index 29181deac1..5f2ece7270 100644 --- a/src/Themes/ui/ColorPicker/index.tsx +++ b/src/Themes/ui/ColorPicker/index.tsx @@ -35,7 +35,6 @@ type OpenColorPickerButtonProps = { }; function parseHEXtoRGB(hex: string): RGB { - if (hex.length == 4) { return { r: Number.parseInt(`${hex[1]}${hex[1]}`, 16), @@ -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),