File

projects/rebirth-ng/src/lib/tabs/tabs.component.ts

Implements

AfterContentInit

Metadata

exportAs tabs
selector re-tabs
templateUrl ./tabs.component.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(rebirthNGConfig: RebirthNGConfig)
Parameters :
Name Type Optional
rebirthNGConfig RebirthNGConfig no

Inputs

activeTab

Type: number | string

cssClass

Type: string

justified

Type: boolean

type

Type: "tabs" | "pills"

Default value: 'tabs'

vertical

Type: boolean

Outputs

activeTabChange $event type: EventEmitter

Methods

ngAfterContentInit
ngAfterContentInit()
Returns : void
select
select(id: number | string)
Parameters :
Name Type Optional
id number | string no
Returns : void

Properties

tabs
tabs: QueryList<TabComponent>
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>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""