themes.service.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Injectable } from '@angular/core';
  2. @Injectable({
  3. providedIn: 'root',
  4. })
  5. export class ThemesService {
  6. themes: ColorTheme[];
  7. currentTheme: ColorTheme;
  8. constructor() {
  9. this.themes = [
  10. {
  11. value: 'neutral',
  12. label: 'themeNeutral',
  13. },
  14. {
  15. value: 'modern',
  16. label: 'themeModern',
  17. },
  18. {
  19. value: 'classic',
  20. label: 'themeClassic',
  21. },
  22. ];
  23. this.selectTheme(this.themes[0]);
  24. }
  25. selectTheme(theme: ColorTheme) {
  26. this.currentTheme = theme;
  27. document.body.setAttribute('data-theme', theme.value); // Needed to let ngb-popover and ngb-modals work properly with themes
  28. }
  29. getAvailableThemes(): ColorTheme[] {
  30. return this.themes;
  31. }
  32. getCurrentTheme(): ColorTheme {
  33. return this.currentTheme;
  34. }
  35. }
  36. export interface ColorTheme {
  37. value: string;
  38. label: string; // Key in the JSON localization for the label
  39. }