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

Commit 133d494

Browse files
refactor(ToolbarComponent): to resolve layout issue with sidenav
1 parent 34d68e3 commit 133d494

11 files changed

+75
-66
lines changed

src/app/app.component.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
<div class="app-fullpage">
22
<header>
3-
<app-toolbar></app-toolbar>
3+
<app-toolbar (navToggle)="sidenav.toggle()"></app-toolbar>
44
</header>
55
<main class="app-content">
6-
<router-outlet></router-outlet>
6+
<mat-sidenav-container>
7+
<mat-sidenav #sidenav role="navigation">
8+
<mat-nav-list (click)="sidenav.toggle()">
9+
<a *ngFor="let menu of menus" mat-list-item routerLinkActive="active" [routerLinkActiveOptions]="menu.options" [routerLink]="menu.link">
10+
{{menu.title}}
11+
</a>
12+
</mat-nav-list>
13+
</mat-sidenav>
14+
<router-outlet></router-outlet>
15+
</mat-sidenav-container>
716
</main>
817
</div>

src/app/app.component.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@
1717
display: flex;
1818
flex-direction: column;
1919
}
20+
21+
mat-sidenav-container {
22+
flex: 1 1 auto;
23+
width: 100%;
24+
height: calc(100vh - 64px);
25+
}
26+
27+
mat-sidenav {
28+
width: 200px;
29+
}

src/app/app.component.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RouterTestingModule } from "@angular/router/testing";
33
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
44
import { AppComponent } from "./app.component";
55
import { ToolbarModule } from "./toolbar/toolbar.module";
6+
import { MatSidenavModule } from "@angular/material";
67

78
describe("AppComponent", () => {
89
let component: AppComponent;
@@ -11,7 +12,12 @@ describe("AppComponent", () => {
1112
beforeEach(
1213
async(() => {
1314
TestBed.configureTestingModule({
14-
imports: [RouterTestingModule, BrowserAnimationsModule, ToolbarModule],
15+
imports: [
16+
RouterTestingModule,
17+
BrowserAnimationsModule,
18+
ToolbarModule,
19+
MatSidenavModule
20+
],
1521
declarations: [AppComponent]
1622
}).compileComponents();
1723
})

src/app/app.component.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
import { Component } from "@angular/core";
22

3+
interface Menu {
4+
title: string;
5+
link: string;
6+
options: { exact: boolean };
7+
}
8+
39
@Component({
410
selector: "app-root",
511
templateUrl: "./app.component.html",
612
styleUrls: ["./app.component.scss"]
713
})
8-
export class AppComponent {}
14+
export class AppComponent {
15+
menus: Menu[] = [
16+
{
17+
title: "Home",
18+
link: "/",
19+
options: { exact: true }
20+
},
21+
{
22+
title: "Operators",
23+
link: "/operators",
24+
options: { exact: false }
25+
},
26+
{
27+
title: "Companies",
28+
link: "/companies",
29+
options: { exact: false }
30+
},
31+
{
32+
title: "Team",
33+
link: "/team",
34+
options: { exact: false }
35+
}
36+
];
37+
}

src/app/app.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import { RouterModule, PreloadAllModules } from "@angular/router";
66
import { AppComponent } from "./app.component";
77
import { RXJS_DOC_ROUTES } from "./app.routing";
88
import { ToolbarModule } from "./toolbar/toolbar.module";
9+
import { MatSidenavModule, MatListModule } from "@angular/material";
910

1011
@NgModule({
1112
declarations: [AppComponent],
1213
imports: [
1314
BrowserModule,
1415
BrowserAnimationsModule,
1516
ToolbarModule,
17+
MatListModule,
18+
MatSidenavModule,
1619
RouterModule.forRoot(RXJS_DOC_ROUTES, {
1720
preloadingStrategy: PreloadAllModules
1821
})
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<p>
2-
companies works!
3-
</p>
1+
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit } from "@angular/core";
22

33
@Component({
4-
selector: 'app-companies',
5-
templateUrl: './companies.component.html',
6-
styleUrls: ['./companies.component.scss']
4+
selector: "app-companies",
5+
templateUrl: "./companies.component.html",
6+
styleUrls: ["./companies.component.scss"]
77
})
88
export class CompaniesComponent implements OnInit {
9+
constructor() {}
910

10-
constructor() { }
11-
12-
ngOnInit() {
13-
}
11+
ngOnInit() {}
1412
}
15-

src/app/companies/companies.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NgModule } from "@angular/core";
33
import { CompaniesComponent } from "./companies.component";
44
import { routing } from "./companies.routing";
55
import { SharedModule } from "../shared.module";
6+
import { environment } from "../../environments/environment";
67

78
@NgModule({
89
imports: [routing, SharedModule],
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
<mat-toolbar color="accent" class="mat-elevation-z6">
2-
<button mat-icon-button (click)="sidenav.toggle()" aria-label="menu">
2+
<button mat-icon-button (click)="navOpen()" aria-label="menu">
33
<mat-icon>
44
menu
55
</mat-icon>
66
</button>
77
<span class="title" fxFlex> RxJS Docs </span>
8-
98
<a aria-label="GitHub Repository" class="mat-button" href="https://github.com/ReactiveX" aria-disabled="false">
109
<span class="mat-button-wrapper">
1110
<img src="../../../assets/img/GitHub-Mark-Light-64px.png"> GitHub
1211
</span>
1312
</a>
1413
</mat-toolbar>
15-
<mat-sidenav-container>
16-
<mat-sidenav #sidenav role="navigation">
17-
<mat-nav-list (click)="sidenav.toggle()">
18-
<a *ngFor="let menu of menus" mat-list-item routerLinkActive="active" [routerLinkActiveOptions]="menu.options" [routerLink]="menu.link">
19-
{{menu.title}}
20-
</a>
21-
</mat-nav-list>
22-
</mat-sidenav>
23-
</mat-sidenav-container>

src/app/toolbar/toolbar.component.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,3 @@ img {
66
padding: 0 16px;
77
font-weight: 600;
88
}
9-
10-
mat-sidenav-container {
11-
flex: 1 1 auto;
12-
width: 100%;
13-
height: calc(100vh - 64px);
14-
}
15-
16-
mat-sidenav {
17-
width: 200px;
18-
}

0 commit comments

Comments
 (0)