feat: added dark and light mode

This commit is contained in:
shahdlala66
2026-04-22 08:19:16 +02:00
parent 91fa247696
commit c18026bce6
6 changed files with 319 additions and 10 deletions
+27 -1
View File
@@ -24,7 +24,16 @@ export class WelcomeComponent {
constructor(
private readonly router: Router,
private readonly gameApi: GameApiService
) {}
) {
this.initTheme();
}
private initTheme(): void {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
}
startOneVsOne(): void {
if (this.creating) {
@@ -108,4 +117,21 @@ export class WelcomeComponent {
this.gameIdInput = '';
this.errorMessage = '';
}
toggleDarkMode(): void {
const htmlElement = document.documentElement;
const isDarkMode = htmlElement.getAttribute('data-theme') === 'dark';
if (isDarkMode) {
htmlElement.removeAttribute('data-theme');
localStorage.removeItem('theme');
} else {
htmlElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
}
}
isDarkMode(): boolean {
return document.documentElement.getAttribute('data-theme') === 'dark';
}
}