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

412 lines (408 loc) 24.1 kB
import * as i0 from '@angular/core'; import { forwardRef, Component, ViewEncapsulation, Inject, Input, EventEmitter, ChangeDetectionStrategy, Output, ViewChild, NgModule } from '@angular/core'; import { trigger, transition, style, animate } from '@angular/animations'; import * as i1 from '@angular/common'; import { CommonModule } from '@angular/common'; import { DomHandler, ConnectedOverlayScrollHandler } from 'primeng/dom'; import * as i2 from '@angular/router'; import { RouterModule } from '@angular/router'; class SlideMenuSub { constructor(slideMenu) { this.backLabel = 'Back'; this.easing = 'ease-out'; this.slideMenu = slideMenu; } itemClick(event, item, listitem) { if (item.disabled) { event.preventDefault(); return; } if (!item.url) { event.preventDefault(); } if (item.command) { item.command({ originalEvent: event, item: item }); } if (item.items && !this.slideMenu.animating) { this.slideMenu.left -= this.slideMenu.menuWidth; this.activeItem = listitem; this.slideMenu.animating = true; setTimeout(() => this.slideMenu.animating = false, this.effectDuration); } if (!item.items && this.slideMenu.popup) { this.slideMenu.hide(); } } ngOnDestroy() { this.activeItem = null; } } SlideMenuSub.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: SlideMenuSub, deps: [{ token: forwardRef(() => SlideMenu) }], target: i0.ɵɵFactoryTarget.Component }); SlideMenuSub.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.4", type: SlideMenuSub, selector: "p-slideMenuSub", inputs: { item: "item", root: "root", backLabel: "backLabel", menuWidth: "menuWidth", effectDuration: "effectDuration", easing: "easing", index: "index" }, ngImport: i0, template: ` <ul [ngClass]="{'p-slidemenu-rootlist':root, 'p-submenu-list':!root, 'p-active-submenu': (-slideMenu.left == (index * menuWidth))}" [style.width.px]="menuWidth" [style.left.px]="root ? slideMenu.left : slideMenu.menuWidth" [style.transitionProperty]="root ? 'left' : 'none'" [style.transitionDuration]="effectDuration + 'ms'" [style.transitionTimingFunction]="easing"> <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':listitem==activeItem,'p-hidden': child.visible === false}" [class]="child.styleClass" [ngStyle]="child.style"> <a *ngIf="!child.routerLink" [attr.href]="child.url" class="p-menuitem-link" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [ngClass]="{'p-disabled':child.disabled}" [attr.tabindex]="child.disabled ? null : '0'" (click)="itemClick($event, child, listitem)"> <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span> <span class="p-menuitem-text">{{child.label}}</span> <span class="p-submenu-icon pi pi-fw pi-angle-right" *ngIf="child.items"></span> </a> <a *ngIf="child.routerLink" [routerLink]="child.routerLink" [queryParams]="child.queryParams" [routerLinkActive]="'p-menuitem-link-active'" [routerLinkActiveOptions]="child.routerLinkActiveOptions||{exact:false}" [href]="child.url" class="p-menuitem-link" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [attr.tabindex]="child.disabled ? null : '0'" [ngClass]="{'p-disabled':child.disabled}" (click)="itemClick($event, child, listitem)" [fragment]="child.fragment" [queryParamsHandling]="child.queryParamsHandling" [preserveFragment]="child.preserveFragment" [skipLocationChange]="child.skipLocationChange" [replaceUrl]="child.replaceUrl" [state]="child.state"> <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span> <span class="p-menuitem-text">{{child.label}}</span> <span class="p-submenu-icon pi pi-fw pi-caret-right" *ngIf="child.items"></span> </a> <p-slideMenuSub class="p-submenu" [item]="child" [index]="index + 1" [menuWidth]="menuWidth" *ngIf="child.items"></p-slideMenuSub> </li> </ng-template> </ul> `, isInline: true, components: [{ type: SlideMenuSub, selector: "p-slideMenuSub", inputs: ["item", "root", "backLabel", "menuWidth", "effectDuration", "easing", "index"] }], 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.RouterLinkWithHref, selector: "a[routerLink],area[routerLink]", inputs: ["routerLink", "target", "queryParams", "fragment", "queryParamsHandling", "preserveFragment", "skipLocationChange", "replaceUrl", "state", "relativeTo"] }, { type: i2.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: SlideMenuSub, decorators: [{ type: Component, args: [{ selector: 'p-slideMenuSub', template: ` <ul [ngClass]="{'p-slidemenu-rootlist':root, 'p-submenu-list':!root, 'p-active-submenu': (-slideMenu.left == (index * menuWidth))}" [style.width.px]="menuWidth" [style.left.px]="root ? slideMenu.left : slideMenu.menuWidth" [style.transitionProperty]="root ? 'left' : 'none'" [style.transitionDuration]="effectDuration + 'ms'" [style.transitionTimingFunction]="easing"> <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':listitem==activeItem,'p-hidden': child.visible === false}" [class]="child.styleClass" [ngStyle]="child.style"> <a *ngIf="!child.routerLink" [attr.href]="child.url" class="p-menuitem-link" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [ngClass]="{'p-disabled':child.disabled}" [attr.tabindex]="child.disabled ? null : '0'" (click)="itemClick($event, child, listitem)"> <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span> <span class="p-menuitem-text">{{child.label}}</span> <span class="p-submenu-icon pi pi-fw pi-angle-right" *ngIf="child.items"></span> </a> <a *ngIf="child.routerLink" [routerLink]="child.routerLink" [queryParams]="child.queryParams" [routerLinkActive]="'p-menuitem-link-active'" [routerLinkActiveOptions]="child.routerLinkActiveOptions||{exact:false}" [href]="child.url" class="p-menuitem-link" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [attr.tabindex]="child.disabled ? null : '0'" [ngClass]="{'p-disabled':child.disabled}" (click)="itemClick($event, child, listitem)" [fragment]="child.fragment" [queryParamsHandling]="child.queryParamsHandling" [preserveFragment]="child.preserveFragment" [skipLocationChange]="child.skipLocationChange" [replaceUrl]="child.replaceUrl" [state]="child.state"> <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span> <span class="p-menuitem-text">{{child.label}}</span> <span class="p-submenu-icon pi pi-fw pi-caret-right" *ngIf="child.items"></span> </a> <p-slideMenuSub class="p-submenu" [item]="child" [index]="index + 1" [menuWidth]="menuWidth" *ngIf="child.items"></p-slideMenuSub> </li> </ng-template> </ul> `, encapsulation: ViewEncapsulation.None }] }], ctorParameters: function () { return [{ type: undefined, decorators: [{ type: Inject, args: [forwardRef(() => SlideMenu)] }] }]; }, propDecorators: { item: [{ type: Input }], root: [{ type: Input }], backLabel: [{ type: Input }], menuWidth: [{ type: Input }], effectDuration: [{ type: Input }], easing: [{ type: Input }], index: [{ type: Input }] } }); class SlideMenu { constructor(el, renderer, cd) { this.el = el; this.renderer = renderer; this.cd = cd; this.menuWidth = 190; this.viewportHeight = 180; this.effectDuration = 250; this.easing = 'ease-out'; this.backLabel = 'Back'; this.autoZIndex = true; this.baseZIndex = 0; this.showTransitionOptions = '.12s cubic-bezier(0, 0, 0.2, 1)'; this.hideTransitionOptions = '.1s linear'; this.onShow = new EventEmitter(); this.onHide = new EventEmitter(); this.left = 0; this.animating = false; } ngAfterViewChecked() { if (!this.viewportUpdated && !this.popup && this.containerViewChild) { this.updateViewPort(); this.viewportUpdated = true; } } set container(element) { this.containerViewChild = element; } set backward(element) { this.backwardViewChild = element; } set slideMenuContent(element) { this.slideMenuContentViewChild = element; } updateViewPort() { this.slideMenuContentViewChild.nativeElement.style.height = this.viewportHeight - DomHandler.getHiddenElementOuterHeight(this.backwardViewChild.nativeElement) + 'px'; } toggle(event) { if (this.visible) this.hide(); else this.show(event); this.preventDocumentDefault = true; } show(event) { this.target = event.currentTarget; this.visible = true; this.preventDocumentDefault = true; this.cd.markForCheck(); } onOverlayAnimationStart(event) { switch (event.toState) { case 'visible': if (this.popup) { this.updateViewPort(); this.moveOnTop(); this.onShow.emit({}); this.appendOverlay(); DomHandler.absolutePosition(this.containerViewChild.nativeElement, this.target); this.bindDocumentClickListener(); this.bindDocumentResizeListener(); this.bindScrollListener(); } break; case 'void': this.onOverlayHide(); this.onHide.emit({}); break; } } appendOverlay() { if (this.appendTo) { if (this.appendTo === 'body') document.body.appendChild(this.containerViewChild.nativeElement); else DomHandler.appendChild(this.containerViewChild.nativeElement, this.appendTo); } } restoreOverlayAppend() { if (this.container && this.appendTo) { this.el.nativeElement.appendChild(this.containerViewChild.nativeElement); } } moveOnTop() { if (this.autoZIndex) { this.containerViewChild.nativeElement.style.zIndex = String(this.baseZIndex + (++DomHandler.zindex)); } } hide() { this.visible = false; this.cd.markForCheck(); } onWindowResize() { this.hide(); } onClick(event) { this.preventDocumentDefault = true; } goBack() { this.left += this.menuWidth; } bindDocumentClickListener() { if (!this.documentClickListener) { const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document'; this.documentClickListener = this.renderer.listen(documentTarget, 'click', () => { if (!this.preventDocumentDefault) { this.hide(); this.cd.detectChanges(); } 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; this.left = 0; } ngOnDestroy() { if (this.popup) { if (this.scrollHandler) { this.scrollHandler.destroy(); this.scrollHandler = null; } this.restoreOverlayAppend(); this.onOverlayHide(); } } } SlideMenu.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: SlideMenu, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); SlideMenu.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.4", type: SlideMenu, selector: "p-slideMenu", inputs: { model: "model", popup: "popup", style: "style", styleClass: "styleClass", menuWidth: "menuWidth", viewportHeight: "viewportHeight", effectDuration: "effectDuration", easing: "easing", backLabel: "backLabel", appendTo: "appendTo", autoZIndex: "autoZIndex", baseZIndex: "baseZIndex", showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions" }, outputs: { onShow: "onShow", onHide: "onHide" }, viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true }, { propertyName: "backward", first: true, predicate: ["backward"], descendants: true }, { propertyName: "slideMenuContent", first: true, predicate: ["slideMenuContent"], descendants: true }], ngImport: i0, template: ` <div #container [ngClass]="{'p-slidemenu p-component':true, 'p-slidemenu-overlay':popup}" [class]="styleClass" [ngStyle]="style" (click)="onClick($event)" [@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" [@.disabled]="popup !== true" (@overlayAnimation.start)="onOverlayAnimationStart($event)" *ngIf="!popup || visible"> <div class="p-slidemenu-wrapper" [style.height]="left ? viewportHeight + 'px' : 'auto'"> <div #slideMenuContent class="p-slidemenu-content"> <p-slideMenuSub [item]="model" root="root" [index]="0" [menuWidth]="menuWidth" [effectDuration]="effectDuration" [easing]="easing"></p-slideMenuSub> </div> <div #backward class="p-slidemenu-backward" [style.display]="left ? 'block' : 'none'" (click)="goBack()"> <span class="p-slidemenu-backward-icon pi pi-fw pi-caret-left"></span><span>{{backLabel}}</span> </div> </div> </div> `, isInline: true, styles: [".p-slidemenu{width:12.5rem}.p-slidemenu.p-slidemenu-overlay{position:absolute}.p-slidemenu ul{list-style:none;margin:0;padding:0}.p-slidemenu .p-slidemenu-rootlist{position:absolute;top:0}.p-slidemenu .p-submenu-list{display:none;position:absolute;top:0;width:12.5rem}.p-slidemenu .p-menuitem-link{cursor:pointer;display:flex;align-items:center;text-decoration:none;overflow:hidden}.p-slidemenu .p-menuitem-icon,.p-slidemenu .p-menuitem-text{vertical-align:middle}.p-slidemenu .p-menuitem{position:relative}.p-slidemenu .p-menuitem-link .p-submenu-icon{margin-left:auto}.p-slidemenu .p-slidemenu-wrapper{position:relative}.p-slidemenu .p-slidemenu-content{overflow-x:hidden;overflow-y:auto;position:relative}.p-slidemenu-backward{position:absolute;bottom:0;width:100%;cursor:pointer;display:none}.p-slidemenu-backward .p-slidemenu-backward-icon,.p-slidemenu-backward span{vertical-align:middle}.p-slidemenu .p-menuitem-active{position:static}.p-slidemenu .p-menuitem-active>.p-submenu>.p-submenu-list{display:block}.p-slidemenu .p-active-submenu>.p-menuitem-active>.p-submenu>.p-submenu-list,.p-slidemenu ul:not(.p-active-submenu)>.p-menuitem:not(.p-menuitem-active){display:none}.p-slidemenu .p-active-submenu>.p-menuitem-active~.p-menuitem{display:block}"], components: [{ type: SlideMenuSub, selector: "p-slideMenuSub", inputs: ["item", "root", "backLabel", "menuWidth", "effectDuration", "easing", "index"] }], 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: SlideMenu, decorators: [{ type: Component, args: [{ selector: 'p-slideMenu', template: ` <div #container [ngClass]="{'p-slidemenu p-component':true, 'p-slidemenu-overlay':popup}" [class]="styleClass" [ngStyle]="style" (click)="onClick($event)" [@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" [@.disabled]="popup !== true" (@overlayAnimation.start)="onOverlayAnimationStart($event)" *ngIf="!popup || visible"> <div class="p-slidemenu-wrapper" [style.height]="left ? viewportHeight + 'px' : 'auto'"> <div #slideMenuContent class="p-slidemenu-content"> <p-slideMenuSub [item]="model" root="root" [index]="0" [menuWidth]="menuWidth" [effectDuration]="effectDuration" [easing]="easing"></p-slideMenuSub> </div> <div #backward class="p-slidemenu-backward" [style.display]="left ? 'block' : 'none'" (click)="goBack()"> <span class="p-slidemenu-backward-icon pi pi-fw pi-caret-left"></span><span>{{backLabel}}</span> </div> </div> </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: ['./slidemenu.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 }], menuWidth: [{ type: Input }], viewportHeight: [{ type: Input }], effectDuration: [{ type: Input }], easing: [{ type: Input }], backLabel: [{ type: Input }], appendTo: [{ type: Input }], autoZIndex: [{ type: Input }], baseZIndex: [{ type: Input }], showTransitionOptions: [{ type: Input }], hideTransitionOptions: [{ type: Input }], onShow: [{ type: Output }], onHide: [{ type: Output }], container: [{ type: ViewChild, args: ['container'] }], backward: [{ type: ViewChild, args: ['backward'] }], slideMenuContent: [{ type: ViewChild, args: ['slideMenuContent'] }] } }); class SlideMenuModule { } SlideMenuModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: SlideMenuModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); SlideMenuModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: SlideMenuModule, declarations: [SlideMenu, SlideMenuSub], imports: [CommonModule, RouterModule], exports: [SlideMenu, RouterModule] }); SlideMenuModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: SlideMenuModule, imports: [[CommonModule, RouterModule], RouterModule] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: SlideMenuModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, RouterModule], exports: [SlideMenu, RouterModule], declarations: [SlideMenu, SlideMenuSub] }] }] }); /** * Generated bundle index. Do not edit. */ export { SlideMenu, SlideMenuModule, SlideMenuSub }; //# sourceMappingURL=primeng-slidemenu.js.map