Skip to content

Commit 8df1d77

Browse files
committed
chore(demo): add examples to demo app
1 parent 27b6eca commit 8df1d77

File tree

16 files changed

+199
-10
lines changed

16 files changed

+199
-10
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
/src/demo-app/demo-app/** @jelbourn
110110
/src/demo-app/dialog/** @jelbourn @crisbeto
111111
/src/demo-app/drawer/** @mmalerba
112+
/src/demo-app/example/** @andrewseguin
113+
/src/demo-app/examples-page/** @andrewseguin
112114
/src/demo-app/expansion/** @josephperrott
113115
/src/demo-app/focus-origin/** @mmalerba
114116
/src/demo-app/gestures/** @jelbourn

package-lock.json

Lines changed: 28 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@angular/compiler": "6.0.0-rc.1",
3232
"@angular/core": "6.0.0-rc.1",
3333
"@angular/forms": "6.0.0-rc.1",
34+
"@angular/elements": "6.0.0-rc.1",
3435
"@angular/platform-browser": "6.0.0-rc.1",
3536
"core-js": "^2.4.1",
3637
"rxjs": "6.0.0-rc.0",
@@ -68,6 +69,7 @@
6869
"chalk": "^1.1.3",
6970
"dgeni": "^0.4.9",
7071
"dgeni-packages": "^0.24.3",
72+
"document-register-element": "^1.8.1",
7173
"firebase": "^4.0.0",
7274
"firebase-admin": "^5.0.0",
7375
"firebase-tools": "^3.11.0",

src/demo-app/demo-app/demo-app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class Home {}
4848
export class DemoApp {
4949
dark = false;
5050
navItems = [
51+
{name: 'Examples', route: '/examples'},
5152
{name: 'Autocomplete', route: '/autocomplete'},
5253
{name: 'Badge', route: '/badge'},
5354
{name: 'Bottom sheet', route: '/bottom-sheet'},

src/demo-app/demo-app/demo-module.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88

99
import {FullscreenOverlayContainer, OverlayContainer} from '@angular/cdk/overlay';
1010
import {CommonModule} from '@angular/common';
11-
import {NgModule} from '@angular/core';
11+
import {Injector, NgModule} from '@angular/core';
1212
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
1313
import {RouterModule} from '@angular/router';
14+
import {createCustomElement} from '@angular/elements';
15+
import {EXAMPLE_COMPONENTS, ExampleModule} from '@angular/material-examples';
16+
1417
import {AutocompleteDemo} from '../autocomplete/autocomplete-demo';
1518
import {BottomSheetDemo, ExampleBottomSheet} from '../bottom-sheet/bottom-sheet-demo';
1619
import {BaselineDemo} from '../baseline/baseline-demo';
@@ -53,7 +56,11 @@ import {StepperDemo} from '../stepper/stepper-demo';
5356
import {ScreenTypeDemo} from '../screen-type/screen-type-demo';
5457
import {LayoutModule} from '@angular/cdk/layout';
5558
import {
56-
FoggyTabContent, RainyTabContent, SunnyTabContent, TabsDemo, Counter
59+
Counter,
60+
FoggyTabContent,
61+
RainyTabContent,
62+
SunnyTabContent,
63+
TabsDemo
5764
} from '../tabs/tabs-demo';
5865
import {ToolbarDemo} from '../toolbar/toolbar-demo';
5966
import {TooltipDemo} from '../tooltip/tooltip-demo';
@@ -64,9 +71,13 @@ import {TableDemoModule} from '../table/table-demo-module';
6471
import {BadgeDemo} from '../badge/badge-demo';
6572
import {TreeDemoModule} from '../tree/tree-demo-module';
6673
import {ConnectedOverlayDemo, DemoOverlay} from '../connected-overlay/connected-overlay-demo';
74+
import {ExamplesPage} from '../examples-page/examples-page';
75+
import {MaterialExampleModule} from '../example/example-module';
6776

6877
@NgModule({
6978
imports: [
79+
MaterialExampleModule,
80+
ExampleModule,
7081
CommonModule,
7182
FormsModule,
7283
ReactiveFormsModule,
@@ -77,6 +88,7 @@ import {ConnectedOverlayDemo, DemoOverlay} from '../connected-overlay/connected-
7788
TreeDemoModule,
7889
],
7990
declarations: [
91+
ExamplesPage,
8092
AutocompleteDemo,
8193
BottomSheetDemo,
8294
BaselineDemo,
@@ -153,4 +165,12 @@ import {ConnectedOverlayDemo, DemoOverlay} from '../connected-overlay/connected-
153165
DemoOverlay,
154166
],
155167
})
156-
export class DemoModule {}
168+
export class DemoModule {
169+
constructor(injector: Injector) {
170+
// Register examples as custom elements so that they can be inserted into the DOM dynamically
171+
Object.keys(EXAMPLE_COMPONENTS).forEach(key => {
172+
const element = createCustomElement(EXAMPLE_COMPONENTS[key].component, {injector});
173+
customElements.define(key, element);
174+
});
175+
}
176+
}

src/demo-app/demo-app/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {TableDemoPage} from '../table/table-demo-page';
5454
import {TABLE_DEMO_ROUTES} from '../table/routes';
5555
import {BadgeDemo} from '../badge/badge-demo';
5656
import {ConnectedOverlayDemo} from '../connected-overlay/connected-overlay-demo';
57+
import {ExamplesPage} from '../examples-page/examples-page';
5758

5859
export const DEMO_APP_ROUTES: Routes = [
5960
{path: '', component: DemoApp, children: [
@@ -102,6 +103,7 @@ export const DEMO_APP_ROUTES: Routes = [
102103
{path: 'stepper', component: StepperDemo},
103104
{path: 'screen-type', component: ScreenTypeDemo},
104105
{path: 'connected-overlay', component: ConnectedOverlayDemo},
106+
{path: 'examples', component: ExamplesPage}
105107
]}
106108
];
107109

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component, Input} from '@angular/core';
10+
import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
11+
12+
/** Displays a set of material examples in a mat-accordion. */
13+
@Component({
14+
selector: 'material-example-list',
15+
template: `
16+
<h2> {{type}} Examples </h2>
17+
<mat-accordion>
18+
<mat-expansion-panel *ngFor="let id of ids">
19+
<mat-expansion-panel-header>
20+
{{id}}: {{exampleComponents[id].title}}
21+
</mat-expansion-panel-header>
22+
<ng-template matExpansionPanelContent>
23+
<material-example [id]="id"></material-example>
24+
</ng-template>
25+
</mat-expansion-panel>
26+
</mat-accordion>
27+
`,
28+
styles: [`
29+
h2 {
30+
text-transform: capitalize;
31+
}
32+
`]
33+
})
34+
export class ExampleList {
35+
/** Type of examples being displayed. */
36+
@Input() type: string;
37+
38+
/** IDs of the examples to display. */
39+
@Input() ids: string[];
40+
41+
exampleComponents = EXAMPLE_COMPONENTS;
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {CommonModule} from '@angular/common';
10+
import {MatExpansionModule} from '@angular/material';
11+
import {NgModule} from '@angular/core';
12+
13+
import {ExampleList} from './example-list';
14+
import {Example} from './example';
15+
16+
@NgModule({
17+
imports: [MatExpansionModule, CommonModule],
18+
declarations: [Example, ExampleList],
19+
exports: [Example, ExampleList]
20+
})
21+
export class MaterialExampleModule {}

src/demo-app/example/example.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component, ElementRef, Input} from '@angular/core';
10+
11+
@Component({
12+
selector: 'material-example',
13+
template: '',
14+
})
15+
export class Example {
16+
/** ID of the material example to display. */
17+
@Input() id: string;
18+
19+
constructor(private elementRef: ElementRef) { }
20+
21+
ngOnInit() {
22+
const element = document.createElement(this.id);
23+
this.elementRef.nativeElement.appendChild(element);
24+
}
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component} from '@angular/core';
10+
import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
11+
12+
/** Renders all material examples listed in the generated EXAMPLE_COMPONENTS. */
13+
@Component({
14+
template: `<material-example-list [ids]="examples"></material-example-list>`
15+
})
16+
export class ExamplesPage {
17+
examples = Object.keys(EXAMPLE_COMPONENTS);
18+
}

0 commit comments

Comments
 (0)