Skip to content

Commit

Permalink
feat(theme): Add menu button to switch between dark and light themes (#…
Browse files Browse the repository at this point in the history
…939)

* feat(theme): Add toggle button to switch between dark and light themes

* chore(): use `[]` rather than `{{}}` in class
  • Loading branch information
jeremysmartt authored and emoralesb05 committed Oct 20, 2017
1 parent d927265 commit 4e80434
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<td-layout #layout
[class]="activeTheme"
[dir]="dir"
[mode]="(media.registerQuery('gt-md') | async) ? 'side' : 'over'"
[sidenavWidth]="(media.registerQuery('gt-md') | async) ? '257px' : '320px'">
Expand Down
7 changes: 7 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export class DocsAppComponent implements AfterViewInit {
this.dir = getDirection();
}

get activeTheme(): string {
return localStorage.getItem('theme');
}
theme(theme: string): void {
localStorage.setItem('theme', theme);
}

ngAfterViewInit(): void {
// broadcast to all listener observables when loading the page
setTimeout(() => { // workaround since MatSidenav has issues redrawing at the beggining
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/toolbar/toolbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,13 @@ <h4 matLine><span class="text-wrap">CDK and [email protected] support</span></h4>
<mat-icon>swap_horiz</mat-icon>
<span>{{dir.toUpperCase()}}</span>
</button>
<button mat-menu-item *ngIf="activeTheme === 'theme-dark'" (click)="theme('default-theme')">
<mat-icon>brightness_high</mat-icon>
<span>Light Mode</span>
</button>
<button mat-menu-item *ngIf="activeTheme != 'theme-dark'" (click)="theme('theme-dark')">
<mat-icon>brightness_low</mat-icon>
<span>Dark Mode</span>
</button>
</mat-menu>
</div>
7 changes: 7 additions & 0 deletions src/app/components/toolbar/toolbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ export class ToolbarComponent {
this._dir.dir = dir;
setDirection(dir);
}

get activeTheme(): string {
return localStorage.getItem('theme');
}
theme(theme: string): void {
localStorage.setItem('theme', theme);
}
}

0 comments on commit 4e80434

Please sign in to comment.