forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
74 lines (62 loc) · 1.89 KB
/
Copy pathexample.ts
File metadata and controls
74 lines (62 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {Component, ElementRef, Injector, Input, OnInit} from '@angular/core';
import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
import {createCustomElement} from '@angular/elements';
@Component({
selector: 'material-example',
template: `
<div class="label" *ngIf="showLabel">
<span class="title"> {{title}} </span>
<span class="id"> <{{id}}> </span>
</div>
<div *ngIf="!id">
Could not find example {{id}}
</div>
`,
styles: [`
.label {
display: flex;
justify-content: space-between;
align-items: flex-end;
margin: 16px 0;
}
.title {
font-size: 20px;
font-weight: 500;
}
.id {
font-size: 13px;
font-family: monospace;
color: #666;
white-space: pre;
}
`]
})
export class Example implements OnInit {
/** ID of the material example to display. */
@Input() id: string;
@Input()
get showLabel(): boolean { return this._showLabel; }
set showLabel(v: boolean) { this._showLabel = coerceBooleanProperty(v); }
_showLabel: boolean;
title: string;
constructor(private _elementRef: ElementRef<HTMLElement>, private _injector: Injector) { }
ngOnInit() {
let exampleElementCtor = customElements.get(this.id);
if (!exampleElementCtor) {
exampleElementCtor = createCustomElement(EXAMPLE_COMPONENTS[this.id].component, {
injector: this._injector
});
customElements.define(this.id, exampleElementCtor);
}
this._elementRef.nativeElement.appendChild(new exampleElementCtor(this._injector));
this.title = EXAMPLE_COMPONENTS[this.id] ? EXAMPLE_COMPONENTS[this.id].title : '';
}
}