Skip to content

Commit 6f1ccda

Browse files
committed
added switching themes
1 parent 269171a commit 6f1ccda

File tree

6 files changed

+60
-21
lines changed

6 files changed

+60
-21
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import {Component, HostBinding} from '@angular/core';
2+
import {HelperService} from './helper.service';
3+
import {DashboardThemes} from './helper.interface';
24

35
@Component({
46
selector: 'theme-helper',
57
templateUrl: './helper.template.html',
68
styleUrls: ['./helper.style.scss']
79
})
810
export class HelperComponent {
11+
dashboardThemes = DashboardThemes;
912
@HostBinding('class.theme-helper') themeHelperClass = true;
1013
@HostBinding('class.theme-helper-opened') isOpened = false;
1114

15+
constructor(private helperService: HelperService) {}
16+
1217
toggle() {
1318
this.isOpened = !this.isOpened;
1419
}
20+
21+
changeTheme(theme: DashboardThemes) {
22+
this.helperService.onThemeChange.emit(theme);
23+
}
1524
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum DashboardThemes {
2+
LIGHT,
3+
DARK
4+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {EventEmitter} from '@angular/core';
2+
import {DashboardThemes} from './helper.interface';
3+
4+
export class HelperService {
5+
dashboardThemes = DashboardThemes;
6+
_dashboardTheme: DashboardThemes = this.dashboardThemes.DARK;
7+
onThemeChange: EventEmitter<any> = new EventEmitter();
8+
9+
constructor() {
10+
this.onThemeChange.subscribe((theme: DashboardThemes) => {
11+
this.dashboardTheme = theme;
12+
});
13+
}
14+
15+
set dashboardTheme(theme: DashboardThemes) {
16+
this._dashboardTheme = theme;
17+
}
18+
19+
get dashboardTheme() {
20+
return this._dashboardTheme;
21+
}
22+
}
23+

src/app/layout/helper/helper.template.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ <h6 class="mb-3">Theme</h6>
1010
</header>
1111
<div class="theme-switcher">
1212
<div class="theme mb-3">
13-
<input [checked]="true" type="radio" id="css-light" value="option2" name="theme-variant" aria-label="Sing Light" readOnly/>
14-
<label for="css-light">
13+
<input [checked]="helperService.dashboardTheme === dashboardThemes.LIGHT" type="radio" id="css-light" value="option2" name="theme-variant" aria-label="Sing Light" readOnly/>
14+
<label for="css-light" (click)="changeTheme(dashboardThemes.LIGHT)">
1515
<img class="theme-image" src="assets/img/theme-light.png" alt="light theme"/>
1616
</label>
1717
</div>
1818
<div class="theme">
19-
<input [checked]="false" type="radio" id="css-dark" value="option1" name="theme-variant" aria-label="Single Dark" readOnly/>
20-
<label for="css-dark">
19+
<input [checked]="helperService.dashboardTheme === dashboardThemes.DARK" type="radio" id="css-dark" value="option1" name="theme-variant" aria-label="Single Dark" readOnly/>
20+
<label for="css-dark" (click)="changeTheme(dashboardThemes.DARK)">
2121
<img class="theme-image" src="assets/img/theme-dark.png" alt="dark theme"/>
2222
</label>
2323
</div>

src/app/layout/layout.component.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import {
2-
Component,
3-
ViewEncapsulation,
4-
ElementRef, Renderer2,
5-
NgZone,
6-
ViewChild, HostBinding, OnInit
7-
} from '@angular/core';
8-
import {
9-
Router,
10-
Event as RouterEvent,
11-
NavigationStart,
12-
NavigationEnd,
13-
NavigationCancel,
14-
NavigationError
15-
} from '@angular/router';
16-
import { AppConfig } from '../app.config';
1+
import {Component, ElementRef, HostBinding, NgZone, OnInit, Renderer2, ViewChild, ViewEncapsulation} from '@angular/core';
2+
import {Event as RouterEvent, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router} from '@angular/router';
3+
import {AppConfig} from '../app.config';
4+
import {DashboardThemes} from './helper/helper.interface';
5+
import {HelperService} from './helper/helper.service';
176

187
declare let jQuery: any;
198
declare let Hammer: any;
@@ -28,6 +17,14 @@ export class LayoutComponent implements OnInit {
2817
@HostBinding('class.nav-static') navStatic: boolean;
2918
@HostBinding('class.chat-sidebar-opened') chatOpened: boolean = false;
3019
@HostBinding('class.app') appClass: boolean = true;
20+
@HostBinding('class.sing-dashboard') singDashboardClass: boolean = true;
21+
@HostBinding('class.dashboard-light') get dashboardLight() {
22+
return this.helperService.dashboardTheme === DashboardThemes.LIGHT;
23+
}
24+
@HostBinding('class.dashboard-dark') get dashboardDark() {
25+
return this.helperService.dashboardTheme === DashboardThemes.DARK;
26+
}
27+
3128
config: any;
3229
configFn: any;
3330
$sidebar: any;
@@ -40,7 +37,9 @@ export class LayoutComponent implements OnInit {
4037
el: ElementRef,
4138
router: Router,
4239
private renderer: Renderer2,
43-
private ngZone: NgZone) {
40+
private ngZone: NgZone,
41+
private helperService: HelperService
42+
) {
4443
Raphael.prototype.safari = function(): any { return; };
4544
this.el = el;
4645
this.config = config.getConfig();

src/app/layout/layout.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { NotificationsComponent } from './notifications/notifications.component'
1919
import { LoadingBarRouterModule } from '@ngx-loading-bar/router';
2020
import {HelperComponent} from './helper/helper.component';
2121
import {NewWidgetModule} from './new-widget/widget.module';
22+
import {HelperService} from './helper/helper.service';
2223

2324
@NgModule({
2425
imports: [
@@ -40,6 +41,9 @@ import {NewWidgetModule} from './new-widget/widget.module';
4041
NotificationsLoadDirective,
4142
ChatMessageComponent,
4243
HelperComponent
44+
],
45+
providers: [
46+
HelperService
4347
]
4448
})
4549
export class LayoutModule {

0 commit comments

Comments
 (0)