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 397
/
Copy pathcomponent-viewer.ts
90 lines (79 loc) · 3 KB
/
component-viewer.ts
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {CommonModule} from '@angular/common';
import {Component, ElementRef, NgModule, ViewChild, ViewEncapsulation} from '@angular/core';
import {MatTabsModule} from '@angular/material';
import {ActivatedRoute, Params, Router, RouterModule} from '@angular/router';
import 'rxjs/add/operator/map';
import {Observable} from 'rxjs/Observable';
import {DocViewerModule} from '../../shared/doc-viewer/doc-viewer-module';
import {DocItem, DocumentationItems} from '../../shared/documentation-items/documentation-items';
import {TableOfContentsModule} from '../../shared/table-of-contents/table-of-contents.module';
import {ComponentPageTitle} from '../page-title/page-title';
@Component({
selector: 'app-component-viewer',
templateUrl: './component-viewer.html',
styleUrls: ['./component-viewer.scss'],
encapsulation: ViewEncapsulation.None,
})
export class ComponentViewer {
componentDocItem: DocItem;
sections: Set<string> = new Set(['overview', 'api']);
constructor(private _route: ActivatedRoute,
private router: Router,
public _componentPageTitle: ComponentPageTitle,
public docItems: DocumentationItems) {
// Listen to changes on the current route for the doc id (e.g. button/checkbox) and the
// parent route for the section (material/cdk).
Observable.combineLatest(_route.params, _route.parent.params)
.map((p: [Params, Params]) => ({id: p[0]['id'], section: p[1]['section']}))
.map(p => docItems.getItemById(p.id, p.section))
.subscribe(d => {
this.componentDocItem = d;
if (this.componentDocItem) {
this._componentPageTitle.title = `${this.componentDocItem.name}`;
this.componentDocItem.examples.length ?
this.sections.add('examples') :
this.sections.delete('examples');
} else {
this.router.navigate(['/components']);
}
});
}
}
@Component({
selector: 'component-overview',
templateUrl: './component-overview.html',
encapsulation: ViewEncapsulation.None,
})
export class ComponentOverview {
@ViewChild('intialFocusTarget') focusTarget: ElementRef;
constructor(public componentViewer: ComponentViewer) {}
focusInitialTarget() {
this.focusTarget.nativeElement.focus();
}
}
@Component({
selector: 'component-api',
templateUrl: './component-api.html',
styleUrls: ['./component-api.scss'],
encapsulation: ViewEncapsulation.None,
})
export class ComponentApi extends ComponentOverview {}
@Component({
selector: 'component-examples',
templateUrl: './component-examples.html',
encapsulation: ViewEncapsulation.None,
})
export class ComponentExamples extends ComponentOverview {}
@NgModule({
imports: [
MatTabsModule,
RouterModule,
DocViewerModule,
CommonModule,
TableOfContentsModule,
],
exports: [ComponentViewer],
declarations: [ComponentViewer, ComponentOverview, ComponentApi, ComponentExamples],
providers: [DocumentationItems, ComponentPageTitle],
})
export class ComponentViewerModule {}