blob: 595f3040fad77b0e2db780402ba9f636cb25c760 [file] [log] [blame]
import { Component, Input, AfterContentInit, ContentChildren, QueryList, HostBinding } from '@angular/core';
import { TabComponent } from './children/tab.component';
import { SvgIconComponent } from "./../../../src/angular/svg-icon/svg-icon.component";
import { Mode, Placement, Size } from './../common/enums';
import template from "./tabs.component.html";
@Component({
selector: 'sdc-tabs',
template: template
})
export class TabsComponent implements AfterContentInit {
@HostBinding('class') classes = 'sdc-tabs sdc-tabs-header';
@ContentChildren(TabComponent) private tabs: QueryList<TabComponent>;
public _size = Size.medium;
public selectTab(tab: TabComponent) {
// deactivate all tabs
this.tabs.toArray().forEach((_tab: TabComponent) => {
_tab.active = false;
_tab.titleIconMode = Mode.secondary;
});
// activate the tab the user has clicked on.
tab.active = true;
tab.titleIconMode = Mode.primary;
}
public ngAfterContentInit() {
// get all active tabs
const activeTabs = this.tabs.filter((tab) => tab.active);
// if there is no active tab set, activate the first
if (activeTabs.length === 0) {
this.selectTab(this.tabs.first);
}
}
}