Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 3d7724e

Browse files
authored
chore(demos): Update demos to Angular MDC v0.38.2 (#1232)
1 parent f40759f commit 3d7724e

File tree

36 files changed

+5030
-5051
lines changed

36 files changed

+5030
-5051
lines changed

demos/app-layout/app-layout.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<mdc-app-bar class="demo-top-app-bar" #appbar fixed [fixedAdjustElement]="mainContent">
22
<mdc-app-bar-row>
33
<mdc-app-bar-section align="start" title="Angular MDC">
4-
<mdc-icon mdcAppBarNavIcon (click)="appdrawer.open()" *ngIf="mobile">menu</mdc-icon>
4+
<mdc-icon mdcAppBarNavIcon (click)="appdrawer.open()" *ngIf="isScreenSmall() || appbar.isCollapsed()">menu</mdc-icon>
55
</mdc-app-bar-section>
66
<mdc-app-bar-section align="end">
77
<a mdcAppBarActionItem href="https://github.com/trimox/angular-mdc-web" alt="GitHub" target="_blank" rel="noopener noreferrer">
@@ -14,7 +14,7 @@
1414
</mdc-app-bar>
1515

1616
<div #mainContent>
17-
<mdc-drawer #appdrawer="mdcDrawer" [drawer]="mobile ? 'temporary' : 'permanent'" fixed class="demo-drawer--cursor-pointer">
17+
<mdc-drawer #appdrawer="mdcDrawer" [drawer]="isScreenSmall() || appbar.isCollapsed() ? 'temporary' : 'permanent'" fixed class="demo-drawer">
1818
<mdc-drawer-content>
1919
<mdc-list-group>
2020
<mdc-list>
@@ -69,7 +69,7 @@
6969
<router-outlet></router-outlet>
7070
</div>
7171

72-
<div class="demo-app-bar-control-container demo-layout__row-with-button" #demoAppBar>
72+
<div class="demo-app-bar-control-container demo-layout__row-with-button" #demoAppBarControls>
7373
<div class="demo-layout__row">
7474
<button mdc-button (click)="appbar.fixed = !appbar.fixed">Fixed: {{appbar.fixed ? 'On' : 'Off'}}</button>
7575
<button mdc-button (click)="appbar.prominent = !appbar.prominent">Promient: {{appbar.prominent ? 'On' : 'Off'}}</button>

demos/app-layout/app-layout.ts

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
1+
import { Component, NgZone, OnInit, OnDestroy, ViewChild } from '@angular/core';
22
import { Router, NavigationEnd } from '@angular/router';
3+
import { filter, takeUntil } from 'rxjs/operators';
4+
import { Subject } from 'rxjs';
5+
6+
const SMALL_WIDTH_BREAKPOINT = 1240;
37

48
import { MdcAppBar } from '@angular-mdc/web';
59

610
@Component({
711
selector: 'app-layout',
812
templateUrl: './app-layout.html'
913
})
10-
export class AppLayout implements OnInit {
14+
export class AppLayout implements OnInit, OnDestroy {
15+
/** Emits whenever the component is destroyed. */
16+
private _destroy = new Subject<void>();
17+
18+
private _mediaMatcher: MediaQueryList = matchMedia(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`);
19+
20+
@ViewChild('demoAppBarControls') demoAppBarControls;
21+
@ViewChild(MdcAppBar) appBar: MdcAppBar;
22+
1123
startVisible: boolean;
1224
buttonVisible: boolean;
1325
inputVisible: boolean;
1426
listVisible: boolean;
1527

16-
mobile: boolean;
17-
1828
navigationLinks = [
1929
{ name: 'App Bar', route: 'app-bar-demo', icon: 'remove' },
2030
{ name: 'Card', route: 'card-demo', icon: 'credit_card' },
@@ -59,25 +69,32 @@ export class AppLayout implements OnInit {
5969
{ name: 'Angular CLI', route: 'cli-guide' }
6070
];
6171

62-
@ViewChild('appbar') appbar: MdcAppBar;
63-
@ViewChild('demoAppBar') demoAppBar: ElementRef;
72+
constructor(
73+
private _router: Router,
74+
private _ngZone: NgZone) {
75+
this._mediaMatcher.addListener(mql => this._ngZone.run(() => this._mediaMatcher = mql));
76+
}
6477

65-
constructor(private _router: Router) { }
78+
isScreenSmall(): boolean {
79+
return this._mediaMatcher.matches;
80+
}
6681

67-
ngOnInit() {
68-
this._router.events.subscribe(event => {
69-
if (this._router.url.includes('/app-bar-demo')) {
70-
if (event instanceof NavigationEnd) {
71-
this.demoAppBar.nativeElement.style.display = 'block';
82+
ngOnInit(): void {
83+
this._router.events
84+
.pipe(takeUntil(this._destroy),
85+
filter(event => event instanceof NavigationEnd))
86+
.subscribe(_ => {
87+
if (this._router.url.includes('/app-bar-demo')) {
88+
this.demoAppBarControls.nativeElement.style.display = 'block';
7289
} else {
73-
this.demoAppBar.nativeElement.style.display = 'none';
74-
this.appbar.fixed = true;
90+
this.demoAppBarControls.nativeElement.style.display = 'none';
91+
this.appBar.fixed = true; // reset to fixed after navigation off app-bar demo
7592
}
76-
}
77-
});
93+
});
94+
}
7895

79-
if (window.screen.width <= 1200) {
80-
this.mobile = true;
81-
}
96+
ngOnDestroy(): void {
97+
this._destroy.next();
98+
this._destroy.complete();
8299
}
83100
}

0 commit comments

Comments
 (0)