import {
Component,
Input,
Output,
ContentChildren,
QueryList,
EventEmitter
} from '@angular/core';
import { TabComponent } from './tab.component';
import './tabs.scss';
@Component({
selector: 'swui-tabs',
template: `
`,
host: {
class: 'swui-tabs'
}
})
export class TabsComponent {
@Input() vertical: boolean;
@Output() select = new EventEmitter();
@ContentChildren(TabComponent) tabs: QueryList;
ngAfterContentInit() {
const tabs = this.tabs.toArray();
const actives = this.tabs.filter(t => { return t.active; });
if(actives.length > 1) {
console.error(`Multiple active tabs set 'active'`);
} else if(!actives.length && tabs.length) {
tabs[0].active = true;
}
}
tabClicked(activeTab) {
const tabs = this.tabs.toArray();
tabs.forEach(tab => tab.active = false);
activeTab.active = true;
this.select.emit(activeTab);
}
}