2018-05-11 17:25:02 +03:00
|
|
|
import { Component, OnInit, Input } from '@angular/core';
|
2017-09-20 12:54:26 +03:00
|
|
|
import { NbThemeService } from '@nebular/theme';
|
|
|
|
|
import { NbJSThemeOptions } from '@nebular/theme/services/js-themes/theme.options';
|
2017-09-20 15:48:30 +03:00
|
|
|
import { AnalyticsService } from '../../../@core/utils/analytics.service';
|
2017-09-20 12:54:26 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ngx-theme-switcher',
|
|
|
|
|
template: `
|
2018-05-11 17:25:02 +03:00
|
|
|
<ngx-switcher
|
|
|
|
|
[firstValue]="false"
|
|
|
|
|
[secondValue]="true"
|
|
|
|
|
[firstValueLabel]="'Light'"
|
|
|
|
|
[secondValueLabel]="'Cosmic'"
|
|
|
|
|
[value]="currentBoolTheme()"
|
|
|
|
|
(valueChange)="toggleTheme($event)"
|
|
|
|
|
[vertical]="vertical"
|
|
|
|
|
>
|
|
|
|
|
</ngx-switcher>
|
2017-09-20 12:54:26 +03:00
|
|
|
`,
|
|
|
|
|
})
|
|
|
|
|
export class ThemeSwitcherComponent implements OnInit {
|
|
|
|
|
theme: NbJSThemeOptions;
|
|
|
|
|
|
2018-05-11 17:25:02 +03:00
|
|
|
firstTheme = 'default';
|
|
|
|
|
secondTheme = 'cosmic';
|
|
|
|
|
|
|
|
|
|
@Input() vertical: boolean = false;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private themeService: NbThemeService,
|
|
|
|
|
private analyticsService: AnalyticsService,
|
|
|
|
|
) {}
|
2017-09-20 12:54:26 +03:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.themeService.getJsTheme()
|
|
|
|
|
.subscribe((theme: NbJSThemeOptions) => this.theme = theme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleTheme(theme: boolean) {
|
2018-05-11 17:25:02 +03:00
|
|
|
const themeName = this.boolToTheme(theme);
|
|
|
|
|
this.themeService.changeTheme(themeName);
|
|
|
|
|
|
2017-09-20 15:48:30 +03:00
|
|
|
this.analyticsService.trackEvent('switchTheme');
|
2017-09-20 12:54:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentBoolTheme() {
|
|
|
|
|
return this.themeToBool(this.theme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private themeToBool(theme: NbJSThemeOptions) {
|
2018-05-11 17:25:02 +03:00
|
|
|
return theme.name === this.secondTheme;
|
2017-09-20 12:54:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolToTheme(theme: boolean) {
|
2018-05-11 17:25:02 +03:00
|
|
|
return theme ? this.secondTheme : this.firstTheme;
|
2017-09-20 12:54:26 +03:00
|
|
|
}
|
|
|
|
|
}
|