primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 11.4 kB
JavaScript
import { Component, ViewEncapsulation, ChangeDetectorRef, Input, ChangeDetectionStrategy, NgModule } from '@angular/core';
import { trigger, state, style, transition, animate } from '@angular/animations';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
class BasePanelMenuItem {
constructor(ref) {
this.ref = ref;
}
handleClick(event, item) {
if (item.disabled) {
event.preventDefault();
return;
}
item.expanded = !item.expanded;
this.ref.detectChanges();
if (!item.url) {
event.preventDefault();
}
if (item.command) {
item.command({
originalEvent: event,
item: item
});
}
}
}
class PanelMenuSub extends BasePanelMenuItem {
constructor(ref) {
super(ref);
}
}
PanelMenuSub.decorators = [
{ type: Component, args: [{
selector: 'p-panelMenuSub',
template: `
<ul [ngClass]="{'p-submenu-list': true, 'p-panelmenu-root-submenu': root}" []="expanded ? {value: 'visible', params: {transitionParams: transitionOptions, height: '*'}} : {value: 'hidden', params: {transitionParams: transitionOptions, height: '0'}}" role="tree">
<ng-template ngFor let-child [ngForOf]="item.items">
<li *ngIf="child.separator" class="p-menu-separator" role="separator">
<li *ngIf="!child.separator" class="p-menuitem" [ngClass]="child.styleClass" [class.p-hidden]="child.visible === false" [ngStyle]="child.style">
<a *ngIf="!child.routerLink" [attr.href]="child.url" class="p-menuitem-link" [attr.tabindex]="!item.expanded ? null : child.disabled ? null : '0'" [attr.id]="child.id"
[ngClass]="{'p-disabled':child.disabled}" role="treeitem" [attr.aria-expanded]="child.expanded"
(click)="handleClick($event,child)" [attr.target]="child.target" [attr.title]="child.title">
<span class="p-panelmenu-icon pi pi-fw" [ngClass]="{'pi-angle-right':!child.expanded,'pi-angle-down':child.expanded}" *ngIf="child.items"></span>
<span class="p-menuitem-icon" [ngClass]="child.icon" *ngIf="child.icon"></span>
<span class="p-menuitem-text" *ngIf="child.escape !== false; else htmlLabel">{{child.label}}</span>
<ng-template #htmlLabel><span class="p-menuitem-text" [innerHTML]="child.label"></span></ng-template>
</a>
<a *ngIf="child.routerLink" [routerLink]="child.routerLink" [queryParams]="child.queryParams" [routerLinkActive]="'p-menuitem-link-active'" [routerLinkActiveOptions]="child.routerLinkActiveOptions||{exact:false}" class="p-menuitem-link"
[ngClass]="{'p-disabled':child.disabled}" [attr.tabindex]="!item.expanded ? null : child.disabled ? null : '0'" [attr.id]="child.id" role="treeitem" [attr.aria-expanded]="child.expanded"
(click)="handleClick($event,child)" [attr.target]="child.target" [attr.title]="child.title"
[fragment]="child.fragment" [queryParamsHandling]="child.queryParamsHandling" [preserveFragment]="child.preserveFragment" [skipLocationChange]="child.skipLocationChange" [replaceUrl]="child.replaceUrl" [state]="child.state">
<span class="p-panelmenu-icon pi pi-fw" [ngClass]="{'pi-angle-right':!child.expanded,'pi-angle-down':child.expanded}" *ngIf="child.items"></span>
<span class="p-menuitem-icon" [ngClass]="child.icon" *ngIf="child.icon"></span>
<span class="p-menuitem-text" *ngIf="child.escape !== false; else htmlRouteLabel">{{child.label}}</span>
<ng-template #htmlRouteLabel><span class="p-menuitem-text" [innerHTML]="child.label"></span></ng-template>
</a>
<p-panelMenuSub [item]="child" [expanded]="child.expanded" [transitionOptions]="transitionOptions" *ngIf="child.items"></p-panelMenuSub>
</li>
</ng-template>
</ul>
`,
animations: [
trigger('submenu', [
state('hidden', style({
height: '0',
overflow: 'hidden'
})),
state('visible', style({
height: '*'
})),
transition('visible <=> hidden', [style({ overflow: 'hidden' }), animate('{{transitionParams}}')]),
transition('void => *', animate(0))
])
],
encapsulation: ViewEncapsulation.None
},] }
];
PanelMenuSub.ctorParameters = () => [
{ type: ChangeDetectorRef }
];
PanelMenuSub.propDecorators = {
item: [{ type: Input }],
expanded: [{ type: Input }],
transitionOptions: [{ type: Input }],
root: [{ type: Input }]
};
class PanelMenu extends BasePanelMenuItem {
constructor(ref) {
super(ref);
this.multiple = true;
this.transitionOptions = '400ms cubic-bezier(0.86, 0, 0.07, 1)';
}
collapseAll() {
for (let item of this.model) {
if (item.expanded) {
item.expanded = false;
}
}
}
handleClick(event, item) {
if (!this.multiple) {
for (let modelItem of this.model) {
if (item !== modelItem && modelItem.expanded) {
modelItem.expanded = false;
}
}
}
this.animating = true;
super.handleClick(event, item);
}
onToggleDone() {
this.animating = false;
}
}
PanelMenu.decorators = [
{ type: Component, args: [{
selector: 'p-panelMenu',
template: `
<div [class]="styleClass" [ngStyle]="style" [ngClass]="'p-panelmenu p-component'">
<ng-container *ngFor="let item of model;let f=first;let l=last;">
<div class="p-panelmenu-panel" [ngClass]="{'p-hidden': item.visible === false}">
<div [ngClass]="{'p-component p-panelmenu-header':true, 'p-highlight':item.expanded,'p-disabled':item.disabled}" [class]="item.styleClass" [ngStyle]="item.style">
<a *ngIf="!item.routerLink" [attr.href]="item.url" (click)="handleClick($event,item)" [attr.tabindex]="item.disabled ? null : '0'" [attr.id]="item.id"
[attr.target]="item.target" [attr.title]="item.title" class="p-panelmenu-header-link" [attr.aria-expanded]="item.expanded" [attr.id]="item.id + '_header'" [attr.aria-controls]="item.id +'_content'">
<span *ngIf="item.items" class="p-panelmenu-icon pi" [ngClass]="{'pi-chevron-right':!item.expanded,'pi-chevron-down':item.expanded}"></span>
<span class="p-menuitem-icon" [ngClass]="item.icon" *ngIf="item.icon"></span>
<span class="p-menuitem-text" *ngIf="item.escape !== false; else htmlLabel">{{item.label}}</span>
<ng-template #htmlLabel><span class="p-menuitem-text" [innerHTML]="item.label"></span></ng-template>
</a>
<a *ngIf="item.routerLink" [routerLink]="item.routerLink" [queryParams]="item.queryParams" [routerLinkActive]="'p-menuitem-link-active'" [routerLinkActiveOptions]="item.routerLinkActiveOptions||{exact:false}"
(click)="handleClick($event,item)" [attr.target]="item.target" [attr.title]="item.title" class="p-panelmenu-header-link" [attr.id]="item.id" [attr.tabindex]="item.disabled ? null : '0'"
[fragment]="item.fragment" [queryParamsHandling]="item.queryParamsHandling" [preserveFragment]="item.preserveFragment" [skipLocationChange]="item.skipLocationChange" [replaceUrl]="item.replaceUrl" [state]="item.state">
<span *ngIf="item.items" class="p-panelmenu-icon pi" [ngClass]="{'pi-chevron-right':!item.expanded,'pi-chevron-down':item.expanded}"></span>
<span class="p-menuitem-icon" [ngClass]="item.icon" *ngIf="item.icon"></span>
<span class="p-menuitem-text" *ngIf="item.escape !== false; else htmlRouteLabel">{{item.label}}</span>
<ng-template #htmlRouteLabel><span class="p-menuitem-text" [innerHTML]="item.label"></span></ng-template>
</a>
</div>
<div *ngIf="item.items" class="p-toggleable-content" []="item.expanded ? {value: 'visible', params: {transitionParams: animating ? transitionOptions : '0ms', height: '*'}} : {value: 'hidden', params: {transitionParams: transitionOptions, height: '0'}}" (.done)="onToggleDone()">
<div class="p-panelmenu-content" role="region" [attr.id]="item.id +'_content' " [attr.aria-labelledby]="item.id +'_header'">
<p-panelMenuSub [item]="item" [expanded]="true" [transitionOptions]="transitionOptions" [root]="true"></p-panelMenuSub>
</div>
</div>
</div>
</ng-container>
</div>
`,
animations: [
trigger('rootItem', [
state('hidden', style({
height: '0',
overflow: 'hidden'
})),
state('visible', style({
height: '*'
})),
transition('visible <=> hidden', [style({ overflow: 'hidden' }), animate('{{transitionParams}}')]),
transition('void => *', animate(0))
])
],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
styles: [".p-panelmenu .p-panelmenu-header-link{-ms-user-select:none;-webkit-user-select:none;align-items:center;cursor:pointer;display:flex;position:relative;text-decoration:none;user-select:none}.p-panelmenu .p-panelmenu-header-link:focus{z-index:1}.p-panelmenu .p-submenu-list{list-style:none;margin:0;padding:0}.p-panelmenu .p-menuitem-link{-ms-user-select:none;-webkit-user-select:none;align-items:center;cursor:pointer;display:flex;text-decoration:none;user-select:none}.p-panelmenu .p-menuitem-text{line-height:1}"]
},] }
];
PanelMenu.ctorParameters = () => [
{ type: ChangeDetectorRef }
];
PanelMenu.propDecorators = {
model: [{ type: Input }],
style: [{ type: Input }],
styleClass: [{ type: Input }],
multiple: [{ type: Input }],
transitionOptions: [{ type: Input }]
};
class PanelMenuModule {
}
PanelMenuModule.decorators = [
{ type: NgModule, args: [{
imports: [CommonModule, RouterModule],
exports: [PanelMenu, RouterModule],
declarations: [PanelMenu, PanelMenuSub]
},] }
];
/**
* Generated bundle index. Do not edit.
*/
export { BasePanelMenuItem, PanelMenu, PanelMenuModule, PanelMenuSub };
//# sourceMappingURL=primeng-panelmenu.js.map