1
|
/**
|
2
|
* The main component that renders single TabComponent
|
3
|
* instances.
|
4
|
*/
|
5
|
|
6
|
import {
|
7
|
Component,
|
8
|
ContentChildren,
|
9
|
QueryList,
|
10
|
AfterContentInit, Output, EventEmitter,
|
11
|
} from '@angular/core';
|
12
|
|
13
|
import { TabComponent } from './tab.component';
|
14
|
|
15
|
@Component({
|
16
|
selector: 'my-tabs',
|
17
|
template: `
|
18
|
<ul [class]="(tabs.toArray().length > 2 ? 'uk-visible@m' : '') + ' uk-tab main-tabs uk-margin-remove uk-child-width-expand'"
|
19
|
uk-tab uk-switcher="connect: .tabs-content" uk-height-match="target: .tab-header">
|
20
|
<li *ngFor="let tab of tabs.toArray(); let i=index"
|
21
|
[class]="'uk-padding-remove '+ tab.customClass + (i == 0?' uk-active':'')"
|
22
|
(click)="selectTab(tab)">
|
23
|
<a class="uk-width-1-1 uk-height-1-1">
|
24
|
<div class="tab-header">{{tab.title}}</div>
|
25
|
<div *ngIf="tab.num" class="number">{{tab.num | number}}</div>
|
26
|
<div *ngIf="tab.customClass == 'statistics'" class="number">
|
27
|
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
28
|
<path d="M0 0h24v24H0z" fill="none"></path>
|
29
|
<path d="M10 20h4V4h-4v16zm-6 0h4v-8H4v8zM16 9v11h4V9h-4z"></path>
|
30
|
</svg>
|
31
|
</div>
|
32
|
</a>
|
33
|
</li>
|
34
|
</ul>
|
35
|
<div [class]="(tabs.toArray().length > 2 ? 'uk-visible@m' : '') + ' uk-switcher tabs-content main-tabs-content'">
|
36
|
<ng-content></ng-content>
|
37
|
</div>
|
38
|
`
|
39
|
})
|
40
|
export class TabsComponent {
|
41
|
|
42
|
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
|
43
|
@Output() public selectedActiveTab: EventEmitter<any> = new EventEmitter();
|
44
|
|
45
|
selectTab(tab: TabComponent){
|
46
|
// activate the tab the user has clicked on.
|
47
|
this.selectedActiveTab.emit(tab.tabId);
|
48
|
}
|
49
|
}
|