This repository was archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 395
Expand component view with example viewer #33
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a11beef
Add DocumentationItems service and use throughout app
jelbourn 75e6d80
Add content to component-view sidenav
jelbourn 3ecf83f
Rename top nav link to "Docs"
jelbourn f921163
Make example viewer work with a set of examples
tinayuangao 70abd09
Add example components for testing
jelbourn c320457
Render raw examples in the Examples tab
jelbourn 8a2f1d9
Add rough example-viewer structure and styles
jelbourn 677c60e
Load example sources into example viewer
jelbourn 2e79a6a
Remove testing examples except for button
jelbourn 60f2039
Add script to syntax highlight an example and hljs style
jelbourn bb03fe5
Example assets loaded via document-viewer
jelbourn 0dfb89c
Introduce shared-module for shared/ directory
jelbourn 505d208
Add missing RouterModule to SharedModule
jelbourn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<button md-button>Click me!</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
|
||
@Component({ | ||
selector: 'button-overview-example', | ||
templateUrl: './button-overview-example.html', | ||
}) | ||
export class ButtonOverviewExample {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="example"> | ||
<h3>Normal Buttons</h3> | ||
<div class="button-row"> | ||
<button md-button>Flat button</button> | ||
<button md-raised-button>Raised button</button> | ||
<button md-fab><md-icon>check</md-icon></button> | ||
<button md-mini-fab><md-icon>check</md-icon></button> | ||
</div> | ||
|
||
<h3>Link Buttons</h3> | ||
<div class="button-row"> | ||
<a md-button routerLink=".">Flat button</a> | ||
<a md-raised-button routerLink=".">Raised button</a> | ||
<a md-fab routerLink="."><md-icon>check</md-icon></a> | ||
<a md-mini-fab routerLink="."><md-icon>check</md-icon></a> | ||
</div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.example { | ||
width: 500px; | ||
} | ||
|
||
.button-row { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-around; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
|
||
@Component({ | ||
selector: 'button-types-example', | ||
templateUrl: './button-types-example.html', | ||
styleUrls: ['./button-types-example.scss'], | ||
}) | ||
export class ButtonTypesExample {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {MaterialModule} from '@angular/material'; | ||
import {ButtonOverviewExample} from './button-overview/button-overview-example'; | ||
import {ButtonTypesExample} from './button-types/button-types-example'; | ||
|
||
|
||
/** | ||
* The list of example components. | ||
* Key is the example name which will be used in `material-docs-example="key"`. | ||
* Value is the component. | ||
*/ | ||
|
||
export const EXAMPLE_COMPONENTS = { | ||
'button-overview': ButtonOverviewExample, | ||
'button-types': ButtonTypesExample | ||
}; | ||
|
||
/** | ||
* The list of all example components. | ||
* We need to put them in both `declarations` and `entryComponents` to make them work. | ||
*/ | ||
export const EXAMPLE_LIST = [ | ||
ButtonOverviewExample, | ||
ButtonTypesExample, | ||
]; | ||
|
||
@NgModule({ | ||
declarations: EXAMPLE_LIST, | ||
entryComponents: EXAMPLE_LIST, | ||
imports: [ | ||
MaterialModule.forRoot(), | ||
] | ||
}) | ||
export class ExampleModule { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
<a *ngFor="let component of componentItems" | ||
class="docs-component-list-item" | ||
[routerLink]="['/component/', component.id]"> | ||
<img src="../../../assets/img/components/{{component.src}}.svg" | ||
class="docs-component-list-item-icon" | ||
[alt]="component.name"> | ||
{{component.name}} | ||
</a> | ||
<div *ngFor="let category of docItems.getItemsInCategories()" class="docs-component-list-category"> | ||
<h2>{{category.name}}</h2> | ||
<a *ngFor="let component of category.items" | ||
class="docs-component-list-item" | ||
[routerLink]="['/component/', component.id]"> | ||
<img src="../../../assets/img/components/{{component.id}}.svg" | ||
class="docs-component-list-item-icon" | ||
[alt]="component.name"> | ||
{{component.name}} | ||
</a> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,11 @@ | ||
import {Component} from '@angular/core'; | ||
import {DocumentationItems} from '../../shared/documentation-items/documentation-items'; | ||
|
||
@Component({ | ||
selector: 'app-components', | ||
templateUrl: './component-list.html', | ||
styleUrls: ['./component-list.scss'] | ||
}) | ||
export class ComponentList { | ||
componentItems = [ | ||
{id: 'button', name: 'Button', src: 'button'}, | ||
{id: 'checkbox', name: 'Checkbox', src: 'checkbox'}, | ||
{id: 'radio-button', name: 'Radio button', src: 'radio'}, | ||
{id: 'button-toggle', name: 'Button toggle', src: 'button-toggle'}, | ||
{id: 'input', name: 'Input', src: 'input'}, | ||
{id: 'textarea', name: 'Textarea', src: 'textarea'}, | ||
{id: 'select', name: 'Select', src: 'select'}, | ||
{id: 'slide-toggle', name: 'Slide toggle', src: 'slide-toggle'}, | ||
{id: 'slider', name: 'Slider', src: 'slider'}, | ||
|
||
{id: 'card', name: 'Card', src: 'card'}, | ||
{id: 'list', name: 'List', src: 'list'}, | ||
{id: 'grid-list', name: 'Grid list', src: 'grid-list'}, | ||
{id: 'sidenav', name: 'Sidenav', src: 'sidenav'}, | ||
{id: 'toolbar', name: 'Toolbar', src: 'toolbar'}, | ||
|
||
{id: 'menu', name: 'Menu', src: 'menu'}, | ||
{id: 'dialog', name: 'Dialog', src: 'dialog'}, | ||
{id: 'snackbar', name: 'Snackbar', src: 'snackbar'}, | ||
{id: 'tooltip', name: 'Tooltip', src: 'tooltip'}, | ||
|
||
{id: 'progress-spinner', name: 'Progress spinner', src: 'progress-spinner'}, | ||
{id: 'progress-bar', name: 'Progress bar', src: 'progress-bar'}, | ||
|
||
{id: 'icon', name: 'Icon', src: 'icon'}, | ||
]; | ||
constructor(public docItems: DocumentationItems) { } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
<md-sidenav-layout> | ||
<md-sidenav opened mode="side" class="docs-component-viewer-sidenav"> | ||
component list | ||
<div *ngFor="let category of docItems.getItemsInCategories()"> | ||
<div>{{category.name}}</div> | ||
<ul> | ||
<li *ngFor="let component of category.items"> | ||
<a [routerLink]="['/component/', component.id]"> | ||
{{component.name}} | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</md-sidenav> | ||
|
||
<h1 class="docs-component-viewer-header"> | ||
{{componentId.toUpperCase()}} | ||
</h1> | ||
<h1 class="docs-component-viewer-header"> {{componentDocItem.name}} </h1> | ||
|
||
<!-- TODO(jelbourn): turn this into nav tabs --> | ||
<md-tab-group class="docs-component-viewer-tabbed-content"> | ||
<md-tab label="OVERVIEW"> | ||
<doc-viewer documentUrl="/assets/documents/overview/{{componentId}}.html"></doc-viewer> | ||
<doc-viewer documentUrl="/assets/documents/overview/{{componentDocItem.id}}.html"> | ||
</doc-viewer> | ||
</md-tab> | ||
|
||
<md-tab label="API"> | ||
<doc-viewer documentUrl="/assets/documents/api/{{componentId}}.html"></doc-viewer> | ||
<doc-viewer documentUrl="/assets/documents/api/{{componentDocItem.id}}.html"></doc-viewer> | ||
</md-tab> | ||
|
||
<md-tab label="EXAMPLES"> | ||
examples | ||
|
||
<example-viewer *ngFor="let example of componentDocItem.examples" [example]="example"> | ||
</example-viewer> | ||
|
||
</md-tab> | ||
</md-tab-group> | ||
</md-sidenav-layout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
border-right: 1px solid black; | ||
width: 300px; | ||
margin: 20px; | ||
} | ||
|
||
.docs-component-viewer-header { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {HttpModule} from '@angular/http'; | ||
import {DocViewer} from './doc-viewer'; | ||
import {ExampleViewer} from '../example-viewer/example-viewer'; | ||
import {ExampleViewerModule} from '../example-viewer/index'; | ||
|
||
export * from './doc-viewer'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
ExampleViewerModule, | ||
HttpModule, | ||
], | ||
declarations: [DocViewer], | ||
exports: [DocViewer], | ||
entryComponents: [ | ||
ExampleViewer, | ||
], | ||
}) | ||
export class DocViewerModule {} |
45 changes: 45 additions & 0 deletions
45
src/app/shared/documentation-items/documentation-items.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {TestBed, inject, async} from '@angular/core/testing'; | ||
import {DocumentationItems} from './documentation-items'; | ||
|
||
|
||
describe('DocViewer', () => { | ||
let docsItems: DocumentationItems; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [], | ||
declarations: [], | ||
providers: [DocumentationItems] | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
beforeEach(inject([DocumentationItems], (di: DocumentationItems) => { | ||
docsItems = di; | ||
})); | ||
|
||
it('get a list of categories', () => { | ||
expect(docsItems.getItemsInCategories()).toBeDefined(); | ||
expect(docsItems.getItemsInCategories().length).toBeGreaterThan(0); | ||
for (const category of docsItems.getItemsInCategories()) { | ||
expect(category.id).toBeDefined(); | ||
expect(category.name).toBeDefined(); | ||
expect(category.items).toBeDefined(); | ||
expect(category.items.length).toBeGreaterThan(0); | ||
} | ||
}); | ||
|
||
it('should get a list of all doc items', () => { | ||
expect(docsItems.getAllItems()).toBeDefined(); | ||
expect(docsItems.getAllItems().length).toBeGreaterThan(0); | ||
for (const item of docsItems.getAllItems()) { | ||
expect(item.id).toBeDefined(); | ||
expect(item.name).toBeDefined(); | ||
} | ||
}); | ||
|
||
it('should get a doc item by id', () => { | ||
expect(docsItems.getItemById('button')).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get the list from EXAMPLE_COMPONENT so we don't have to write them twice?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't- doing that would be incompatible with AoT because the values have to be static constants.