Skip to content

Commit 1ee9c5f

Browse files
authored
chore(demo): add examples to demo app (#11018)
* chore(demo): add examples to demo app * fix aot
1 parent b24308c commit 1ee9c5f

17 files changed

+182
-7
lines changed

.github/CODEOWNERS

+2
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.json

+2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
"@angular/common": "6.0.0-rc.6",
3131
"@angular/compiler": "6.0.0-rc.6",
3232
"@angular/core": "6.0.0-rc.6",
33+
"@angular/elements": "6.0.0-rc.6",
3334
"@angular/forms": "6.0.0-rc.6",
3435
"@angular/platform-browser": "6.0.0-rc.6",
36+
"@webcomponents/custom-elements": "^1.1.0",
3537
"core-js": "^2.4.1",
3638
"rxjs": "6.0.0",
3739
"systemjs": "0.19.43",

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

+1
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

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
import {LayoutModule} from '@angular/cdk/layout';
1010
import {FullscreenOverlayContainer, OverlayContainer} from '@angular/cdk/overlay';
1111
import {CommonModule} from '@angular/common';
12-
import {NgModule} from '@angular/core';
12+
import {Injector, NgModule} from '@angular/core';
1313
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
1414
import {RouterModule} from '@angular/router';
15+
import {createCustomElement} from '@angular/elements';
16+
import {EXAMPLE_COMPONENTS, ExampleModule} from '@angular/material-examples';
17+
1518
import {AutocompleteDemo} from '../autocomplete/autocomplete-demo';
1619
import {BadgeDemo} from '../badge/badge-demo';
1720
import {BaselineDemo} from '../baseline/baseline-demo';
@@ -65,9 +68,13 @@ import {TypographyDemo} from '../typography/typography-demo';
6568
import {DemoApp, Home} from './demo-app';
6669
import {DEMO_APP_ROUTES} from './routes';
6770
import {PaginatorDemo} from '../paginator/paginator-demo';
71+
import {ExamplesPage} from '../examples-page/examples-page';
72+
import {MaterialExampleModule} from '../example/example-module';
6873

6974
@NgModule({
7075
imports: [
76+
MaterialExampleModule,
77+
ExampleModule,
7178
CommonModule,
7279
FormsModule,
7380
ReactiveFormsModule,
@@ -78,6 +85,7 @@ import {PaginatorDemo} from '../paginator/paginator-demo';
7885
TreeDemoModule,
7986
],
8087
declarations: [
88+
ExamplesPage,
8189
AutocompleteDemo,
8290
BadgeDemo,
8391
BaselineDemo,
@@ -155,4 +163,12 @@ import {PaginatorDemo} from '../paginator/paginator-demo';
155163
SpaghettiPanel,
156164
],
157165
})
158-
export class DemoModule {}
166+
export class DemoModule {
167+
constructor(injector: Injector) {
168+
// Register examples as custom elements so that they can be inserted into the DOM dynamically
169+
Object.keys(EXAMPLE_COMPONENTS).forEach(key => {
170+
const element = createCustomElement(EXAMPLE_COMPONENTS[key].component, {injector});
171+
customElements.define(key, element);
172+
});
173+
}
174+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {BadgeDemo} from '../badge/badge-demo';
5656
import {ConnectedOverlayDemo} from '../connected-overlay/connected-overlay-demo';
5757
import {PaginatorDemo} from '../paginator/paginator-demo';
5858

59+
import {ExamplesPage} from '../examples-page/examples-page';
5960

6061
export const DEMO_APP_ROUTES: Routes = [
6162
{path: '', component: DemoApp, children: [
@@ -105,6 +106,7 @@ export const DEMO_APP_ROUTES: Routes = [
105106
{path: 'stepper', component: StepperDemo},
106107
{path: 'screen-type', component: ScreenTypeDemo},
107108
{path: 'connected-overlay', component: ConnectedOverlayDemo},
109+
{path: 'examples', component: ExamplesPage}
108110
]}
109111
];
110112

src/demo-app/example/example-list.ts

+42
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+
}
+21
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

+25
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+
}
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+
}

src/demo-app/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
<link href="theme.css" rel="stylesheet">
1212
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
1313

14+
<script>
15+
if (customElements) {
16+
customElements.forcePolyfill = true;
17+
}
18+
</script>
19+
<script src="node_modules/@webcomponents/custom-elements/custom-elements.min.js"></script>
20+
1421
<!-- FontAwesome for mat-icon demo. -->
1522
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
1623
</head>

src/demo-app/system-config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ System.config({
2727
'@angular/compiler': 'node:@angular/compiler/bundles/compiler.umd.js',
2828
'@angular/forms': 'node:@angular/forms/bundles/forms.umd.js',
2929
'@angular/animations': 'node:@angular/animations/bundles/animations.umd.js',
30+
'@angular/elements': 'node:@angular/elements/bundles/elements.umd.js',
3031
'@angular/router': 'node:@angular/router/bundles/router.umd.js',
3132
'@angular/animations/browser': 'node:@angular/animations/bundles/animations-browser.umd.js',
3233
'@angular/platform-browser/animations':
@@ -39,6 +40,7 @@ System.config({
3940
// TODO(devversion): replace once the index.ts file for the Material package has been added.
4041
'@angular/material': 'dist/packages/material/public-api.js',
4142
'@angular/material-experimental': 'dist/packages/material-experimental/index.js',
43+
'@angular/material-examples': 'dist/packages/material-examples/index.js',
4244
'@angular/material-moment-adapter': 'dist/packages/material-moment-adapter/index.js',
4345
'@angular/cdk': 'dist/packages/cdk/index.js',
4446
'@angular/cdk-experimental': 'dist/packages/cdk-experimental/index.js',

src/demo-app/tsconfig-aot.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"@angular/material-experimental": ["../../dist/releases/material-experimental"],
2323
"@angular/cdk-experimental/*": ["../../dist/releases/cdk-experimental/*"],
2424
"@angular/cdk-experimental": ["../../dist/releases/cdk-experimental"],
25-
"@angular/material-moment-adapter": ["../../dist/releases/material-moment-adapter"]
25+
"@angular/material-moment-adapter": ["../../dist/releases/material-moment-adapter"],
26+
"@angular/material-examples": ["../../dist/packages/material-examples"]
2627
}
2728
},
2829
"files": [

src/demo-app/tsconfig-build.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"@angular/material-experimental": ["../../dist/packages/material-experimental"],
3333
"@angular/cdk-experimental/*": ["../../dist/packages/cdk-experimental/*"],
3434
"@angular/cdk-experimental": ["../../dist/packages/cdk-experimental"],
35-
"@angular/material-moment-adapter": ["../../dist/packages/material-moment-adapter"]
35+
"@angular/material-moment-adapter": ["../../dist/packages/material-moment-adapter"],
36+
"@angular/material-examples": ["../../dist/packages/material-examples"]
3637
}
3738
},
3839
"files": [

src/demo-app/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"@angular/material-experimental": ["../material-experimental"],
1515
"@angular/cdk-experimental/*": ["../cdk-experimental/*"],
1616
"@angular/cdk-experimental": ["../cdk-experimental"],
17-
"@angular/material-moment-adapter": ["../material-moment-adapter/public-api.ts"]
17+
"@angular/material-moment-adapter": ["../material-moment-adapter/public-api.ts"],
18+
"@angular/material-examples": ["../../dist/packages/material-examples"]
1819
}
1920
},
2021
"include": ["./**/*.ts"]
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// TypeScript config file that extends the default build tsconfig file. This config is used to
2+
// also compile the unit-test files. Since the code will run inside of the browser, the target is
3+
// set to ES5. Also the format needs to be CommonJS for Karma.
4+
{
5+
"extends": "./tsconfig-build",
6+
"compilerOptions": {
7+
"importHelpers": false,
8+
"module": "commonjs",
9+
"target": "es5",
10+
"types": ["jasmine"]
11+
},
12+
"angularCompilerOptions": {
13+
"strictMetadataEmit": false, // Workaround for Angular #22210
14+
"skipTemplateCodegen": true,
15+
"emitDecoratorMetadata": true,
16+
"fullTemplateTypeCheck": true
17+
},
18+
"include": [
19+
"**/*.spec.ts",
20+
"index.ts"
21+
]
22+
}

tools/gulp/tasks/aot.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ task('aot:deps', sequenceTask(
1818
'material:build-release',
1919
'cdk-experimental:build-release',
2020
'material-experimental:build-release',
21-
'material-moment-adapter:build-release'
21+
'material-moment-adapter:build-release',
22+
// The examples module needs to be built before building examples package
23+
'build-examples-module',
24+
'material-examples:build-release',
2225
],
2326
// Build the assets after the releases have been built, because the demo-app assets import
2427
// SCSS files from the release packages.

tools/gulp/tasks/development.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
materialExperimentalPackage,
1010
cdkExperimentalPackage,
1111
materialPackage,
12-
momentAdapterPackage
12+
momentAdapterPackage,
13+
examplesPackage,
1314
} from '../packages';
1415

1516
// These imports don't have any typings provided.
@@ -34,6 +35,7 @@ const appVendors = [
3435
'web-animations-js',
3536
'moment',
3637
'tslib',
38+
'@webcomponents',
3739
];
3840

3941
/** Glob that matches all required vendors for the demo-app. */
@@ -58,6 +60,7 @@ task(':watch:devapp', () => {
5860
['material-experimental:build-no-bundles']);
5961
watchFiles(join(cdkExperimentalPackage.sourceDir, '**/*'),
6062
['cdk-experimental:build-no-bundles']);
63+
watchFiles(join(examplesPackage.sourceDir, '**/*'), ['material-examples:build-no-bundles']);
6164
});
6265

6366
/** Path to the demo-app tsconfig file. */
@@ -81,6 +84,8 @@ task('build:devapp', sequenceTask(
8184
'cdk-experimental:build-no-bundles',
8285
'material-experimental:build-no-bundles',
8386
'material-moment-adapter:build-no-bundles',
87+
'build-examples-module', // The examples module needs to be built before building examples package
88+
'material-examples:build-no-bundles',
8489
[':build:devapp:assets', ':build:devapp:scss', ':build:devapp:ts']
8590
));
8691

@@ -98,6 +103,10 @@ task('stage-deploy:devapp', ['build:devapp'], () => {
98103
join(outDir, 'dist/packages/cdk-experimental'));
99104
copyFiles(materialPackage.outputDir, '**/prebuilt/*.+(css|map)',
100105
join(outDir, 'dist/packages/material'));
106+
copyFiles(examplesPackage.outputDir, '**/*.+(js|map)',
107+
join(outDir, 'dist/packages/material-examples'));
108+
copyFiles(momentAdapterPackage.outputDir, '**/*.+(js|map)',
109+
join(outDir, 'dist/packages/material-moment-adapter'));
101110
});
102111

103112
/**

0 commit comments

Comments
 (0)