Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit ff9cf2e

Browse files
authored
Expand component view with example viewer (#33)
* Add DocumentationItems service and use throughout app * Add content to component-view sidenav * Rename top nav link to "Docs" * Make example viewer work with a set of examples * Add example components for testing * Render raw examples in the Examples tab * Add rough example-viewer structure and styles * Load example sources into example viewer * Remove testing examples except for button * Add script to syntax highlight an example and hljs style * Example assets loaded via document-viewer * Introduce shared-module for shared/ directory * Add missing RouterModule to SharedModule
1 parent f84ed72 commit ff9cf2e

27 files changed

+492
-86
lines changed

src/app/app-module.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import {HttpModule} from '@angular/http';
66
import {MaterialModule} from '@angular/material';
77
import {MaterialDocsApp} from './material-docs-app';
88
import {Homepage} from './pages/homepage/homepage';
9-
import {NavBar} from './shared/navbar/navbar';
109
import {routing} from './routes';
1110
import {ComponentList} from './pages/component-list/component-list';
12-
import {DocViewerModule} from './shared/doc-viewer/index';
13-
import {ExampleViewerModule} from './shared/example-viewer/index';
1411
import {ComponentViewer} from './pages/component-viewer/component-viewer';
12+
import {ExampleModule} from './examples/example-module';
13+
import {SharedModule} from './shared/shared-module';
1514

1615

1716
@NgModule({
@@ -20,12 +19,11 @@ import {ComponentViewer} from './pages/component-viewer/component-viewer';
2019
ComponentList,
2120
ComponentViewer,
2221
Homepage,
23-
NavBar,
2422
],
2523
imports: [
2624
BrowserModule,
27-
DocViewerModule,
28-
ExampleViewerModule,
25+
ExampleModule,
26+
SharedModule,
2927
FormsModule,
3028
HttpModule,
3129
MaterialModule.forRoot(),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button md-button>Click me!</button>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Component} from '@angular/core';
2+
3+
4+
@Component({
5+
selector: 'button-overview-example',
6+
templateUrl: './button-overview-example.html',
7+
})
8+
export class ButtonOverviewExample {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="example">
2+
<h3>Normal Buttons</h3>
3+
<div class="button-row">
4+
<button md-button>Flat button</button>
5+
<button md-raised-button>Raised button</button>
6+
<button md-fab><md-icon>check</md-icon></button>
7+
<button md-mini-fab><md-icon>check</md-icon></button>
8+
</div>
9+
10+
<h3>Link Buttons</h3>
11+
<div class="button-row">
12+
<a md-button routerLink=".">Flat button</a>
13+
<a md-raised-button routerLink=".">Raised button</a>
14+
<a md-fab routerLink="."><md-icon>check</md-icon></a>
15+
<a md-mini-fab routerLink="."><md-icon>check</md-icon></a>
16+
</div>
17+
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.example {
2+
width: 500px;
3+
}
4+
5+
.button-row {
6+
display: flex;
7+
align-items: center;
8+
justify-content: space-around;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Component} from '@angular/core';
2+
3+
4+
@Component({
5+
selector: 'button-types-example',
6+
templateUrl: './button-types-example.html',
7+
styleUrls: ['./button-types-example.scss'],
8+
})
9+
export class ButtonTypesExample {}

src/app/examples/example-module.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {NgModule} from '@angular/core';
2+
import {MaterialModule} from '@angular/material';
3+
import {ButtonOverviewExample} from './button-overview/button-overview-example';
4+
import {ButtonTypesExample} from './button-types/button-types-example';
5+
6+
7+
/**
8+
* The list of example components.
9+
* Key is the example name which will be used in `material-docs-example="key"`.
10+
* Value is the component.
11+
*/
12+
13+
export const EXAMPLE_COMPONENTS = {
14+
'button-overview': ButtonOverviewExample,
15+
'button-types': ButtonTypesExample
16+
};
17+
18+
/**
19+
* The list of all example components.
20+
* We need to put them in both `declarations` and `entryComponents` to make them work.
21+
*/
22+
export const EXAMPLE_LIST = [
23+
ButtonOverviewExample,
24+
ButtonTypesExample,
25+
];
26+
27+
@NgModule({
28+
declarations: EXAMPLE_LIST,
29+
entryComponents: EXAMPLE_LIST,
30+
imports: [
31+
MaterialModule.forRoot(),
32+
]
33+
})
34+
export class ExampleModule { }
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<a *ngFor="let component of componentItems"
2-
class="docs-component-list-item"
3-
[routerLink]="['/component/', component.id]">
4-
<img src="../../../assets/img/components/{{component.src}}.svg"
5-
class="docs-component-list-item-icon"
6-
[alt]="component.name">
7-
{{component.name}}
8-
</a>
1+
<div *ngFor="let category of docItems.getItemsInCategories()" class="docs-component-list-category">
2+
<h2>{{category.name}}</h2>
3+
<a *ngFor="let component of category.items"
4+
class="docs-component-list-item"
5+
[routerLink]="['/component/', component.id]">
6+
<img src="../../../assets/img/components/{{component.id}}.svg"
7+
class="docs-component-list-item-icon"
8+
[alt]="component.name">
9+
{{component.name}}
10+
</a>
11+
</div>

src/app/pages/component-list/component-list.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
@import '~@angular/material/button/button-base';
2+
3+
4+
.docs-component-list-category {
5+
margin: 50px;
6+
}
7+
18
.docs-component-list-item {
29
display: inline-flex;
310
flex-direction: column;
Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
11
import {Component} from '@angular/core';
2+
import {DocumentationItems} from '../../shared/documentation-items/documentation-items';
23

34
@Component({
45
selector: 'app-components',
56
templateUrl: './component-list.html',
67
styleUrls: ['./component-list.scss']
78
})
89
export class ComponentList {
9-
componentItems = [
10-
{id: 'button', name: 'Button', src: 'button'},
11-
{id: 'checkbox', name: 'Checkbox', src: 'checkbox'},
12-
{id: 'radio-button', name: 'Radio button', src: 'radio'},
13-
{id: 'button-toggle', name: 'Button toggle', src: 'button-toggle'},
14-
{id: 'input', name: 'Input', src: 'input'},
15-
{id: 'textarea', name: 'Textarea', src: 'textarea'},
16-
{id: 'select', name: 'Select', src: 'select'},
17-
{id: 'slide-toggle', name: 'Slide toggle', src: 'slide-toggle'},
18-
{id: 'slider', name: 'Slider', src: 'slider'},
19-
20-
{id: 'card', name: 'Card', src: 'card'},
21-
{id: 'list', name: 'List', src: 'list'},
22-
{id: 'grid-list', name: 'Grid list', src: 'grid-list'},
23-
{id: 'sidenav', name: 'Sidenav', src: 'sidenav'},
24-
{id: 'toolbar', name: 'Toolbar', src: 'toolbar'},
25-
26-
{id: 'menu', name: 'Menu', src: 'menu'},
27-
{id: 'dialog', name: 'Dialog', src: 'dialog'},
28-
{id: 'snackbar', name: 'Snackbar', src: 'snackbar'},
29-
{id: 'tooltip', name: 'Tooltip', src: 'tooltip'},
30-
31-
{id: 'progress-spinner', name: 'Progress spinner', src: 'progress-spinner'},
32-
{id: 'progress-bar', name: 'Progress bar', src: 'progress-bar'},
33-
34-
{id: 'icon', name: 'Icon', src: 'icon'},
35-
];
10+
constructor(public docItems: DocumentationItems) { }
3611
}

0 commit comments

Comments
 (0)