-
Notifications
You must be signed in to change notification settings - Fork 40
/
tab-nav-bar.ts
105 lines (96 loc) · 2.71 KB
/
tab-nav-bar.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import {
Attribute,
ChangeDetectionStrategy,
Component,
Directive,
ElementRef,
Input,
OnDestroy,
ViewEncapsulation
} from '@angular/core';
import { FocusMonitor } from '@ptsecurity/cdk/a11y';
import {
CanColor,
CanColorCtor,
CanDisable,
CanDisableCtor,
HasTabIndex,
HasTabIndexCtor,
mixinColor,
mixinDisabled,
mixinTabIndex
} from '@ptsecurity/mosaic/core';
// Boilerplate for applying mixins to McTabNav.
/** @docs-private */
export class McTabNavBase {
// tslint:disable-next-line:naming-convention
constructor(public _elementRef: ElementRef) {}
}
export const mcTabNavMixinBase: CanColorCtor &
typeof McTabNavBase = mixinColor(McTabNavBase);
/**
* Navigation component matching the styles of the tab group header.
*/
@Component({
selector: '[mc-tab-nav-bar]',
exportAs: 'mcTabNavBar, mcTabNav',
inputs: ['color'],
templateUrl: 'tab-nav-bar.html',
styleUrls: ['tab-nav-bar.css'],
host: { class: 'mc-tab-nav-bar' },
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class McTabNav extends mcTabNavMixinBase
implements CanColor {
constructor(elementRef: ElementRef) {
super(elementRef);
}
}
// Boilerplate for applying mixins to McTabLink.
export class McTabLinkBase {}
export const mcTabLinkMixinBase: HasTabIndexCtor & CanDisableCtor &
typeof McTabLinkBase = mixinTabIndex(mixinDisabled(McTabLinkBase));
/**
* Link inside of a `mc-tab-nav-bar`.
*/
@Directive({
selector: '[mc-tab-link], [mcTabLink]',
exportAs: 'mcTabLink',
inputs: ['disabled', 'tabIndex'],
host: {
class: 'mc-tab-link',
'[attr.aria-current]': 'active',
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.tabIndex]': 'tabIndex',
'[class.mc-disabled]': 'disabled',
'[class.mc-active]': 'active'
}
})
export class McTabLink extends mcTabLinkMixinBase
implements OnDestroy, CanDisable, HasTabIndex {
/** Whether the link is active. */
@Input()
get active(): boolean {
return this.isActive;
}
set active(value: boolean) {
if (value !== this.isActive) {
this.isActive = value;
}
}
/** Whether the tab link is active or not. */
protected isActive: boolean = false;
constructor(
public elementRef: ElementRef,
@Attribute('tabindex') tabIndex: string,
private focusMonitor: FocusMonitor
) {
super();
this.tabIndex = parseInt(tabIndex) || 0;
this.focusMonitor.monitor(this.elementRef.nativeElement);
}
ngOnDestroy() {
this.focusMonitor.stopMonitoring(this.elementRef.nativeElement);
}
}