Files
tom goriunovandGitHub f0e713b877 Add support for customizing the UI color theme (#2923)
* UI customizations: new features

Fixes #2905

* colors for graphs

* introduce env variable

* colors for topbar, stats, selected state and tabs

* fix build

* fix validator

* refactor link.primary.hover color token

* refactor selected colors

* update styles for switch and fix some color tokens

* change color for selectable controls

* icon color tokens refactoring

* UI customizations: new features

Fixes #2905

* test for common components

* tweaks

* migrate from color-mode-hex cookie to color-theme cookie

* clean up

* update screenshots

* more screenshot updates

* update default color of chart line

* update envs for mega eth
2025-08-19 11:58:05 +02:00

87 lines
2.2 KiB
TypeScript

import type { ColorThemeId } from 'types/settings';
import config from 'configs/app';
import type { ColorMode } from 'toolkit/chakra/color-mode';
export interface ColorTheme {
id: ColorThemeId;
label: string;
colorMode: ColorMode;
hex: string;
sampleBg: string;
}
const getNestedValue = (obj: Record<string, unknown>, property: string) => {
const keys = property.split('.');
let current = obj;
for (const key of keys) {
const value = current[key];
if (value === undefined) {
return undefined;
}
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
current = value as Record<string, unknown>;
} else {
return value;
}
}
};
export function getThemeHexWithOverrides(colorThemeId: ColorThemeId) {
const defaultHex = COLOR_THEMES.find((theme) => theme.id === colorThemeId)?.hex;
if (!defaultHex) {
return;
}
const overrides = config.UI.colorTheme.overrides;
if (colorThemeId === 'light') {
const value = getNestedValue(overrides, 'bg.primary._light.value');
return typeof value === 'string' ? value : defaultHex;
}
if (colorThemeId === 'dark') {
const value = getNestedValue(overrides, 'bg.primary._dark.value');
return typeof value === 'string' ? value : defaultHex;
}
return defaultHex;
};
export function getDefaultColorTheme(colorMode: ColorMode) {
const colorTheme = COLOR_THEMES.filter((theme) => theme.colorMode === colorMode).slice(-1)[0];
return colorTheme.id;
}
export const COLOR_THEMES: Array<ColorTheme> = [
{
id: 'light',
label: 'Light',
colorMode: 'light',
hex: '#FFFFFF',
sampleBg: 'linear-gradient(154deg, #EFEFEF 50%, rgba(255, 255, 255, 0.00) 330.86%)',
},
{
id: 'dim',
label: 'Dim',
colorMode: 'dark',
hex: '#232B37',
sampleBg: 'linear-gradient(152deg, #232B37 50%, rgba(255, 255, 255, 0.00) 290.71%)',
},
{
id: 'midnight',
label: 'Midnight',
colorMode: 'dark',
hex: '#1B2E48',
sampleBg: 'linear-gradient(148deg, #1B3F71 50%, rgba(255, 255, 255, 0.00) 312.35%)',
},
{
id: 'dark',
label: 'Dark',
colorMode: 'dark',
hex: '#101112',
sampleBg: 'linear-gradient(161deg, #000 9.37%, #383838 92.52%)',
},
];