90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
|
/**
|
||
|
* The main component that renders single TabComponent
|
||
|
* instances.
|
||
|
*/
|
||
|
|
||
|
import {
|
||
|
Component,
|
||
|
ContentChildren,
|
||
|
QueryList,
|
||
|
AfterContentInit, Output, EventEmitter, ViewChild, ElementRef,
|
||
|
} from '@angular/core';
|
||
|
|
||
|
import { TabComponent } from './tab.component';
|
||
|
|
||
|
declare var UIkit: any;
|
||
|
|
||
|
@Component({
|
||
|
selector: 'my-small-tabs',
|
||
|
template: `
|
||
|
<ul uk-tab class="uk-tab main-tabs uk-margin-remove uk-child-width-expand">
|
||
|
<li *ngFor="let tab of activeTabs" [class]="'uk-active uk-padding-remove '+(tab.statistics ? ' statistics ' : '')">
|
||
|
<a class="uk-width-1-1 uk-height-1-1">
|
||
|
<div class="tab-header">{{tab.title}}</div>
|
||
|
<div *ngIf="tab.num" class="number">{{tab.num | number}}</div>
|
||
|
<div *ngIf="tab.statistics" class="number">
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
||
|
<path d="M0 0h24v24H0z" fill="none"></path>
|
||
|
<path d="M10 20h4V4h-4v16zm-6 0h4v-8H4v8zM16 9v11h4V9h-4z"></path>
|
||
|
</svg>
|
||
|
</div>
|
||
|
</a>
|
||
|
</li>
|
||
|
<li class="uk-padding-remove fake_tab">
|
||
|
<a class="uk-text-center uk-width-1-1 uk-height-1-1">...</a>
|
||
|
<div #drop_element uk-drop="mode: click" class="uk-drop">
|
||
|
<div class="uk-card uk-card-body uk-card-default">
|
||
|
<ul class="uk-list uk-list-divider main-small-tabs" uk-switcher="connect: .small-tabs-content">
|
||
|
<li *ngFor="let tab of tabs" (click)="selectTab(tab)" [class]="' uk-height-1-1 uk-width-1-1'+(tab.active ? ' uk-text-bold' : '')">
|
||
|
<a class="uk-display-block uk-height-1-1 uk-width-1-1">{{tab.title}}</a>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</div>
|
||
|
</li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="uk-switcher small-tabs-content main-tabs-content">
|
||
|
<ng-content></ng-content>
|
||
|
</div>
|
||
|
|
||
|
`
|
||
|
})
|
||
|
export class SmallTabsComponent implements AfterContentInit {
|
||
|
@ViewChild('drop_element') dropElement: ElementRef;
|
||
|
|
||
|
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
|
||
|
@Output() public selectedActiveTab: EventEmitter<any> = new EventEmitter();
|
||
|
public activeTabs: TabComponent[] = [];
|
||
|
|
||
|
// contentChildren are set
|
||
|
ngAfterContentInit() {
|
||
|
// get all active tabs
|
||
|
this.activeTabs = this.tabs.filter((tab)=>tab.active);
|
||
|
|
||
|
// if there is no active tab set, activate the first
|
||
|
if(this.tabs.length > 0 && this.activeTabs.length === 0) {
|
||
|
this.selectTab(this.tabs.first);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
selectTab(tab: TabComponent){
|
||
|
console.log("selectTab: "+tab.title);
|
||
|
|
||
|
// deactivate all tabs
|
||
|
this.tabs.toArray().forEach(tab => tab.active = false);
|
||
|
|
||
|
this.activeTabs = [];
|
||
|
this.activeTabs.push(tab);
|
||
|
|
||
|
// activate the tab the user has clicked on.
|
||
|
tab.active = true;
|
||
|
this.selectedActiveTab.emit(tab.tabId);
|
||
|
|
||
|
if(this.dropElement) {
|
||
|
console.log("dropElement: ",this.dropElement);
|
||
|
UIkit.drop(this.dropElement.nativeElement).hide(false);
|
||
|
}
|
||
|
}
|
||
|
}
|