session-desktop/ts/util/hexColorToRGB.ts
William Grant b704b8202d feat: added colors file with all declared theme and primary colors
added hexColorToRBG utility so that we can handle rgba colors using the same variables
2022-09-06 12:14:40 +10:00

22 lines
634 B
TypeScript

// https://css-tricks.com/converting-color-spaces-in-javascript
export function hexColorToRGB(hexColor: string): string {
let red = 0;
let green = 0;
let blue = 0;
// 3 digits
if (hexColor.length === 4) {
red = Number(`0x${hexColor[1]}${hexColor[1]}`);
green = Number(`0x${hexColor[2]}${hexColor[2]}`);
blue = Number(`0x${hexColor[3]}${hexColor[3]}`);
// 6 digits
} else if (hexColor.length === 7) {
red = Number(`0x${hexColor[1]}${hexColor[2]}`);
green = Number(`0x${hexColor[3]}${hexColor[4]}`);
blue = Number(`0x${hexColor[5]}${hexColor[6]}`);
}
return `${red}, ${green}, ${blue}`;
}