feat(ui): OLED dark mode variant (#1560)

This commit is contained in:
Alex
2026-05-29 06:56:04 +01:00
committed by GitHub
parent e4bf4c5659
commit 5e0eac5764
19 changed files with 156 additions and 49 deletions
@@ -41,7 +41,7 @@
}
.sidebar-item-container.active-route-container {
background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
background-color: var(--color-active-surface);
}
.sidebar-item-link {
@@ -233,7 +233,7 @@ a.sidebar-item-link.active-route {
}
.sidebar-item-container.active-route-container {
background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
background-color: var(--color-active-surface);
}
.sidebar-item-container:has(:focus-visible) {
@@ -233,7 +233,7 @@
&.active-route {
color: var(--color-primary-text);
background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
background-color: var(--color-active-surface);
.sidebar-footer-action-label {
color: inherit;
@@ -598,7 +598,7 @@
}
&.active-route {
background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
background-color: var(--color-active-surface);
color: var(--color-primary-text);
}
}
@@ -51,6 +51,18 @@ const appHighlight = {
focusColor: 'var(--color-primary-text)',
};
const contentSurface = {
background: 'var(--color-page)',
borderColor: 'var(--color-border)',
color: 'var(--color-text)',
};
const overlaySurface = {
background: 'var(--color-card)',
borderColor: 'var(--color-border)',
color: 'var(--color-text)',
};
function buildAppTokenPalette(prefix: 'primary' | 'surface', stops: readonly string[]): ColorPalette {
return Object.fromEntries(
stops.map((stop) => [stop, `var(--color-${prefix}-${stop})`])
@@ -87,10 +99,19 @@ function buildPrimePalettePreset(theme: ResolvedThemePalettes): object {
const AppPrimePreset = definePreset(Aura, {
semantic: {
colorScheme: {
light: { content: { background: 'var(--color-page)' } },
light: {
content: contentSurface,
overlay: {
popover: overlaySurface,
modal: overlaySurface,
},
},
dark: {
content: { background: 'var(--color-page)' },
// Card menus are surface.800; Aura default hover is also 800 — use app surface-hover mix.
content: contentSurface,
overlay: {
popover: overlaySurface,
modal: overlaySurface,
},
navigation: {
item: {
focusBackground: 'color-mix(in srgb, {text.color}, transparent 92%)',
@@ -1,32 +1,12 @@
import {describe, expect, expectTypeOf, it} from 'vitest';
import {describe, expect, it} from 'vitest';
import {
APP_THEME_OPTIONS,
AppearancePreference,
AppState,
AppTheme,
CustomPrimary,
DEFAULT_APP_THEME,
THEME_REGISTRY,
} from './app-state.model';
describe('app-state.model', () => {
it('supports partially specified visual theme state', () => {
const appState: AppState = {
themePreference: DEFAULT_APP_THEME,
appearancePreference: 'system',
};
expect(appState.themePreference).toBe(DEFAULT_APP_THEME);
expect(appState.appearancePreference).toBe('system');
});
it('keeps each field optional and constrained to supported values', () => {
expectTypeOf<AppState['themePreference']>().toEqualTypeOf<AppTheme | undefined>();
expectTypeOf<AppState['appearancePreference']>().toEqualTypeOf<AppearancePreference | undefined>();
expectTypeOf<AppState['customPrimary']>().toEqualTypeOf<CustomPrimary | undefined>();
});
it('derives theme options from the registry', () => {
expect(APP_THEME_OPTIONS).toBe(THEME_REGISTRY);
expect(APP_THEME_OPTIONS.some(option => option.name === DEFAULT_APP_THEME)).toBe(true);
@@ -12,7 +12,8 @@ export {
export type {AppTheme, CustomPrimary} from './theme-registry';
export interface AppState {
themePreference?: AppTheme;
appearancePreference?: AppearancePreference;
customPrimary?: CustomPrimary;
themePreference: AppTheme;
appearancePreference: AppearancePreference;
customPrimary: CustomPrimary;
oledDarkMode: boolean;
}
@@ -67,6 +67,7 @@ describe('AppConfigService', () => {
vi.spyOn(window, 'getComputedStyle').mockReturnValue(computedStyle);
root.classList.remove('dark');
delete root.dataset['appTheme'];
delete root.dataset['oledDarkMode'];
TestBed.resetTestingModule();
TestBed.configureTestingModule({
@@ -84,6 +85,7 @@ describe('AppConfigService', () => {
rootStyle.cssText = '';
root.classList.remove('dark');
delete root.dataset['appTheme'];
delete root.dataset['oledDarkMode'];
vi.restoreAllMocks();
vi.unstubAllGlobals();
});
@@ -93,6 +95,7 @@ describe('AppConfigService', () => {
themePreference: 'grimmory',
appearancePreference: 'system',
customPrimary: 'orange',
oledDarkMode: false,
});
expect(localStorageMock.getItem('appConfigState')).toBeNull();
expect(root.dataset['appTheme']).toBe('grimmory');
@@ -145,6 +148,7 @@ describe('AppConfigService', () => {
themePreference: 'grimmory',
appearancePreference: 'system',
customPrimary: 'orange',
oledDarkMode: false,
});
expect(root.dataset['appTheme']).toBe('grimmory');
expect(root.classList.contains('dark')).toBe(false);
@@ -152,6 +156,23 @@ describe('AppConfigService', () => {
themePreference: 'grimmory',
appearancePreference: 'system',
customPrimary: 'orange',
oledDarkMode: false,
}));
});
it('applies OLED mode only when the effective appearance is dark', () => {
service.setOledDarkMode(true);
expect(root.dataset['oledDarkMode']).toBeUndefined();
service.setAppearancePreference('dark');
expect(root.classList.contains('dark')).toBe(true);
expect(root.dataset['oledDarkMode']).toBe('true');
service.setAppearancePreference('light');
expect(root.classList.contains('dark')).toBe(false);
expect(root.dataset['oledDarkMode']).toBeUndefined();
});
});
@@ -22,6 +22,8 @@ type StoredAppState = Partial<AppState> & {
surface?: unknown;
};
type AppStatePatch = Partial<AppState>;
interface LoadedAppState {
state: AppState;
shouldPersist: boolean;
@@ -33,8 +35,10 @@ interface LoadedAppState {
export class AppConfigService {
private readonly STORAGE_KEY = 'appConfigState';
readonly themes = APP_THEME_OPTIONS;
private readonly appStateSignal = signal<AppState>({});
private readonly appStateSignal = signal<AppState>(this.withDefaults({}));
private readonly effectiveAppearanceSignal = signal<'light' | 'dark'>('dark');
readonly appState = this.appStateSignal.asReadonly();
readonly effectiveAppearance = this.effectiveAppearanceSignal.asReadonly();
document = inject(DOCUMENT);
platformId = inject(PLATFORM_ID);
faviconService = inject(FaviconService);
@@ -61,7 +65,11 @@ export class AppConfigService {
this.updateAppState({appearancePreference});
}
private updateAppState(patch: AppState): void {
setOledDarkMode(oledDarkMode: boolean): void {
this.updateAppState({oledDarkMode});
}
private updateAppState(patch: AppStatePatch): void {
const state = this.withDefaults({
...this.appStateSignal(),
...patch,
@@ -103,6 +111,7 @@ export class AppConfigService {
themePreference: state.themePreference,
appearancePreference: state.appearancePreference,
customPrimary: state.customPrimary,
oledDarkMode: state.oledDarkMode,
});
}
@@ -110,22 +119,23 @@ export class AppConfigService {
return 'preset' in state || 'primary' in state || 'surface' in state;
}
private withDefaults(state: AppState): AppState {
private withDefaults(state: AppStatePatch): AppState {
return {
themePreference: this.resolveThemePreference(state.themePreference),
appearancePreference: this.resolveAppearancePreference(state.appearancePreference),
customPrimary: this.resolveCustomPrimary(state.customPrimary),
oledDarkMode: state.oledDarkMode === true,
};
}
private resolveCustomPrimary(customPrimary: AppState['customPrimary']): CustomPrimary {
private resolveCustomPrimary(customPrimary: AppStatePatch['customPrimary']): CustomPrimary {
if (customPrimary && CUSTOM_PRIMARY_OPTIONS.includes(customPrimary)) {
return customPrimary;
}
return DEFAULT_CUSTOM_PRIMARY;
}
private resolveThemePreference(themePreference: AppState['themePreference']): AppTheme {
private resolveThemePreference(themePreference: AppStatePatch['themePreference']): AppTheme {
if (themePreference && this.themes.some((option) => option.name === themePreference)) {
return themePreference;
}
@@ -133,7 +143,7 @@ export class AppConfigService {
return DEFAULT_APP_THEME;
}
private resolveAppearancePreference(appearancePreference: AppState['appearancePreference']): AppearancePreference {
private resolveAppearancePreference(appearancePreference: AppStatePatch['appearancePreference']): AppearancePreference {
if (appearancePreference === 'light' || appearancePreference === 'dark' || appearancePreference === 'system') {
return appearancePreference;
}
@@ -152,12 +162,12 @@ export class AppConfigService {
private saveAppState(state: AppState): void {
if (isPlatformBrowser(this.platformId)) {
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(this.withDefaults(state)));
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(state));
}
}
applyCurrentTheme(): void {
this.applyAppState(this.withDefaults(this.appStateSignal()));
this.applyAppState(this.appStateSignal());
}
private applyAppState(state: AppState): void {
@@ -177,8 +187,14 @@ export class AppConfigService {
const appearancePreference = this.resolveAppearancePreference(state.appearancePreference);
const effective = this.effectiveAppearancePreference(appearancePreference);
this.effectiveAppearanceSignal.set(effective);
root.dataset['appTheme'] = theme;
root.classList.toggle('dark', effective === 'dark');
if (state.oledDarkMode && effective === 'dark') {
root.dataset['oledDarkMode'] = 'true';
} else {
delete root.dataset['oledDarkMode'];
}
root.style.setProperty('color-scheme', effective);
this.applyCustomPrimary(root, theme, this.resolveCustomPrimary(state.customPrimary));
this.syncSystemSchemeListener(appearancePreference);
@@ -9,6 +9,7 @@
padding: 1.5rem 1.5rem 1.25rem;
border-radius: 10px 10px 0 0;
border: 1px solid var(--border-color);
background: var(--color-card);
box-shadow: 0 2px 6px rgb(0 0 0 / 8%);
.header-icon-wrapper {