/
route-tabset.component.ts
159 lines (149 loc) · 4.68 KB
/
route-tabset.component.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/
import { Component, Input, Output, EventEmitter, HostBinding } from '@angular/core';
import { RouterLinkActive } from '@angular/router';
import { convertToBoolProperty, NbBooleanInput } from '../helpers';
/**
* Route tabset components.
* Renders tabs inside of a router-outlet.
*
* ```ts
* tabs = [
* {
* title: 'Route tab #1',
* route: '/pages/description',
* icon: 'home',
* responsive: true, // hide title before `tabset-tab-text-hide-breakpoint` value
* },
* {
* title: 'Route tab #2',
* route: '/pages/images',
* }
* ];
*
* <nb-route-tabset [tabs]="tabs"></nb-route-tabset>
* ```
* ### Installation
*
* Import `NbRouteTabsetModule` to your feature module.
* ```ts
* @NgModule({
* imports: [
* // ...
* NbRouteTabsetModule,
* ],
* })
* export class PageModule { }
* ```
*
* @stacked-example(Route Tabset, tabset/route-tabset-showcase.component)
*
* @styles
*
* route-tabset-background-color:
* route-tabset-border-radius:
* route-tabset-shadow:
* route-tabset-tab-background-color:
* route-tabset-tab-padding:
* route-tabset-tab-text-color:
* route-tabset-tab-text-font-family:
* route-tabset-tab-text-font-size:
* route-tabset-tab-text-font-weight:
* route-tabset-tab-text-line-height:
* route-tabset-tab-text-transform:
* route-tabset-tab-underline-width:
* route-tabset-tab-underline-color:
* route-tabset-tab-active-background-color:
* route-tabset-tab-active-text-color:
* route-tabset-tab-active-underline-color:
* route-tabset-tab-focus-background-color:
* route-tabset-tab-focus-text-color:
* route-tabset-tab-focus-underline-color:
* route-tabset-tab-hover-background-color:
* route-tabset-tab-hover-text-color:
* route-tabset-tab-hover-underline-color:
* route-tabset-tab-disabled-background-color:
* route-tabset-tab-disabled-text-color:
* route-tabset-tab-disabled-underline-color:
* route-tabset-divider-color:
* route-tabset-divider-style:
* route-tabset-divider-width:
* route-tabset-scrollbar-color:
* route-tabset-scrollbar-background-color:
* route-tabset-scrollbar-width:
* route-tabset-tab-text-hide-breakpoint:
*/
@Component({
selector: 'nb-route-tabset',
styleUrls: ['./route-tabset.component.scss'],
template: `
<ul class="route-tabset">
<ng-container *ngFor="let tab of tabs">
<li *ngIf="tab.disabled; else enabled"
[class.responsive]="tab.responsive"
class="route-tab disabled"
tabindex="-1">
<a tabindex="-1" class="tab-link">
<nb-icon *ngIf="tab.icon" [config]="tab.icon"></nb-icon>
<span *ngIf="tab.title" class="tab-text">{{ tab.title }}</span>
</a>
</li>
<ng-template #enabled>
<li (click)="$event.preventDefault(); selectTab(tab)"
[routerLink]="tab.route"
routerLinkActive="active"
[routerLinkActiveOptions]="activeLinkOptions"
[class.responsive]="tab.responsive"
[queryParams]="tab.queryParams"
[queryParamsHandling]="tab.queryParamsHandling"
[fragment]="tab.fragment"
[preserveFragment]="tab.preserveFragment"
[skipLocationChange]="tab.skipLocationChange"
[replaceUrl]="tab.replaceUrl"
[state]="tab.state"
tabindex="0"
class="route-tab">
<a tabindex="-1" class="tab-link">
<nb-icon *ngIf="tab.icon" [config]="tab.icon"></nb-icon>
<span *ngIf="tab.title" class="tab-text">{{ tab.title }}</span>
</a>
</li>
</ng-template>
</ng-container>
</ul>
<router-outlet></router-outlet>
`,
})
export class NbRouteTabsetComponent {
@HostBinding('class.full-width') fullWidthValue: boolean = false;
/**
* Tabs configuration
* @param Object{route: string, title: string, tag?: string, responsive?: boolean, disabled?: boolean}
*/
@Input() tabs: any[];
/**
* Options passed to `routerLinkActiveOptions` directive which set on tab links.
* `{ exact: true }` by default.
*/
@Input() activeLinkOptions: RouterLinkActive['routerLinkActiveOptions'] = { exact: true };
/**
* Take full width of a parent
* @param {boolean} val
*/
@Input()
set fullWidth(val: boolean) {
this.fullWidthValue = convertToBoolProperty(val);
}
static ngAcceptInputType_fullWidth: NbBooleanInput;
/**
* Emits when tab is selected
* @type {EventEmitter<any>}
*/
@Output() changeTab = new EventEmitter<any>();
selectTab(tab: any) {
this.changeTab.emit(tab);
}
}