feat(ui): add connection color tinting
This commit is contained in:
1 parent
4cd9432fcb
commit
0b376c234f
4 files changed
+57
-5
No files matched your search
@@ -0,0 +1,18 @@
|
||||
export function hexToRgba(color: string | undefined, alpha: number): string | undefined {
|
||||
if (!color) return undefined;
|
||||
const hex = color.trim().replace(/^#/, "");
|
||||
const normalized =
|
||||
hex.length === 3
|
||||
? hex
|
||||
.split("")
|
||||
.map((c) => c + c)
|
||||
.join("")
|
||||
: hex;
|
||||
if (!/^[0-9a-fA-F]{6}$/.test(normalized)) return undefined;
|
||||
|
||||
const value = Number.parseInt(normalized, 16);
|
||||
const r = (value >> 16) & 255;
|
||||
const g = (value >> 8) & 255;
|
||||
const b = value & 255;
|
||||
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
||||
}
|
||||
Reference in new issue
Block a user