Files
hermes-web-angular/src/app/shared/services/theme.service.ts

45 lines
870 B
TypeScript

import { inject, Injectable, signal } from '@angular/core';
import EventService from './EventService';
@Injectable({
providedIn: 'root'
})
export class ThemeService {
private events = inject(EventService);
private _current = signal<'light' | 'dark'>('dark');
get theme() {
return this._current();
}
set theme(value: 'light' | 'dark') {
const previous = this._current();
if (previous == value) {
return;
}
this._current.set(value);
localStorage.setItem('ui-theme', value);
this.events.emit('theme_change', {
previous_theme: previous,
current_theme: value,
});
}
isDarkTheme() {
return this.theme == 'dark';
}
isLightTheme() {
return this.theme == 'light';
}
toggle() {
if (this.theme == 'light') {
this.theme = 'dark';
} else {
this.theme = 'light';
}
}
}