refactor(ui): move theme and locale settings location (#1624)
This commit is contained in:
@@ -52,7 +52,6 @@
|
||||
required
|
||||
[(ngModel)]="username"
|
||||
[placeholder]="t('usernamePlaceholder')"
|
||||
class="form-input"
|
||||
autocomplete="username"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -91,10 +91,6 @@
|
||||
@include auth.form-label;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
@include auth.form-input;
|
||||
}
|
||||
|
||||
.login-button {
|
||||
@include auth.auth-button;
|
||||
|
||||
|
||||
@@ -404,6 +404,53 @@
|
||||
<span>{{ t('readingStats') }}</span>
|
||||
</button>
|
||||
}
|
||||
|
||||
<div class="flex flex-col-reverse">
|
||||
<button
|
||||
type="button"
|
||||
class="menu-item user-account-popover-action"
|
||||
aria-controls="user-account-appearance-menu"
|
||||
[attr.aria-expanded]="appearanceMenuOpen()"
|
||||
(click)="toggleAppearanceMenu()"
|
||||
>
|
||||
<i class="pi pi-palette" aria-hidden="true"></i>
|
||||
<span>{{ 'layout.theme.appearance' | transloco }}</span>
|
||||
<span class="ml-auto mr-2 min-w-0 max-w-[5.5rem] overflow-hidden text-ellipsis whitespace-nowrap text-xs text-text-secondary">{{ selectedAppearanceLabel() }}</span>
|
||||
<i
|
||||
class="pi pi-chevron-down size-3 shrink-0 text-[0.6875rem] text-text-secondary! transition-transform duration-150"
|
||||
[class.rotate-180]="appearanceMenuOpen()"
|
||||
aria-hidden="true">
|
||||
</i>
|
||||
</button>
|
||||
|
||||
<div
|
||||
id="user-account-appearance-menu"
|
||||
class="pointer-events-none grid origin-bottom grid-rows-[0fr] translate-y-1 opacity-0 transition-[grid-template-rows,opacity,transform] duration-150 ease-out data-[open=true]:pointer-events-auto data-[open=true]:mt-1 data-[open=true]:border-t data-[open=true]:border-border data-[open=true]:pt-1 data-[open=true]:grid-rows-[1fr] data-[open=true]:translate-y-0 data-[open=true]:opacity-100 motion-reduce:transition-none"
|
||||
[attr.aria-label]="'layout.theme.appearance' | transloco"
|
||||
[attr.aria-hidden]="!appearanceMenuOpen()"
|
||||
[attr.data-open]="appearanceMenuOpen()"
|
||||
[attr.inert]="appearanceMenuOpen() ? null : ''"
|
||||
>
|
||||
<div class="min-h-0 overflow-hidden">
|
||||
<div class="flex flex-col gap-0.5 pb-1 pl-[calc(var(--control-icon-size)+var(--menu-item-gap))]">
|
||||
@for (option of appearanceOptions; track option.value) {
|
||||
<button
|
||||
type="button"
|
||||
class="menu-item user-account-popover-action aria-pressed:bg-active-surface aria-pressed:text-primary! aria-pressed:[&_.pi]:text-primary!"
|
||||
[attr.aria-pressed]="selectedAppearancePreference() === option.value"
|
||||
(click)="updateAppearancePreference(option.value)"
|
||||
>
|
||||
<i [class]="option.icon" aria-hidden="true"></i>
|
||||
<span>{{ option.labelKey | transloco }}</span>
|
||||
@if (selectedAppearancePreference() === option.value) {
|
||||
<i class="pi pi-check ml-auto text-primary!" aria-hidden="true"></i>
|
||||
}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="user-account-popover-footer">
|
||||
|
||||
@@ -25,6 +25,8 @@ import { LibraryImportProgressService } from '../../service/library-import-progr
|
||||
import { AppVersion, VersionService } from '../../service/version.service';
|
||||
import { DialogLauncherService } from '../../services/dialog-launcher.service';
|
||||
import { LayoutService } from '../layout.service';
|
||||
import { AppThemeService } from '../../service/app-theme.service';
|
||||
import type { AppearancePreference } from '../../model/app-state.model';
|
||||
|
||||
import { AppSidebarComponent } from './app.sidebar.component';
|
||||
|
||||
@@ -44,6 +46,8 @@ describe('AppSidebarComponent', () => {
|
||||
let progressUpdates$: BehaviorSubject<MetadataBatchProgressNotification>;
|
||||
let hasPendingFiles: WritableSignal<boolean>;
|
||||
let hasActiveImport: WritableSignal<boolean>;
|
||||
let setAppearancePreference: ReturnType<typeof vi.fn>;
|
||||
let appState: WritableSignal<{ appearancePreference: AppearancePreference }>;
|
||||
const sidebarCollapsed = signal(false);
|
||||
const isDesktop = signal(true);
|
||||
const currentPath = signal('/dashboard');
|
||||
@@ -73,6 +77,10 @@ describe('AppSidebarComponent', () => {
|
||||
});
|
||||
hasPendingFiles = signal(false);
|
||||
hasActiveImport = signal(false);
|
||||
appState = signal({ appearancePreference: 'system' });
|
||||
setAppearancePreference = vi.fn((appearancePreference: AppearancePreference) => {
|
||||
appState.update(state => ({...state, appearancePreference}));
|
||||
});
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppSidebarComponent, getTranslocoModule()],
|
||||
@@ -110,6 +118,14 @@ describe('AppSidebarComponent', () => {
|
||||
{ provide: SeriesDataService, useValue: { allSeries: signal([]) } },
|
||||
{ provide: AuthorService, useValue: { allAuthors: signal([]) } },
|
||||
{ provide: MessageService, useValue: { add: vi.fn() } },
|
||||
{
|
||||
provide: AppThemeService,
|
||||
useValue: {
|
||||
appState,
|
||||
appearancePreference: computed(() => appState().appearancePreference),
|
||||
setAppearancePreference,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -202,6 +218,21 @@ describe('AppSidebarComponent', () => {
|
||||
expect(component.userInitials()).toBe('');
|
||||
});
|
||||
|
||||
it('updates the appearance preference without closing the appearance menu', () => {
|
||||
const sidebar = component as unknown as {
|
||||
appearanceMenuOpen: Signal<boolean>;
|
||||
toggleAppearanceMenu(): void;
|
||||
updateAppearancePreference(appearancePreference: AppearancePreference): void;
|
||||
};
|
||||
|
||||
sidebar.toggleAppearanceMenu();
|
||||
sidebar.updateAppearancePreference('dark');
|
||||
|
||||
expect(setAppearancePreference).toHaveBeenCalledWith('dark');
|
||||
expect(appState().appearancePreference).toBe('dark');
|
||||
expect(sidebar.appearanceMenuOpen()).toBe(true);
|
||||
});
|
||||
|
||||
it('normalizes semantic version labels with or without a leading v', () => {
|
||||
const sidebar = component as unknown as { appVersionLabel: () => string };
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@ import { MetadataProgressService } from '../../service/metadata-progress.service
|
||||
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
|
||||
import { MetadataBatchStatus } from '../../model/metadata-batch-progress.model';
|
||||
import { LibraryImportProgressService } from '../../service/library-import-progress.service';
|
||||
import { AppThemeService } from '../../service/app-theme.service';
|
||||
import type { AppearancePreference } from '../../model/app-state.model';
|
||||
import { APPEARANCE_OPTIONS } from '../theme/appearance-options';
|
||||
|
||||
const DOCUMENTATION_URL = 'https://grimmory.org/docs/getting-started';
|
||||
const ABOVE_ALIGN_LEFT: ConnectedPosition[] = [
|
||||
@@ -140,6 +143,7 @@ export class AppSidebarComponent {
|
||||
private readonly metadataProgressService = inject(MetadataProgressService);
|
||||
private readonly bookdropFileService = inject(BookdropFileService);
|
||||
private readonly libraryImportProgressService = inject(LibraryImportProgressService);
|
||||
private readonly themeService = inject(AppThemeService);
|
||||
|
||||
readonly currentUser = this.userService.currentUser;
|
||||
private readonly allAuthors = this.authorService.allAuthors;
|
||||
@@ -155,6 +159,14 @@ export class AppSidebarComponent {
|
||||
private readonly translate = (key: string): string => this.t.translate(key);
|
||||
protected readonly userPopoverOpen = signal(false);
|
||||
protected readonly userPopoverOrigin = signal<CdkOverlayOrigin | null>(null);
|
||||
protected readonly appearanceMenuOpen = signal(false);
|
||||
protected readonly appearanceOptions = APPEARANCE_OPTIONS;
|
||||
protected readonly selectedAppearancePreference = this.themeService.appearancePreference;
|
||||
protected readonly selectedAppearanceLabel = computed(() => {
|
||||
this.activeLang();
|
||||
const selectedOption = APPEARANCE_OPTIONS.find(option => option.value === this.selectedAppearancePreference());
|
||||
return selectedOption ? this.translate(selectedOption.labelKey) : '';
|
||||
});
|
||||
protected readonly canAccessReadingStats = computed(() => {
|
||||
const user = this.currentUser();
|
||||
return !!user && (user.permissions.admin || user.permissions.canAccessUserStats);
|
||||
@@ -267,6 +279,15 @@ export class AppSidebarComponent {
|
||||
|
||||
protected closeUserPopover(): void {
|
||||
this.userPopoverOpen.set(false);
|
||||
this.appearanceMenuOpen.set(false);
|
||||
}
|
||||
|
||||
protected toggleAppearanceMenu(): void {
|
||||
this.appearanceMenuOpen.update(open => !open);
|
||||
}
|
||||
|
||||
protected updateAppearancePreference(appearancePreference: AppearancePreference): void {
|
||||
this.themeService.setAppearancePreference(appearancePreference);
|
||||
}
|
||||
|
||||
protected openDocumentation(): void {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import type {AppearancePreference} from '../../model/app-state.model';
|
||||
|
||||
export interface AppearanceOption {
|
||||
value: AppearancePreference;
|
||||
labelKey: string;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
export const APPEARANCE_OPTIONS: readonly AppearanceOption[] = [
|
||||
{value: 'light', labelKey: 'layout.theme.light', icon: 'pi pi-sun'},
|
||||
{value: 'dark', labelKey: 'layout.theme.dark', icon: 'pi pi-moon'},
|
||||
{value: 'system', labelKey: 'layout.theme.system', icon: 'pi pi-desktop'},
|
||||
];
|
||||
@@ -31,6 +31,14 @@ interface AppThemeColorScheme {
|
||||
|
||||
interface AppThemePresetComponents {
|
||||
components?: {
|
||||
inputtext?: {
|
||||
root?: {
|
||||
focusBorderColor?: string;
|
||||
focusRing?: {
|
||||
shadow?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
button?: {
|
||||
colorScheme?: {
|
||||
light?: {
|
||||
@@ -49,6 +57,13 @@ describe('theme-palette-extend', () => {
|
||||
expect(preset.semantic?.colorScheme?.dark?.content?.background).toBe('var(--color-page)');
|
||||
});
|
||||
|
||||
it('bridges Prime input focus styles to app control tokens', () => {
|
||||
const inputtext = (ExtendedAura as AppThemePresetComponents).components?.inputtext?.root;
|
||||
|
||||
expect(inputtext?.focusBorderColor).toBe('var(--control-focus-border)');
|
||||
expect(inputtext?.focusRing?.shadow).toBe('none');
|
||||
});
|
||||
|
||||
it('uses balanced light outlined button tokens', () => {
|
||||
const outlined = (ExtendedAura as AppThemePreset & AppThemePresetComponents)
|
||||
.components?.button?.colorScheme?.light?.outlined;
|
||||
|
||||
@@ -51,6 +51,17 @@ const appHighlight = {
|
||||
focusColor: 'var(--color-primary-text)',
|
||||
};
|
||||
|
||||
const appInputText = {
|
||||
focusBorderColor: 'var(--control-focus-border)',
|
||||
focusRing: {
|
||||
width: '0',
|
||||
style: 'none',
|
||||
color: 'transparent',
|
||||
offset: '0',
|
||||
shadow: 'none',
|
||||
},
|
||||
};
|
||||
|
||||
const contentSurface = {
|
||||
background: 'var(--color-page)',
|
||||
borderColor: 'var(--color-border)',
|
||||
@@ -126,6 +137,7 @@ const AppPrimePreset = definePreset(Aura, {
|
||||
tieredmenu: { root: menuRoot },
|
||||
contextmenu: { root: menuRoot },
|
||||
menubar: { submenu: menuRoot },
|
||||
inputtext: { root: appInputText },
|
||||
button: {
|
||||
colorScheme: {
|
||||
light: { outlined: lightOutlinedButton },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
|
||||
import { inject, Injectable, PLATFORM_ID, signal } from '@angular/core';
|
||||
import { computed, inject, Injectable, PLATFORM_ID, signal } from '@angular/core';
|
||||
import { FaviconService } from '../layout/theme/favicon-service';
|
||||
import {applyPrimeTheme, primeThemeTokenPalettes} from '../layout/theme/theme-palette-extend';
|
||||
import {
|
||||
@@ -38,6 +38,11 @@ export class AppThemeService {
|
||||
private readonly appStateSignal = signal<AppState>(this.withDefaults({}));
|
||||
private readonly effectiveAppearanceSignal = signal<'light' | 'dark'>('dark');
|
||||
readonly appState = this.appStateSignal.asReadonly();
|
||||
readonly themePreference = computed(() => this.appStateSignal().themePreference ?? DEFAULT_APP_THEME);
|
||||
readonly appearancePreference = computed(() => this.appStateSignal().appearancePreference ?? DEFAULT_APPEARANCE_PREFERENCE);
|
||||
readonly customPrimary = computed(() => this.appStateSignal().customPrimary ?? DEFAULT_CUSTOM_PRIMARY);
|
||||
readonly themeSyncEnabled = computed(() => this.appStateSignal().themeSyncEnabled !== false);
|
||||
readonly oledDarkMode = computed(() => this.appStateSignal().oledDarkMode);
|
||||
readonly effectiveAppearance = this.effectiveAppearanceSignal.asReadonly();
|
||||
document = inject(DOCUMENT);
|
||||
platformId = inject(PLATFORM_ID);
|
||||
|
||||
Reference in New Issue
Block a user