@@ -3,8 +3,8 @@ import { DOCUMENT } from "@angular/common";
33import { TEDI_THEME_DEFAULT_TOKEN } from "../../tokens/theme.token" ;
44import { cookieSignal } from "../../utils/cookies.util" ;
55
6- export type Theme = "default" | "dark" | "rit ";
7- export const AVAILABLE_THEMES : Theme [ ] = [ "default" , "dark" , "rit" ] ;
6+ export type TEDITheme = "default" | "dark" ;
7+ export type Theme = TEDITheme | string ;
88export const THEME_CLASS_PREFIX = "tedi-theme--" ;
99export const THEME_COOKIE_NAME = "tedi-theme" ;
1010export const THEME_FALLBACK_VALUE : Theme = "default" ;
@@ -14,17 +14,24 @@ export class ThemeService {
1414 private readonly document = inject ( DOCUMENT ) ;
1515 private readonly defaultTheme = inject ( TEDI_THEME_DEFAULT_TOKEN ) ;
1616
17- readonly theme = cookieSignal < Theme > ( THEME_COOKIE_NAME , this . defaultTheme ) ;
17+ readonly theme = cookieSignal < Theme > (
18+ THEME_COOKIE_NAME ,
19+ this . defaultTheme
20+ ) ;
1821
1922 constructor ( ) {
2023 effect ( ( ) => {
2124 const html = this . document . documentElement ;
25+ const nextTheme = this . theme ( ) ;
2226
23- for ( const t of AVAILABLE_THEMES ) {
24- html . classList . remove ( `${ THEME_CLASS_PREFIX } ${ t } ` ) ;
27+ for ( let i = html . classList . length - 1 ; i >= 0 ; i -- ) {
28+ const className = html . classList . item ( i ) ;
29+ if ( className ?. startsWith ( THEME_CLASS_PREFIX ) ) {
30+ html . classList . remove ( className ) ;
31+ }
2532 }
2633
27- html . classList . add ( `${ THEME_CLASS_PREFIX } ${ this . theme ( ) } ` ) ;
34+ html . classList . add ( `${ THEME_CLASS_PREFIX } ${ nextTheme } ` ) ;
2835 } ) ;
2936 }
30- }
37+ }
0 commit comments