-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
tab.ts
82 lines (68 loc) · 2.48 KB
/
tab.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
/**
* @license
* Copyright Google Inc. 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 {TemplatePortal} from '../core/portal/portal';
import {
ViewContainerRef, Input, TemplateRef, ViewChild, OnInit, ContentChild,
Component, ChangeDetectionStrategy, OnDestroy, OnChanges, SimpleChanges,
} from '@angular/core';
import {CanDisable, mixinDisabled} from '../core/common-behaviors/disabled';
import {MdTabLabel} from './tab-label';
import {Subject} from 'rxjs/Subject';
// Boilerplate for applying mixins to MdTab.
/** @docs-private */
export class MdTabBase {}
export const _MdTabMixinBase = mixinDisabled(MdTabBase);
@Component({
moduleId: module.id,
selector: 'md-tab, mat-tab',
templateUrl: 'tab.html',
inputs: ['disabled'],
changeDetection: ChangeDetectionStrategy.OnPush,
exportAs: 'mdTab',
})
export class MdTab extends _MdTabMixinBase implements OnInit, CanDisable, OnChanges, OnDestroy {
/** Content for the tab label given by <ng-template md-tab-label>. */
@ContentChild(MdTabLabel) templateLabel: MdTabLabel;
/** Template inside the MdTab view that contains an <ng-content>. */
@ViewChild(TemplateRef) _content: TemplateRef<any>;
/** The plain text label for the tab, used when there is no template label. */
@Input('label') textLabel: string = '';
/** The portal that will be the hosted content of the tab */
private _contentPortal: TemplatePortal | null = null;
get content(): TemplatePortal | null { return this._contentPortal; }
/** Emits whenever the label changes. */
_labelChange = new Subject<void>();
/**
* The relatively indexed position where 0 represents the center, negative is left, and positive
* represents the right.
*/
position: number | null = null;
/**
* The initial relatively index origin of the tab if it was created and selected after there
* was already a selected tab. Provides context of what position the tab should originate from.
*/
origin: number | null = null;
/**
* Whether the tab is currently active.
*/
isActive = false;
constructor(private _viewContainerRef: ViewContainerRef) {
super();
}
ngOnChanges(changes: SimpleChanges) {
if (changes.hasOwnProperty('textLabel')) {
this._labelChange.next();
}
}
ngOnDestroy() {
this._labelChange.complete();
}
ngOnInit() {
this._contentPortal = new TemplatePortal(this._content, this._viewContainerRef);
}
}