Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
feat(examples): use router for navigation between examples
Browse files Browse the repository at this point in the history
 - component and index pages implemented.
 - remove debounce on peekaboo listener as it causes a flicker when switching routes.
 - add ComponentsService for querying the known component metadata.
 - add NavigationService for managing global navigation state (like where the next/prev footer buttons navigate to.)
 - include router.dev.js for ng2 router support.
  • Loading branch information
justindujardin committed Dec 28, 2015
1 parent 3d42aa6 commit 380625e
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 40 deletions.
48 changes: 28 additions & 20 deletions examples/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ <h2>
</md-toolbar>
<md-toolbar class="fixed-toolbar">
<div class="md-toolbar-tools">
<button md-button class="md-hamburger md-icon-button" aria-label="Settings">
<button md-button
class="md-hamburger md-icon-button"
[routerLink]="['Index']"
aria-label="Home">
<i md-icon class="md-light">menu</i>
</button>
<h2 md-peekaboo
Expand All @@ -34,25 +37,30 @@ <h2>
<md-toolbar class="shadow-toolbar md-whiteframe-z1" md-peekaboo [break]="190" breakAction="show"></md-toolbar>

<md-content class="examples" md-scroll-y layout-padding>

<h1 class="examples-title">Getting Started</h1>
<p class="examples-intro">
There are many examples on this page. Here's the <a href="coverage/" target="_blank">test coverage</a> report, and a
<a href="http://plnkr.co/edit/CnDUjVufVnevluFOBvdD?p=preview" target="_blank">plunkr template</a> to get you going.
</p>

<nav class="examples-toc">
<h1>Components</h1>
<ul>
<li *ngFor="#value of meta"><a href="#{{value.id}}">{{value.name}}</a></li>
</ul>
</nav>
<router-outlet></router-outlet>
</md-content>


<section *ngFor="#value of meta" [id]="value.id">
<h1>{{ value.name }}</h1>
<example *ngFor="#demo of value.examples" [model]="demo"></example>
<md-divider></md-divider>
</section>
<footer>
<div class="container" layout="row" layout-align="center center">
<a class="previous" flex="50" *ngIf="navigation.prevLink"
layout="row" layout-align="start center"
[routerLink]="navigation.prevLink.routeLink">
<i md-icon>arrow_back</i>
<span layout="column" hide-sm>
<span class="label">Previous</span>
<span class="name md-title">{{navigation.prevLink.brief}}</span>
</span>

</md-content>
</a>
<a class="next" flex="50" *ngIf="navigation.nextLink"
layout="row" layout-align="end center"
[routerLink]="navigation.nextLink.routeLink">
<span layout="column">
<span class="label">Next</span>
<span class="name md-title">{{navigation.nextLink.brief}}</span>
</span>
<i md-icon>arrow_forward</i>
</a>
</div>
</footer>
64 changes: 62 additions & 2 deletions examples/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,73 @@ $md-font-url: '../public/font/';

demos-app {

md-content.examples {
width: 800px;
@media screen and (max-width: $layout-breakpoint-md) {
width: 640px;
}
@media screen and (max-width: $layout-breakpoint-sm) {
width: 480px;
}
@media screen and (max-width: $layout-breakpoint-sm) {
width: 360px;
}
}

footer {
background-color: md-color($md-primary);
width: 100%;
.container {
margin: auto;
padding: 0 25px;
width: 80%;
@media screen and (max-width: $layout-breakpoint-md) {
width: 640px;
}
@media screen and (max-width: $layout-breakpoint-sm) {
width: 480px;
}
@media screen and (max-width: $layout-breakpoint-sm) {
width: 360px;
}

a.previous, a.next {
font-family: $font-family;
color: md-color($md-primary, 50);
@include md-medium-tall-toolbar();
text-decoration: none;
&:visited {
color: md-color($md-primary, 100);
}
.label {
color: md-color($md-primary, 200);
}
.name {
font-weight: 500;
white-space: nowrap;
}
i {
padding-top: 24px;
}
}
.previous {
text-align: left;
}
.next {
text-align: right;
}

}
}

> md-toolbar {
font-family: $font-family;
}
.fixed-toolbar, .shadow-toolbar {
position: fixed;
top: 0;
left:0;
right:0;
left: 0;
right: 0;
z-index: $z-index-sidenav;
&.shadow-toolbar {
z-index: $z-index-sidenav - 1;
Expand Down Expand Up @@ -73,6 +132,7 @@ demos-app {

.examples {
padding-top: 80px;
min-height: 640px;

.examples-title {
color: md-color($md-primary);
Expand Down
43 changes: 27 additions & 16 deletions examples/app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import {Component, View} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router';

import {MATERIAL_DIRECTIVES, MATERIAL_PROVIDERS} from '../ng2-material/all';
import {ROUTER_DIRECTIVES, RouteConfig} from 'angular2/router';

import {DEMO_DIRECTIVES} from './all';
import Example from './example';
import {Http, Response, HTTP_PROVIDERS} from 'angular2/http';
import {IndexPage} from "./routes/index";
import {ComponentPage} from "./routes/component";
import {HashLocationStrategy} from "angular2/router";
import {LocationStrategy} from "angular2/router";
import {bind} from "angular2/core";
import {ComponentsService} from "./services/components";
import {Router} from "angular2/router";
import {Query} from "angular2/core";
import {QueryList} from "angular2/core";
import {NavigationService} from "./services/navigation";
import {AfterViewInit} from "angular2/core";

//
// PLUNKR for ng2: http://plnkr.co/edit/UPJESEgyKFsm4hyW4fWR
Expand All @@ -21,37 +35,34 @@ export interface IExampleData {
name:string;
}

@RouteConfig([
{path: '/', name: 'Index', component: IndexPage, useAsDefault: true},
{path: '/components/:id', name: 'Component', component: ComponentPage}
])

@Component({
selector: 'demos-app'
})
@View({
templateUrl: 'examples/app.html',
directives: [MATERIAL_DIRECTIVES, Example, DEMO_DIRECTIVES]
directives: [MATERIAL_DIRECTIVES, ROUTER_DIRECTIVES, Example, DEMO_DIRECTIVES]
})
export class DemosApp {
meta: any;

version: string;

constructor(http: Http) {
http.get('public/meta.json')
.subscribe((res: Response) => {
this.meta = res.json();
// HACKS: use to filter down to a single example for testing
//let data = res.json();
//let results = [];
//data.forEach((d) => {
// if(d.name === 'Button'){
// results.push(d);
// }
//});
//this.meta = results;
});
constructor(http: Http, public navigation: NavigationService) {
http.get('public/version.json')
.subscribe((res: Response) => {
this.version = res.json().version;
});
}

}

bootstrap(DemosApp, [HTTP_PROVIDERS, MATERIAL_PROVIDERS]);
bootstrap(DemosApp, [
HTTP_PROVIDERS, ROUTER_PROVIDERS, MATERIAL_PROVIDERS,
ComponentsService, NavigationService,
bind(LocationStrategy).toClass(HashLocationStrategy)
]);
2 changes: 1 addition & 1 deletion examples/example.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.layout-content,
.doc-content {
max-width: 864px;
min-width: 400px;
min-width: 300px;
margin: 16px;
box-sizing: border-box;
}
Expand Down
49 changes: 49 additions & 0 deletions examples/routes/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {Component} from 'angular2/core';
import {RouteConfig, RouterOutlet} from 'angular2/router';
import {RouteParams} from "angular2/router";
import {Router} from "angular2/router";
import {OnInit} from "angular2/core";
import {ComponentsService, IComponentMeta} from "../services/components";
import {MATERIAL_DIRECTIVES} from "../../ng2-material/all";
import Example from "../example";
import {ROUTER_DIRECTIVES} from "angular2/router";
import {NavigationService} from "../services/navigation";

@Component({
selector: 'component-page',
template: `
<h1 class="examples-title">{{ value.name }}</h1>
<p class="examples-intro" *ngIf="value.readme" [innerHtml]="value.readme"></p>
<example *ngFor="#demo of value.examples" [model]="demo"></example>
<md-divider></md-divider>`,
directives: [Example, ROUTER_DIRECTIVES, MATERIAL_DIRECTIVES]
})
export class ComponentPage implements OnInit {

public id: string;

public value: IComponentMeta = <IComponentMeta>{};

public next: IComponentMeta = null;
public previous: IComponentMeta = null;

constructor(private _components: ComponentsService,
private _navigation: NavigationService,
private _routeParams: RouteParams) {
}

ngOnInit() {
let id = this._routeParams.get('id');
this._components.getComponent(id).then((c: IComponentMeta) => {
this.value = c;
this._components.getNext(c).then((next: IComponentMeta) => {
this._navigation.nextLink = this._navigation.componentLink(next);
});
this._components.getPrevious(c).then((previous: IComponentMeta) => {
this._navigation.prevLink = this._navigation.componentLink(previous);
});
});
}

}
42 changes: 42 additions & 0 deletions examples/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {Component} from 'angular2/core';
import {RouteConfig, RouterOutlet} from 'angular2/router';
import {ComponentsService} from "../services/components";
import {IComponentMeta} from "../services/components";
import {OnInit} from "angular2/core";
import {NavigationService} from "../services/navigation";
import {MATERIAL_DIRECTIVES} from "ng2-material/all";
import {ROUTER_DIRECTIVES} from "angular2/router";

@Component({
template: `
<h1 class="examples-title">Getting Started</h1>
<p class="examples-intro">
There are many examples on this page. Here's the <a href="coverage/" target="_blank">test coverage</a> report, and a
<a href="http://plnkr.co/edit/CnDUjVufVnevluFOBvdD?p=preview" target="_blank">plunkr template</a> to get you going.
</p>
<nav class="examples-toc">
<h1>Components</h1>
<ul>
<li *ngFor="#value of components"><a [routerLink]="['Component', {id: value.id}]">{{value.name}}</a></li>
</ul>
</nav>`,
directives: [ROUTER_DIRECTIVES, MATERIAL_DIRECTIVES]
})
export class IndexPage implements OnInit {
public components: IComponentMeta[] = [];

constructor(private _components: ComponentsService,
public navigation: NavigationService) {
}

ngOnInit(): any {
this._components.getComponents()
.then((comps) => {
this.components = comps;
this.navigation.prevLink = this.navigation.componentLink(comps[comps.length - 1]);
this.navigation.nextLink = this.navigation.componentLink(comps[0]);
});
}

}
Loading

0 comments on commit 380625e

Please sign in to comment.