UNPKG

@bcodes/ngx-theme-service

Version:

Configurable theme switching service for use with CSS variables

33 lines (32 loc) 1.31 kB
import { InjectionToken, OnDestroy } from '@angular/core'; import { Observable } from 'rxjs'; /** Apply a CSS class to the `<html>` element when switching themes */ export interface ThemeTransitionConfig { readonly className: string; /** remove class after duration in milliseconds */ readonly duration: number; } export interface ThemeServiceConfig { readonly themes: ReadonlyArray<string>; /** theme that should always be on the target element if using explicit default theme */ readonly defaultTheme?: string; /** optional transition configuration */ readonly transitionConfig?: ThemeTransitionConfig; /** themes applied to <html> by default. Supply CSS selector to change */ readonly targetElementSelector?: string; } export declare const THEME_CONFIG: InjectionToken<ThemeServiceConfig>; export declare class ThemeService implements OnDestroy { private config; private document; private stopListening$; private selectedTheme; selectedTheme$: Observable<string>; constructor(config: ThemeServiceConfig, document: Document); switchTheme(className: string): void; private setupSubscription; private removeClasses; private addClasses; private readonly targetElement; ngOnDestroy(): void; }