projects/rebirth-ng/src/lib/tabs/tabs.component.ts
exportAs | tabs |
selector | re-tabs |
templateUrl | ./tabs.component.html |
Properties |
Methods |
Inputs |
Outputs |
constructor(rebirthNGConfig: RebirthNGConfig)
|
||||||
Parameters :
|
activeTab
|
Type: |
cssClass
|
Type: |
justified
|
Type: |
type
|
Type:
Default value: |
vertical
|
Type: |
activeTabChange
|
$event type: EventEmitter
|
ngAfterContentInit |
ngAfterContentInit()
|
Returns :
void
|
select | ||||||
select(id: number | string)
|
||||||
Parameters :
Returns :
void
|
tabs |
tabs:
|
Type : QueryList<TabComponent>
|
Decorators : ContentChildren
|
import {
Component,
QueryList,
ContentChildren,
Input,
Output,
EventEmitter,
AfterContentInit
} from '@angular/core';
import { TabComponent } from './tab.component';
import { RebirthNGConfig } from '../rebirth-ng.config';
@Component({
selector: 're-tabs',
templateUrl: './tabs.component.html',
exportAs: 'tabs'
})
export class TabsComponent implements AfterContentInit {
@Input() type: 'tabs' | 'pills' = 'tabs';
@Input() activeTab: number | string;
@Input() vertical: boolean;
@Input() justified: boolean;
@Input() cssClass: string;
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
@Output() activeTabChange = new EventEmitter<number | string>();
constructor(rebirthNGConfig: RebirthNGConfig) {
this.type = <any>rebirthNGConfig.tabs.type;
this.justified = rebirthNGConfig.tabs.justified;
this.vertical = rebirthNGConfig.tabs.vertical;
}
ngAfterContentInit(): void {
if (!this.activeTab && this.tabs.length) {
this.select(this.tabs.first.id);
}
}
select(id: number | string) {
const tab = this.tabs.find(item => item.id === id);
if (tab && !tab.disabled) {
this.activeTab = id;
this.activeTabChange.emit(id);
}
}
}
<ul class="nav nav-{{type}} {{cssClass}}" [ngClass]="{'nav-stacked': vertical,'nav-justified': justified}"
role="tablist">
<li role="presentation" *ngFor="let tab of tabs" [class.disabled]="tab.disabled"
[class.active]="tab.id == activeTab" (click)="select(tab.id)">
<a role="tab" data-toggle="tab" [attr.aria-expanded]="tab.id == activeTab">
<ng-template *ngIf="!tab.title" [ngTemplateOutlet]="tab.titleTpl?.templateRef"></ng-template>
<span *ngIf="tab.title">{{tab.title}}</span>
</a>
</li>
</ul>
<div class="tab-content">
<ng-container *ngFor="let tab of tabs">
<div class="tab-pane fade" role="tabpanel" [ngClass]="{'in active': tab.id == activeTab}">
<ng-template [ngTemplateOutlet]="tab?.contentTpl?.templateRef"></ng-template>
</div>
</ng-container>
</div>