UNPKG

ngx-mat-menu

Version:

⚡ Try it on [StackBlitz](https://stackblitz.com/edit/angular-lnjubx)!

401 lines (392 loc) 23.3 kB
import { __decorate } from 'tslib'; import { ɵɵdefineInjectable, Injectable, EventEmitter, Input, Output, HostListener, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { Subject } from 'rxjs'; import { Router } from '@angular/router'; import { trigger, transition, style, animate } from '@angular/animations'; import { CommonModule } from '@angular/common'; import { FlexLayoutModule } from '@angular/flex-layout'; import { MatButtonModule } from '@angular/material/button'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatIconModule } from '@angular/material/icon'; import { BrowserModule } from '@angular/platform-browser'; import { MatBadgeModule } from '@angular/material/badge'; import { MatExpansionModule } from '@angular/material/expansion'; import { MatSelectModule } from '@angular/material/select'; import { FormsModule } from '@angular/forms'; let NgxMatMenuService = class NgxMatMenuService { constructor() { this.changeMenuSelect = new Subject(); this.changeShowMenu = new Subject(); } selectMenu(selected) { this.selectedMenu = selected; this.changeMenuSelect.next(this.selectedMenu); } getSelectedMenu() { return this.selectedMenu; } changeMenu(show) { this.showMenu = show; this.changeShowMenu.next(this.showMenu); } }; NgxMatMenuService.ɵprov = ɵɵdefineInjectable({ factory: function NgxMatMenuService_Factory() { return new NgxMatMenuService(); }, token: NgxMatMenuService, providedIn: "root" }); NgxMatMenuService = __decorate([ Injectable({ providedIn: 'root' }) ], NgxMatMenuService); let NgxMatMenuComponent = class NgxMatMenuComponent { constructor(menuService, router) { this.menuService = menuService; this.router = router; this.showMenu = false; this.widthSidebar = '0px'; this.posSidebar = 'relative'; this.showHeader = true; this.hover = false; this.themeSidebarHeader = { background: 'white', color: '' }; this.openNotif = new EventEmitter(); this.logoutEvent = new EventEmitter(); this.profileClick = new EventEmitter(); this.selectItem = new EventEmitter(); this.activeMenu = this.menuService.getSelectedMenu(); // Sidebar selection change this.menuService.changeMenuSelect.subscribe(data => { this.activeMenu = data; }); // Header,sidebar show/hide this.menuService.changeShowMenu.subscribe(data => { this.show = data; }); } ngOnInit() { this.checkSidebarPos(); } ngOnChanges() { console.log(this.lang); switch (this.lang) { case 'en': this.textLogout = 'Logout'; break; case 'hu': this.textLogout = 'Kijelentkezés'; break; default: this.textLogout = 'Logout'; break; } } onResize() { this.checkSidebarPos(); } checkSidebarPos() { const width = document.getElementById('cont').offsetWidth; if (width <= 700) { this.posSidebar = 'absolute'; } else { this.posSidebar = 'relative'; } } setMenu(event) { if (event !== undefined) { if (event === true) { this.widthSidebar = this.defaultWidth ? this.defaultWidth : '200px'; this.showMenu = !this.showMenu; } else { setTimeout(() => { this.showMenu = !this.showMenu; }, 200); this.widthSidebar = '0px'; } } else { if (this.showMenu) { this.widthSidebar = '0px'; setTimeout(() => { this.showMenu = !this.showMenu; }, 200); } else { this.widthSidebar = this.defaultWidth ? this.defaultWidth : '200px'; setTimeout(() => { this.showMenu = !this.showMenu; }, 200); } } } /** * Expandable menu item height change * @param id Id of item and expandable element */ expandMenu(id) { console.log(document.getElementById(id.toString()).offsetHeight); if (document.getElementById(id.toString()).offsetHeight === 0) { document.getElementById(id.toString()).style.height = 'auto'; document.getElementById(id.toString()).style.display = 'block'; } else { document.getElementById(id.toString()).style.height = '0px'; document.getElementById(id.toString()).style.display = 'none'; } } msSelect_SelectionChange(value) { this.selectItem.emit(value); } // Output: showNotif(event) { this.openNotif.emit(event); } selectMenu(selected, route) { console.log(route); if (route) { this.menuService.selectMenu(selected); this.router.navigate([`${route}`]); } } profile_Click(event) { this.profileClick.emit(event); } logout() { this.setMenu(false); this.logoutEvent.next(); } hovered() { if (this.hover == true) { return this.badgeColor; } } }; NgxMatMenuComponent.ctorParameters = () => [ { type: NgxMatMenuService }, { type: Router } ]; __decorate([ Input() ], NgxMatMenuComponent.prototype, "themeSidebar", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "themeHeader", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "themeSidebarHeader", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "arrMenuOptions", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "logoutIcon", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "badgeColor", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "srcLogo", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "heightLogo", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "widthLogo", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "lang", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "visibleNotif", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "badge", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "defaultWidth", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "borderHeader", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "borderSidebar", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "borderSidebarHeader", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "borderSidebarFooter", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "borderMenuItems", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "headerPicture", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "headerTitle", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "headerTitleColor", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "headerSubtitle", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "headerSubtitleColor", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "selectPlaceholder", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "arrSelectItems", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "defaultSelectValue", void 0); __decorate([ Input() ], NgxMatMenuComponent.prototype, "showSelectValue", void 0); __decorate([ Output() ], NgxMatMenuComponent.prototype, "openNotif", void 0); __decorate([ Output() ], NgxMatMenuComponent.prototype, "logoutEvent", void 0); __decorate([ Output() ], NgxMatMenuComponent.prototype, "profileClick", void 0); __decorate([ Output() ], NgxMatMenuComponent.prototype, "selectItem", void 0); __decorate([ HostListener('window:resize', ['']) ], NgxMatMenuComponent.prototype, "onResize", null); NgxMatMenuComponent = __decorate([ Component({ selector: 'ngx-mat-menu', template: "<div id=\"cont\" style=\"height: 100%;width: 100%;\" fxLayout=\"row\" fxLayoutAlign=\"space-between stretch\">\r\n <!-- SIDEBAR -->\r\n <div style=\"overflow-x: hidden; max-width: 90vw; box-shadow: 0px 0px 10px #777777;\" [style.width]=\"widthSidebar\"\r\n [style.position]=\"posSidebar\" [ngStyle]=\"themeSidebar\" fxLayout=\"column\" fxLayoutAlign=\"start start\"\r\n class=\"app-sidebar\" *ngIf=\"show\" [style.border]=\"borderSidebar\">\r\n\r\n <!-- SIDEBAR HEADER -->\r\n <div class=\"app-sidebar-header\" [style.border-bottom]=\"borderSidebarHeader\" [ngStyle]=\"themeSidebarHeader\">\r\n <!-- \r\n <div fxLayout=\"row\" fxLayoutAlign=\"center center\">\r\n <mat-icon style=\"margin-right: 10px;\" *ngIf=\"headerIcon\">{{headerIcon}}</mat-icon> {{headerText}}\r\n </div>\r\n -->\r\n <div fxLayout=\"column\" fxLayoutAlign=\"start stretch\" style=\"height: 100%;\">\r\n <div fxFlex *ngIf=\"headerPicture\" fxLayout=\"row\" fxLayoutAlign=\"start center\">\r\n <div [ngStyle]=\"{ 'background-image': 'url(' + headerPicture + ')'}\" class=\"app-header-picture\"\r\n (click)=\"profile_Click($event)\">\r\n </div>\r\n </div>\r\n <div fxFlex fxLayout=\"column\" fxLayoutAlign=\"center start\">\r\n <span class=\"app-header-title\" [style.color]=\"headerTitleColor\">{{headerTitle}}</span>\r\n <span class=\"app-header-subtitle\" [style.color]=\"headerSubtitleColor\">{{headerSubtitle}}</span>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n\r\n <div *ngIf=\"arrSelectItems\" fxLayout=\"column\" fxLayoutAlign=\"start start\" style=\"width: 100%; background: white; height: 70px;\">\r\n <mat-form-field style=\"height: 45px;\r\n width: calc(100% - 40px);\r\n margin-left: 15px; \r\n margin-right: 15px;\" >\r\n <mat-select \r\n (selectionChange)=\"msSelect_SelectionChange($event.value)\"\r\n [placeholder]=\"selectPlaceholder\" [(ngModel)]=\"defaultSelectValue\" name=\"item\">\r\n <mat-option *ngFor=\"let item of arrSelectItems\" [value]=\"item.value\">\r\n {{item.title}} <span *ngIf=\"showSelectValue\"> - {{item.value}}</span>\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n \r\n </div>\r\n\r\n\r\n <!-- SIDEBAR LIST -->\r\n <div fxFlex fxLayout=\"column\" fxLayoutAlign=\"start start\"\r\n class=\"app-sidebar-body\"\r\n >\r\n\r\n <div *ngFor=\"let item of arrMenuOptions\" [style.border-top]=\"borderMenuItems\" style=\"width: 100%;\"\r\n fxLayout=\"column\" fxLayoutAlign=\"start stretch\">\r\n\r\n\r\n <!-- EXPENDABLE ITEM -->\r\n <mat-expansion-panel #meph *ngIf=\"item.children && !item.divider\" [ngStyle]=\"themeSidebar\"\r\n class=\"expandable-item\" hideToggle=\"true\" style=\"width: 100%;padding: 0px\">\r\n\r\n <!-- BASE ITEM -->\r\n <mat-expansion-panel-header class=\"app-sidebar-item\" style=\"padding-left: 0px;\"\r\n (click)=\"selectMenu(item.id,item.route)\" libColor>\r\n <div style=\"width: 100%; height: 45px;\" fxLayout=\"row\" fxLayoutAlign=\"space-between center\"\r\n [ngClass]=\"{'material-selected-menu': activeMenu === item.id}\">\r\n <div fxLayout=\"row\" fxLayoutAlign=\"start center\">\r\n <div style=\"width: 50px;\" fxLayout=\"row\" fxLayoutAlign=\"center center\"\r\n *ngIf=\"item.icon\">\r\n <mat-icon *ngIf=\"item.icon\">{{item.icon}}</mat-icon>\r\n </div>\r\n <div fxFlex fxLayout=\"row\" fxLayoutAlign=\"start center\" style=\"margin-left: 10px;\">\r\n {{item.title}}\r\n </div>\r\n </div>\r\n <div>\r\n <mat-icon style=\"margin: 10px;\" *ngIf=\"meph.expanded\">expand_less</mat-icon>\r\n <mat-icon style=\"margin: 10px;\" *ngIf=\"!meph.expanded\">expand_more</mat-icon>\r\n\r\n </div>\r\n </div>\r\n\r\n </mat-expansion-panel-header>\r\n\r\n\r\n\r\n\r\n <!-- SUB ITEMS -->\r\n <div fxFlex style=\"width: 100%;\" [id]=\"item.id\" class=\"sub-item-list\">\r\n\r\n <div class=\"app-sidebar-item\" *ngFor=\"let sub of item.children\" style=\"width: 100%;\"\r\n fxLayout=\"column\" fxLayoutAlign=\"start stretch\"\r\n [ngClass]=\"{'material-selected-menu': activeMenu === sub.id}\"\r\n (click)=\"selectMenu(sub.id,sub.route)\" libColor>\r\n\r\n <!-- DIVIDER IF NEEDED .. TODO: HEIGHT!\r\n <div *ngIf=\"sub.divider\" style=\"width: 100%;\r\n border-bottom: 0.5px solid lightgray;\">\r\n </div> -->\r\n\r\n <div class=\"app-sidebar-item\" fxLayout=\"row\" fxLayoutAlign=\"start stretch\"\r\n style=\"width: 100%;\">\r\n <div style=\"width: 50px;\" fxLayout=\"row\" fxLayoutAlign=\"center center\" *ngIf=\"sub.icon\">\r\n <mat-icon *ngIf=\"sub.icon\">{{sub.icon}}</mat-icon>\r\n </div>\r\n <div fxFlex fxLayout=\"row\" fxLayoutAlign=\"start center\" style=\"margin-left: 10px;\">\r\n {{sub.title}}\r\n </div>\r\n </div>\r\n </div>\r\n\r\n </div>\r\n </mat-expansion-panel>\r\n\r\n <!-- DIVIDER IF NEEDED .. TODO: SET COLOR -->\r\n <div *ngIf=\"item.divider\" style=\"width: 100%;\r\n border-bottom: 0.5px solid lightgray;\">\r\n\r\n </div>\r\n\r\n\r\n\r\n\r\n <!-- SIMPLE MENU ITEMS -->\r\n <div class=\"app-sidebar-item\" *ngIf=\"!item.children && !item.divider\" fxLayout=\"row\"\r\n fxLayoutAlign=\"start stretch\" [ngClass]=\"{'material-selected-menu': activeMenu === item.id}\"\r\n (click)=\"selectMenu(item.id,item.route)\" libColor>\r\n <div style=\"width: 50px;\" fxLayout=\"row\" fxLayoutAlign=\"center center\" *ngIf=\"item.icon\">\r\n <mat-icon *ngIf=\"item.icon\">{{item.icon}}</mat-icon>\r\n </div>\r\n <div fxFlex fxLayout=\"row\" fxLayoutAlign=\"start center\" style=\"margin-left: 10px;\">\r\n {{item.title}}\r\n </div>\r\n </div>\r\n\r\n\r\n </div>\r\n\r\n </div>\r\n\r\n <!-- SIDEBAR FOOTER -->\r\n <div class=\"app-sidebar-footer\" style=\"overflow-x: hidden;\" [style.border-top]=\"borderSidebarFooter\"\r\n fxLayout=\"row\" fxLayoutAlign=\"center center\">\r\n <button mat-button (click)=\"logout()\">\r\n <mat-icon style=\"margin-right: 10px;\" *ngIf=\"logoutIcon\">{{logoutIcon}}</mat-icon>{{textLogout}}\r\n </button>\r\n </div>\r\n </div>\r\n\r\n <!-- HEADER -->\r\n <div style=\"height: 100%;width:100%; min-width: 0px !important;\" fxLayout=\"column\"\r\n fxLayoutAlign=\"space-between stretch\">\r\n <div *ngIf=\"show\" class=\"app-header\">\r\n <ngx-mat-menu-header [theme]=\"themeHeader\" [visibleNotif]=\"visibleNotif\" [srcLogo]=\"srcLogo\"\r\n [widthLogo]=\"widthLogo\" [heightLogo]=\"heightLogo\" (showMenu)=\"setMenu($event)\"\r\n (showNotif)=\"showNotif($event)\" [badge]=\"badge\" [borderHeader]=\"borderHeader\"></ngx-mat-menu-header>\r\n </div>\r\n <div fxFlex (swipeleft)=\"showMenu ? setMenu(false) : ''\" (swiperight)=\"show === true ? setMenu(true) : null\"\r\n style=\"height: 100%; width: 100%;\">\r\n <ng-content></ng-content>\r\n </div>\r\n </div>\r\n\r\n <div class=\"app-small-blur\" style=\"height: 100%;width: 100%; position: absolute;\"\r\n *ngIf=\"showMenu && showHeader && posSidebar === 'absolute'\" (click)=\"setMenu(false)\"\r\n (swipeleft)=\"setMenu(false)\">\r\n </div>\r\n</div>", animations: [ trigger('enterAnimation', [ transition(':enter', [ style({ transform: 'translateX(100%)', opacity: 0 }), animate('250ms', style({ transform: 'translateX(0)', opacity: 1 })) ]), transition(':leave', [ style({ transform: 'translateX(0)', opacity: 1 }), animate('250ms', style({ transform: 'translateX(100%)', opacity: 0 })) ]) ]) ], styles: [".app-sidebar{-webkit-transition:.4s;transition:.4s;overflow:auto;margin:0!important;height:100%;background:#fff;z-index:900}.app-sidebar-header{height:150px;width:100%;white-space:nowrap;display:block;overflow:hidden;-webkit-transition:.5s ease-in-out;transition:.5s ease-in-out}.app-sidebar-body{white-space:nowrap;display:block;overflow:hidden;-webkit-transition:.5s ease-in-out;transition:.5s ease-in-out;width:100%}.app-sidebar-footer{height:60px;width:100%}.app-sidebar-item{height:45px;width:calc(100% - 10px);margin:5px;cursor:pointer}.app-sidebar-item:hover{font-weight:500}.app-small-blur{z-index:800;background-color:#000;opacity:.4}.app-header{-webkit-transition:.5s;transition:.5s;height:60px;background:#fff}.material-selected-menu{border-radius:5px;background-color:rgba(138,138,138,.4)}.app-header-picture{width:50px;height:50px;border-radius:100%;background-size:cover;margin-left:15px;cursor:pointer}.app-header-title{margin-left:15px;font-size:large;font-weight:500}.app-header-subtitle{margin-left:15px;margin-top:5px;font-size:medium}.expandable-item{border:0 solid transparent;background:0 0;box-shadow:none;border-radius:0!important}.sub-item-list{-webkit-transition:.4s;transition:.4s}.mat-expansion-panel-header{padding:0!important;height:60px}"] }) ], NgxMatMenuComponent); let HeaderComponent = class HeaderComponent { constructor() { this.showMenu = new EventEmitter(); this.showNotif = new EventEmitter(); } ngOnInit() { } ngOnChanges() { this.heightLogo = this.heightLogo ? this.heightLogo : 'auto'; this.widthLogo = this.widthLogo ? this.widthLogo : 'auto'; } btnShowMenu_Click() { this.showMenu.emit(); } btnShowNotif_Click() { this.showNotif.emit(); } }; __decorate([ Input() ], HeaderComponent.prototype, "theme", void 0); __decorate([ Input() ], HeaderComponent.prototype, "visibleNotif", void 0); __decorate([ Input() ], HeaderComponent.prototype, "srcLogo", void 0); __decorate([ Input() ], HeaderComponent.prototype, "heightLogo", void 0); __decorate([ Input() ], HeaderComponent.prototype, "widthLogo", void 0); __decorate([ Input() ], HeaderComponent.prototype, "badge", void 0); __decorate([ Input() ], HeaderComponent.prototype, "borderHeader", void 0); __decorate([ Output() ], HeaderComponent.prototype, "showMenu", void 0); __decorate([ Output() ], HeaderComponent.prototype, "showNotif", void 0); HeaderComponent = __decorate([ Component({ selector: 'ngx-mat-menu-header', template: "<div \r\nstyle=\"height: 100%;\" \r\n[ngStyle]=\"theme\"\r\n[style.border]=\"borderHeader\"\r\nfxLayout=\"row\" fxLayoutAlign=\"space-between center\">\r\n <div>\r\n <button mat-icon-button (click)=\"btnShowMenu_Click()\">\r\n <mat-icon>menu</mat-icon>\r\n </button>\r\n </div>\r\n <div>\r\n <img [src]=\"srcLogo\" [ngStyle]=\"{'height': heightLogo, 'width': widthLogo}\" style=\"height: 60px; \">\r\n </div>\r\n <div>\r\n <button mat-icon-button *ngIf=\"visibleNotif\">\r\n <mat-icon (click)=\"btnShowNotif_Click()\" [matBadge]=\"badge\" matBadgeColor=\"warn\" matBadgePosition=\"before\" [matBadgeHidden]=\"badge == 0\">notifications_none</mat-icon>\r\n </button>\r\n </div>\r\n</div>", styles: [""] }) ], HeaderComponent); let ColorDirective = class ColorDirective { constructor(elementRef, menucomp) { this.elementRef = elementRef; this.menucomp = menucomp; } onMouseEnter() { this.highlight(this.menucomp.badgeColor); } onMouseLeave() { this.highlight(null); } highlight(color) { this.elementRef.nativeElement.style.color = color; } }; ColorDirective.ctorParameters = () => [ { type: ElementRef }, { type: NgxMatMenuComponent } ]; __decorate([ HostListener('mouseenter') ], ColorDirective.prototype, "onMouseEnter", null); __decorate([ HostListener('mouseleave') ], ColorDirective.prototype, "onMouseLeave", null); ColorDirective = __decorate([ Directive({ selector: '[libColor]' }) ], ColorDirective); let NgxMatMenuModule = class NgxMatMenuModule { }; NgxMatMenuModule = __decorate([ NgModule({ declarations: [NgxMatMenuComponent, HeaderComponent, ColorDirective], imports: [ FlexLayoutModule, MatButtonModule, MatIconModule, MatFormFieldModule, CommonModule, BrowserModule, MatBadgeModule, MatExpansionModule, MatSelectModule, FormsModule ], exports: [NgxMatMenuComponent] }) ], NgxMatMenuModule); /* * Public API Surface of ngx-mat-menu */ /** * Generated bundle index. Do not edit. */ export { NgxMatMenuComponent, NgxMatMenuModule, NgxMatMenuService, HeaderComponent as ɵa, ColorDirective as ɵb }; //# sourceMappingURL=ngx-mat-menu.js.map