diff --git a/utils/tabs/small-tabs.component.ts b/utils/tabs/small-tabs.component.ts new file mode 100644 index 00000000..e0e757f3 --- /dev/null +++ b/utils/tabs/small-tabs.component.ts @@ -0,0 +1,89 @@ +/** + * 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: ` + + +
+ +
+ + ` +}) +export class SmallTabsComponent implements AfterContentInit { + @ViewChild('drop_element') dropElement: ElementRef; + + @ContentChildren(TabComponent) tabs: QueryList; + @Output() public selectedActiveTab: EventEmitter = 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); + } + } +} diff --git a/utils/tabs/tabs.component.ts b/utils/tabs/tabs.component.ts index bf786eaa..d476bd40 100644 --- a/utils/tabs/tabs.component.ts +++ b/utils/tabs/tabs.component.ts @@ -15,8 +15,7 @@ import { TabComponent } from './tab.component'; @Component({ selector: 'my-tabs', template: ` -