UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![npm downloads](https://img.shields.io/npm/dm/primeng.sv

473 lines (469 loc) 25.8 kB
import * as i0 from '@angular/core'; import { EventEmitter, Component, ViewEncapsulation, Input, Output, ChangeDetectionStrategy, NgModule } from '@angular/core'; import * as i1 from '@angular/common'; import { CommonModule } from '@angular/common'; import { DomHandler, ConnectedOverlayScrollHandler } from 'primeng/dom'; import * as i3 from '@angular/router'; import { RouterModule } from '@angular/router'; import * as i2 from 'primeng/ripple'; import { RippleModule } from 'primeng/ripple'; import { trigger, transition, style, animate } from '@angular/animations'; class TieredMenuSub { constructor(el, renderer, cd) { this.el = el; this.renderer = renderer; this.cd = cd; this.autoZIndex = true; this.baseZIndex = 0; this.leafClick = new EventEmitter(); this.keydownItem = new EventEmitter(); this.menuHoverActive = false; } get parentActive() { return this._parentActive; } set parentActive(value) { if (!this.root) { this._parentActive = value; if (!value) this.activeItem = null; } } onItemClick(event, item) { if (item.disabled) { event.preventDefault(); return; } if (!item.url && !item.routerLink) { event.preventDefault(); } if (item.command) { item.command({ originalEvent: event, item: item }); } if (item.items) { if (this.activeItem && item === this.activeItem) { this.activeItem = null; this.unbindDocumentClickListener(); } else { this.activeItem = item; if (this.root) { this.bindDocumentClickListener(); } } } if (!item.items) { this.onLeafClick(); } } onItemMouseEnter(event, item) { if (item.disabled || this.mobileActive) { event.preventDefault(); return; } if (this.root) { if (this.activeItem || this.autoDisplay || this.popup) { this.activeItem = item; this.bindDocumentClickListener(); } } else { this.activeItem = item; this.bindDocumentClickListener(); } } onLeafClick() { this.activeItem = null; if (this.root) { this.unbindDocumentClickListener(); } this.leafClick.emit(); } onItemKeyDown(event, item) { let listItem = event.currentTarget.parentElement; switch (event.key) { case 'ArrowDown': var nextItem = this.findNextItem(listItem); if (nextItem) { nextItem.children[0].focus(); } event.preventDefault(); break; case 'ArrowUp': var prevItem = this.findPrevItem(listItem); if (prevItem) { prevItem.children[0].focus(); } event.preventDefault(); break; case 'ArrowRight': if (item.items) { this.activeItem = item; if (this.root) { this.bindDocumentClickListener(); } setTimeout(() => { listItem.children[1].children[0].children[0].children[0].focus(); }, 50); } event.preventDefault(); break; default: break; } this.keydownItem.emit({ originalEvent: event, element: listItem }); } findNextItem(item) { let nextItem = item.nextElementSibling; if (nextItem) return DomHandler.hasClass(nextItem, 'p-disabled') || !DomHandler.hasClass(nextItem, 'p-menuitem') ? this.findNextItem(nextItem) : nextItem; else return null; } findPrevItem(item) { let prevItem = item.previousElementSibling; if (prevItem) return DomHandler.hasClass(prevItem, 'p-disabled') || !DomHandler.hasClass(prevItem, 'p-menuitem') ? this.findPrevItem(prevItem) : prevItem; else return null; } onChildItemKeyDown(event) { if (event.originalEvent.key === 'ArrowLeft') { this.activeItem = null; if (this.root) { this.unbindDocumentClickListener(); } event.element.parentElement.parentElement.parentElement.children[0].focus(); } } bindDocumentClickListener() { if (!this.documentClickListener) { this.documentClickListener = (event) => { if (this.el && !this.el.nativeElement.contains(event.target)) { this.activeItem = null; this.cd.markForCheck(); this.unbindDocumentClickListener(); } }; document.addEventListener('click', this.documentClickListener); } } unbindDocumentClickListener() { if (this.documentClickListener) { document.removeEventListener('click', this.documentClickListener); this.documentClickListener = null; } } ngOnDestroy() { this.unbindDocumentClickListener(); } } TieredMenuSub.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: TieredMenuSub, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); TieredMenuSub.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.4", type: TieredMenuSub, selector: "p-tieredMenuSub", inputs: { item: "item", root: "root", autoDisplay: "autoDisplay", autoZIndex: "autoZIndex", baseZIndex: "baseZIndex", mobileActive: "mobileActive", popup: "popup", parentActive: "parentActive" }, outputs: { leafClick: "leafClick", keydownItem: "keydownItem" }, ngImport: i0, template: ` <ul [ngClass]="{'p-submenu-list': !root}"> <ng-template ngFor let-child [ngForOf]="(root ? item : item.items)"> <li *ngIf="child.separator" class="p-menu-separator" [ngClass]="{'p-hidden': child.visible === false}"> <li *ngIf="!child.separator" #listItem [ngClass]="{'p-menuitem':true, 'p-menuitem-active': child === activeItem, 'p-hidden': child.visible === false}" [ngStyle]="child.style" [class]="child.styleClass"> <a *ngIf="!child.routerLink" (keydown)="onItemKeyDown($event, child)" [attr.href]="child.url" [attr.data-automationid]="child.automationId" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" (click)="onItemClick($event, child)" (mouseenter)="onItemMouseEnter($event,child)" [ngClass]="{'p-menuitem-link':true,'p-disabled':child.disabled}" [attr.tabindex]="child.disabled ? null : '0'" [attr.aria-haspopup]="item.items != null" [attr.aria-expanded]="item === activeItem" pRipple> <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="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> <span class="p-submenu-icon pi pi-angle-right" *ngIf="child.items"></span> </a> <a *ngIf="child.routerLink" (keydown)="onItemKeyDown($event, child)" [routerLink]="child.routerLink" [attr.data-automationid]="child.automationId" [queryParams]="child.queryParams" [routerLinkActive]="'p-menuitem-link-active'" [routerLinkActiveOptions]="child.routerLinkActiveOptions||{exact:false}" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [attr.tabindex]="child.disabled ? null : '0'" role="menuitem" (click)="onItemClick($event, child)" (mouseenter)="onItemMouseEnter($event,child)" [ngClass]="{'p-menuitem-link':true,'p-disabled':child.disabled}" [fragment]="child.fragment" [queryParamsHandling]="child.queryParamsHandling" [preserveFragment]="child.preserveFragment" [skipLocationChange]="child.skipLocationChange" [replaceUrl]="child.replaceUrl" [state]="child.state" pRipple> <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="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> <span class="p-submenu-icon pi pi-angle-right" *ngIf="child.items"></span> </a> <p-tieredMenuSub (keydownItem)="onChildItemKeyDown($event)" [parentActive]="child === activeItem" [item]="child" *ngIf="child.items" [mobileActive]="mobileActive" [autoDisplay]="autoDisplay" (leafClick)="onLeafClick()" [popup]="popup"></p-tieredMenuSub> </li> </ng-template> </ul> `, isInline: true, components: [{ type: TieredMenuSub, selector: "p-tieredMenuSub", inputs: ["item", "root", "autoDisplay", "autoZIndex", "baseZIndex", "mobileActive", "popup", "parentActive"], outputs: ["leafClick", "keydownItem"] }], directives: [{ type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i2.Ripple, selector: "[pRipple]" }, { type: i3.RouterLinkWithHref, selector: "a[routerLink],area[routerLink]", inputs: ["routerLink", "target", "queryParams", "fragment", "queryParamsHandling", "preserveFragment", "skipLocationChange", "replaceUrl", "state", "relativeTo"] }, { type: i3.RouterLinkActive, selector: "[routerLinkActive]", inputs: ["routerLinkActiveOptions", "routerLinkActive"], exportAs: ["routerLinkActive"] }], encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: TieredMenuSub, decorators: [{ type: Component, args: [{ selector: 'p-tieredMenuSub', template: ` <ul [ngClass]="{'p-submenu-list': !root}"> <ng-template ngFor let-child [ngForOf]="(root ? item : item.items)"> <li *ngIf="child.separator" class="p-menu-separator" [ngClass]="{'p-hidden': child.visible === false}"> <li *ngIf="!child.separator" #listItem [ngClass]="{'p-menuitem':true, 'p-menuitem-active': child === activeItem, 'p-hidden': child.visible === false}" [ngStyle]="child.style" [class]="child.styleClass"> <a *ngIf="!child.routerLink" (keydown)="onItemKeyDown($event, child)" [attr.href]="child.url" [attr.data-automationid]="child.automationId" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" (click)="onItemClick($event, child)" (mouseenter)="onItemMouseEnter($event,child)" [ngClass]="{'p-menuitem-link':true,'p-disabled':child.disabled}" [attr.tabindex]="child.disabled ? null : '0'" [attr.aria-haspopup]="item.items != null" [attr.aria-expanded]="item === activeItem" pRipple> <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="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> <span class="p-submenu-icon pi pi-angle-right" *ngIf="child.items"></span> </a> <a *ngIf="child.routerLink" (keydown)="onItemKeyDown($event, child)" [routerLink]="child.routerLink" [attr.data-automationid]="child.automationId" [queryParams]="child.queryParams" [routerLinkActive]="'p-menuitem-link-active'" [routerLinkActiveOptions]="child.routerLinkActiveOptions||{exact:false}" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [attr.tabindex]="child.disabled ? null : '0'" role="menuitem" (click)="onItemClick($event, child)" (mouseenter)="onItemMouseEnter($event,child)" [ngClass]="{'p-menuitem-link':true,'p-disabled':child.disabled}" [fragment]="child.fragment" [queryParamsHandling]="child.queryParamsHandling" [preserveFragment]="child.preserveFragment" [skipLocationChange]="child.skipLocationChange" [replaceUrl]="child.replaceUrl" [state]="child.state" pRipple> <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="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> <span class="p-submenu-icon pi pi-angle-right" *ngIf="child.items"></span> </a> <p-tieredMenuSub (keydownItem)="onChildItemKeyDown($event)" [parentActive]="child === activeItem" [item]="child" *ngIf="child.items" [mobileActive]="mobileActive" [autoDisplay]="autoDisplay" (leafClick)="onLeafClick()" [popup]="popup"></p-tieredMenuSub> </li> </ng-template> </ul> `, encapsulation: ViewEncapsulation.None }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { item: [{ type: Input }], root: [{ type: Input }], autoDisplay: [{ type: Input }], autoZIndex: [{ type: Input }], baseZIndex: [{ type: Input }], mobileActive: [{ type: Input }], popup: [{ type: Input }], parentActive: [{ type: Input }], leafClick: [{ type: Output }], keydownItem: [{ type: Output }] } }); class TieredMenu { constructor(el, renderer, cd) { this.el = el; this.renderer = renderer; this.cd = cd; this.autoZIndex = true; this.baseZIndex = 0; this.showTransitionOptions = '.12s cubic-bezier(0, 0, 0.2, 1)'; this.hideTransitionOptions = '.1s linear'; } toggle(event) { if (this.visible) this.hide(); else this.show(event); this.preventDocumentDefault = true; } show(event) { this.target = event.currentTarget; this.visible = true; this.parentActive = true; this.preventDocumentDefault = true; this.cd.markForCheck(); } onOverlayAnimationStart(event) { switch (event.toState) { case 'visible': if (this.popup) { this.container = event.element; this.moveOnTop(); this.appendOverlay(); DomHandler.absolutePosition(this.container, this.target); this.bindDocumentClickListener(); this.bindDocumentResizeListener(); this.bindScrollListener(); } break; case 'void': this.onOverlayHide(); break; } } appendOverlay() { if (this.appendTo) { if (this.appendTo === 'body') document.body.appendChild(this.container); else DomHandler.appendChild(this.container, this.appendTo); } } restoreOverlayAppend() { if (this.container && this.appendTo) { this.el.nativeElement.appendChild(this.container); } } moveOnTop() { if (this.autoZIndex) { this.container.style.zIndex = String(this.baseZIndex + (++DomHandler.zindex)); } } hide() { this.visible = false; this.parentActive = false; this.cd.markForCheck(); } onWindowResize() { this.hide(); } onLeafClick() { if (this.popup) { this.hide(); } this.unbindDocumentClickListener(); } bindDocumentClickListener() { if (!this.documentClickListener) { const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document'; this.documentClickListener = this.renderer.listen(documentTarget, 'click', () => { if (!this.preventDocumentDefault && this.popup) { this.hide(); } this.preventDocumentDefault = false; }); } } unbindDocumentClickListener() { if (this.documentClickListener) { this.documentClickListener(); this.documentClickListener = null; } } bindDocumentResizeListener() { this.documentResizeListener = this.onWindowResize.bind(this); window.addEventListener('resize', this.documentResizeListener); } unbindDocumentResizeListener() { if (this.documentResizeListener) { window.removeEventListener('resize', this.documentResizeListener); this.documentResizeListener = null; } } bindScrollListener() { if (!this.scrollHandler) { this.scrollHandler = new ConnectedOverlayScrollHandler(this.target, () => { if (this.visible) { this.hide(); } }); } this.scrollHandler.bindScrollListener(); } unbindScrollListener() { if (this.scrollHandler) { this.scrollHandler.unbindScrollListener(); } } onOverlayHide() { this.unbindDocumentClickListener(); this.unbindDocumentResizeListener(); this.unbindScrollListener(); this.preventDocumentDefault = false; this.target = null; } ngOnDestroy() { if (this.popup) { if (this.scrollHandler) { this.scrollHandler.destroy(); this.scrollHandler = null; } this.restoreOverlayAppend(); this.onOverlayHide(); } } } TieredMenu.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: TieredMenu, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); TieredMenu.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.4", type: TieredMenu, selector: "p-tieredMenu", inputs: { model: "model", popup: "popup", style: "style", styleClass: "styleClass", appendTo: "appendTo", autoZIndex: "autoZIndex", baseZIndex: "baseZIndex", autoDisplay: "autoDisplay", showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions" }, ngImport: i0, template: ` <div [ngClass]="{'p-tieredmenu p-component':true, 'p-tieredmenu-overlay':popup}" [class]="styleClass" [ngStyle]="style" [@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" [@.disabled]="popup !== true" (@overlayAnimation.start)="onOverlayAnimationStart($event)" (click)="preventDocumentDefault=true" *ngIf="!popup || visible"> <p-tieredMenuSub [item]="model" root="root" [parentActive]="parentActive" [baseZIndex]="baseZIndex" [autoZIndex]="autoZIndex" (leafClick)="onLeafClick()" [autoDisplay]="autoDisplay" [popup]="popup"></p-tieredMenuSub> </div> `, isInline: true, styles: [".p-tieredmenu-overlay{position:absolute}.p-tieredmenu ul{margin:0;padding:0;list-style:none}.p-tieredmenu .p-submenu-list{position:absolute;min-width:100%;z-index:1;display:none}.p-tieredmenu .p-menuitem-link{cursor:pointer;display:flex;align-items:center;text-decoration:none;overflow:hidden;position:relative}.p-tieredmenu .p-menuitem-text{line-height:1}.p-tieredmenu .p-menuitem{position:relative}.p-tieredmenu .p-menuitem-link .p-submenu-icon{margin-left:auto}.p-tieredmenu .p-menuitem-active>p-tieredmenusub>.p-submenu-list{display:block;left:100%;top:0}"], components: [{ type: TieredMenuSub, selector: "p-tieredMenuSub", inputs: ["item", "root", "autoDisplay", "autoZIndex", "baseZIndex", "mobileActive", "popup", "parentActive"], outputs: ["leafClick", "keydownItem"] }], directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], animations: [ trigger('overlayAnimation', [ transition(':enter', [ style({ opacity: 0, transform: 'scaleY(0.8)' }), animate('{{showTransitionParams}}') ]), transition(':leave', [ animate('{{hideTransitionParams}}', style({ opacity: 0 })) ]) ]) ], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: TieredMenu, decorators: [{ type: Component, args: [{ selector: 'p-tieredMenu', template: ` <div [ngClass]="{'p-tieredmenu p-component':true, 'p-tieredmenu-overlay':popup}" [class]="styleClass" [ngStyle]="style" [@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" [@.disabled]="popup !== true" (@overlayAnimation.start)="onOverlayAnimationStart($event)" (click)="preventDocumentDefault=true" *ngIf="!popup || visible"> <p-tieredMenuSub [item]="model" root="root" [parentActive]="parentActive" [baseZIndex]="baseZIndex" [autoZIndex]="autoZIndex" (leafClick)="onLeafClick()" [autoDisplay]="autoDisplay" [popup]="popup"></p-tieredMenuSub> </div> `, animations: [ trigger('overlayAnimation', [ transition(':enter', [ style({ opacity: 0, transform: 'scaleY(0.8)' }), animate('{{showTransitionParams}}') ]), transition(':leave', [ animate('{{hideTransitionParams}}', style({ opacity: 0 })) ]) ]) ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, styleUrls: ['./tieredmenu.css'] }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { model: [{ type: Input }], popup: [{ type: Input }], style: [{ type: Input }], styleClass: [{ type: Input }], appendTo: [{ type: Input }], autoZIndex: [{ type: Input }], baseZIndex: [{ type: Input }], autoDisplay: [{ type: Input }], showTransitionOptions: [{ type: Input }], hideTransitionOptions: [{ type: Input }] } }); class TieredMenuModule { } TieredMenuModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: TieredMenuModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); TieredMenuModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: TieredMenuModule, declarations: [TieredMenu, TieredMenuSub], imports: [CommonModule, RouterModule, RippleModule], exports: [TieredMenu, RouterModule] }); TieredMenuModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: TieredMenuModule, imports: [[CommonModule, RouterModule, RippleModule], RouterModule] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: TieredMenuModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, RouterModule, RippleModule], exports: [TieredMenu, RouterModule], declarations: [TieredMenu, TieredMenuSub] }] }] }); /** * Generated bundle index. Do not edit. */ export { TieredMenu, TieredMenuModule, TieredMenuSub }; //# sourceMappingURL=primeng-tieredmenu.js.map