add: darktheme support + theme service
This commit is contained in:
1 parent
1b5f48b1b2
commit
343a49daad
9 files changed
+584
-397
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ThemeService {
|
||||
private theme: 'light' | 'dark' = 'light';
|
||||
|
||||
constructor() {
|
||||
this.loadTheme(); // Load the theme when the service is initialized
|
||||
}
|
||||
|
||||
toggleTheme(): void {
|
||||
this.theme = this.theme === 'light' ? 'dark' : 'light';
|
||||
this.applyTheme();
|
||||
}
|
||||
|
||||
private loadTheme(): void {
|
||||
// Load theme from localStorage or default to 'light'
|
||||
this.theme = (localStorage.getItem('theme') as 'light' | 'dark') || 'light';
|
||||
this.applyTheme();
|
||||
}
|
||||
|
||||
private applyTheme(): void {
|
||||
document.documentElement.setAttribute('data-bs-theme', this.theme);
|
||||
localStorage.setItem('theme', this.theme); // Save theme to localStorage
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user