diff --git a/src/app/components/tabmenu/tabmenu.ts b/src/app/components/tabmenu/tabmenu.ts index 12a7a9cf236..b040b499251 100644 --- a/src/app/components/tabmenu/tabmenu.ts +++ b/src/app/components/tabmenu/tabmenu.ts @@ -1,7 +1,8 @@ -import {NgModule,Component,ElementRef,Input,Output} from '@angular/core'; +import {NgModule,Component,Input,ContentChildren,QueryList,AfterContentInit,TemplateRef} from '@angular/core'; import {CommonModule} from '@angular/common'; import {DomHandler} from '../dom/domhandler'; import {MenuItem} from '../common/menuitem'; +import {PrimeTemplate} from '../common/shared'; import {RouterModule} from '@angular/router'; @Component({ @@ -9,19 +10,25 @@ import {RouterModule} from '@angular/router'; template: `
@@ -29,7 +36,7 @@ import {RouterModule} from '@angular/router'; `, providers: [DomHandler] }) -export class TabMenu { +export class TabMenu implements AfterContentInit { @Input() model: MenuItem[]; @@ -41,6 +48,24 @@ export class TabMenu { @Input() styleClass: string; + @ContentChildren(PrimeTemplate) templates: QueryList; + + itemTemplate: TemplateRef; + + ngAfterContentInit() { + this.templates.forEach((item) => { + switch(item.getType()) { + case 'item': + this.itemTemplate = item.template; + break; + + default: + this.itemTemplate = item.template; + break; + } + }); + } + itemClick(event: Event, item: MenuItem) { if(item.disabled) { event.preventDefault(); diff --git a/src/app/components/tabview/tabview.ts b/src/app/components/tabview/tabview.ts index 5ce56e935a9..dee02c687ac 100644 --- a/src/app/components/tabview/tabview.ts +++ b/src/app/components/tabview/tabview.ts @@ -1,5 +1,5 @@ -import {NgModule,Component,ElementRef,OnDestroy,Input,Output,EventEmitter,HostListener,AfterContentInit, - ContentChildren,ContentChild,QueryList,TemplateRef,EmbeddedViewRef,ViewContainerRef} from '@angular/core'; +import {NgModule,Component,ElementRef,OnDestroy,Input,Output,EventEmitter,AfterContentInit, + ContentChildren,QueryList,TemplateRef,EmbeddedViewRef,ViewContainerRef} from '@angular/core'; import {CommonModule} from '@angular/common'; import {TooltipModule} from '../tooltip/tooltip'; import {SharedModule,PrimeTemplate} from '../common/shared'; diff --git a/src/app/showcase/components/tabmenu/tabmenudemo.html b/src/app/showcase/components/tabmenu/tabmenudemo.html index a70c69cf96e..4deb7fc69f4 100644 --- a/src/app/showcase/components/tabmenu/tabmenudemo.html +++ b/src/app/showcase/components/tabmenu/tabmenudemo.html @@ -6,7 +6,23 @@
- +

Default

+ + +

Templating

+ + +
+
+
+ {{item.label}} +
+ + + +
+
+
@@ -51,7 +67,7 @@

Getting Started

ActiveItem

-

By defaulttem item that matches the active route is highlighted, alternatively activeItem property can be used choose the initial active item.

+

By default item that matches the active route is highlighted, alternatively activeItem property can be used choose the initial active item.

 
 <p-tabMenu [model]="items" [activeItem]="items[0]"></p-tabMenu>
@@ -79,6 +95,18 @@ 

ActiveItem

} }
+
+ +

Templating

+

Menuitem content supports templating via the "item" template which gets the menuitem instance and the index.

+
+
+<p-tabMenu [model]="items">
+    <ng-template pTemplate="item" let-item let-i="index">
+        //item content
+    </ng-template>
+</p-tabMenu>
+
 

Properties

@@ -171,7 +199,23 @@

Dependencies

 
-<p-tabMenu [model]="items"></p-tabMenu>
+<h3 class="first">Default</h3>
+<p-tabMenu [model]="items1" [activeItem]="items1[0]"></p-tabMenu>
+
+<h3>Templating</h3>
+<p-tabMenu [model]="items2" [activeItem]="activeItem">
+    <ng-template pTemplate="item" let-item let-i="index">
+        <div style="position: relative; text-align: center; min-width: 10em">
+            <div class="ui-menuitem-icon" [ngClass]="item.icon" *ngIf="item.icon" style="font-size: 2em"></div>
+            <div class="ui-menuitem-text">
+                {{item.label}}
+            </div>
+            <a tabindex="0" class="ui-menuitem-icon" (click)="closeItem($event, i)" style="position: absolute; right: -1em; top: -.5em; padding: 0" *ngIf="i !== 0">
+                <span class="pi pi-times"></span>
+            </a>
+        </div>
+    </ng-template>
+</p-tabMenu>
 
 
@@ -179,17 +223,37 @@

Dependencies

export class TabMenuDemo { - items: MenuItem[]; + items1: MenuItem[]; + + items2: MenuItem[]; + + activeItem: MenuItem; ngOnInit() { - this.items = [ + this.items1 = [ + {label: 'Stats', icon: 'fa fa-fw fa-bar-chart'}, + {label: 'Calendar', icon: 'fa fa-fw fa-calendar'}, + {label: 'Documentation', icon: 'fa fa-fw fa-book'}, + {label: 'Support', icon: 'fa fa-fw fa-support'}, + {label: 'Social', icon: 'fa fa-fw fa-twitter'} + ]; + + this.items2 = [ {label: 'Stats', icon: 'fa fa-fw fa-bar-chart'}, {label: 'Calendar', icon: 'fa fa-fw fa-calendar'}, {label: 'Documentation', icon: 'fa fa-fw fa-book'}, {label: 'Support', icon: 'fa fa-fw fa-support'}, {label: 'Social', icon: 'fa fa-fw fa-twitter'} ]; + + this.activeItem = this.items2[0]; } + + closeItem(event, index) { + this.items2 = this.items2.filter((item, i) => i !== index); + event.preventDefault(); + } + } diff --git a/src/app/showcase/components/tabmenu/tabmenudemo.ts b/src/app/showcase/components/tabmenu/tabmenudemo.ts index c829f442ff6..3c6230a1ab2 100644 --- a/src/app/showcase/components/tabmenu/tabmenudemo.ts +++ b/src/app/showcase/components/tabmenu/tabmenudemo.ts @@ -6,15 +6,34 @@ import {MenuItem} from '../../../components/common/api'; }) export class TabMenuDemo { - items: MenuItem[]; + items1: MenuItem[]; + + items2: MenuItem[]; + + activeItem: MenuItem; ngOnInit() { - this.items = [ + this.items1 = [ + {label: 'Stats', icon: 'fa fa-fw fa-bar-chart'}, + {label: 'Calendar', icon: 'fa fa-fw fa-calendar'}, + {label: 'Documentation', icon: 'fa fa-fw fa-book'}, + {label: 'Support', icon: 'fa fa-fw fa-support'}, + {label: 'Social', icon: 'fa fa-fw fa-twitter'} + ]; + + this.items2 = [ {label: 'Stats', icon: 'fa fa-fw fa-bar-chart'}, {label: 'Calendar', icon: 'fa fa-fw fa-calendar'}, {label: 'Documentation', icon: 'fa fa-fw fa-book'}, {label: 'Support', icon: 'fa fa-fw fa-support'}, {label: 'Social', icon: 'fa fa-fw fa-twitter'} ]; + + this.activeItem = this.items2[0]; + } + + closeItem(event, index) { + this.items2 = this.items2.filter((item, i) => i !== index); + event.preventDefault(); } } \ No newline at end of file