import { Component, Input, ContentChildren, Output, EventEmitter, ContentChild, TemplateRef, OnChanges } from '@angular/core';
import { RdComponent } from '../../base/rdComponent';
export type TabTypes = 'horizontal' | 'vertical' | 'featured';
@Component({
selector: 'rd-tab-content',
template: `
`
})
export class TabContent extends RdComponent {
@Input("rd-text") text: string;
@Input("rd-icon") icon: string;
@Input("rd-icon-url") iconUrl: string;
@Input("rd-icon-tooltip") tooltip: string;
@Input("rd-icon-color") iconColor: string;
@Input("rd-badge-text") badgeText: string;
@Input("rd-badge-level") badgeLevel: number | string;
@Output("rd-on-open") openEvent: EventEmitter = new EventEmitter();
@Output("rd-click-setting") settingEvent: EventEmitter = new EventEmitter();
active = false;
}
@Component({
selector: 'rd-tab',
template: `
`
})
export class Tab extends RdComponent implements OnChanges {
@Input("rd-type") type: TabTypes = "horizontal";
@ContentChild(TemplateRef) template;
@ContentChildren(TabContent) contents;
activeContent;
ngDoCheck() {
if (this.contents && this.contents._results.length > 0 && !this.activeContent) {
this.contentClicked(this.contents._results[0]);
}
}
ngOnChanges(changes) {
if (this.activeContent && changes.type) {
setTimeout(() => {
this.contentClicked(this.contents._results[0]);
}, 1);
}
}
activateContent(content) {
if (this.activeContent) this.activeContent.active = false;
this.activeContent = content;
this.activeContent.active = true;
}
contentClicked(content) {
if (!content.active) {
this.activateContent(content);
content.openEvent.emit();
}
}
}