ngx-notification-bar
Version:
Angular notification bar component for Angular 2+ projects.
1 lines • 13.6 kB
Source Map (JSON)
{"version":3,"file":"ngx-notification-bar.mjs","sources":["../../../projects/ngx-notification-bar/src/lib/notification-bar.models.ts","../../../projects/ngx-notification-bar/src/lib/notification-bar.service.ts","../../../projects/ngx-notification-bar/src/lib/notification-bar.component.ts","../../../projects/ngx-notification-bar/src/lib/notification-bar.module.ts","../../../projects/ngx-notification-bar/src/public_api.ts","../../../projects/ngx-notification-bar/src/ngx-notification-bar.ts"],"sourcesContent":["export enum NotificationType { Info, Success, Error, Warning }\r\n\r\nexport interface Notification {\r\n message: string;\r\n type?: NotificationType;\r\n typeValue?: string;\r\n autoHide?: boolean;\r\n hideDelay?: number;\r\n isHtml?: boolean;\r\n allowClose?: boolean;\r\n hideOnHover?: boolean;\r\n}\r\n","import { Injectable, EventEmitter } from '@angular/core';\r\n\r\nimport { Notification } from './notification-bar.models';\r\n\r\n/**\r\n * A service to create notification, It can be used from any component or guard\r\n */\r\n@Injectable()\r\nexport class NotificationBarService {\r\n\r\n\r\n onCreate = new EventEmitter<Notification>();\r\n onClose = new EventEmitter<Notification>();\r\n\r\n constructor() {\r\n }\r\n\r\n create(notification: Notification) {\r\n this.onCreate.emit(notification);\r\n }\r\n\r\n close(notification: Notification) {\r\n this.onClose.emit(notification);\r\n }\r\n}\r\n","import { trigger, state, style, transition, animate } from '@angular/animations';\r\nimport {\r\n Component, OnInit, Optional, Inject,\r\n InjectionToken, OnDestroy\r\n} from '@angular/core';\r\n\r\nimport { NotificationBarService } from './notification-bar.service';\r\nimport { Notification, NotificationType } from './notification-bar.models';\r\nimport { MessagesConfig } from './message-config';\r\nimport { Subscription } from 'rxjs';\r\n\r\nexport const MESSAGES_CONFIG = new InjectionToken('notification-bar.messages.config');\r\n\r\n@Component({\r\n selector: 'notification-bar',\r\n styles: [`\r\n :host {\r\n position: relative;\r\n display: block;\r\n }\r\n .notifications-container {\r\n position: fixed;\r\n top: 0px;\r\n right: 0;\r\n left: 0;\r\n line-height: 25px;\r\n width: 100%;\r\n z-index: 6;\r\n overflow: hidden;\r\n }\r\n .notification {\r\n position: relative;\r\n text-align: center;\r\n font-size: 12px;\r\n color: #fff;\r\n }\r\n .message {\r\n padding: 0 12px;\r\n }\r\n .error {\r\n background-color: #F64747;\r\n border-bottom: 1px solid #f31515;\r\n }\r\n .success {\r\n background-color: #03C9A9;\r\n border-bottom: 1px solid #02aa8f;\r\n }\r\n .warning {\r\n background-color: #F7CA18;\r\n border-bottom: 1px solid #e7ba08;\r\n }\r\n .info {\r\n background-color: #0c6997;\r\n border-bottom: 1px solid #0c6997;\r\n }\r\n .close-click {\r\n font-size: 22px;\r\n cursor: pointer;\r\n padding: 10px;\r\n position: relative;\r\n top: 2px;\r\n margin: 0 auto;\r\n }\r\n `],\r\n template: `\r\n <div class=\"notifications-container\">\r\n <div *ngFor=\"let notification of notifications; let i = index;\"\r\n class=\"notification {{notification.typeValue}}\"\r\n (mouseover)=\"hideOnHover(notification)\"\r\n [@flyDown]>\r\n <span *ngIf=\"notification.isHtml\" class=\"message\" [innerHTML]=\"notification.message\"></span>\r\n <span *ngIf=\"!notification.isHtml\" class=\"message\">{{notification.message}}</span>\r\n <span class=\"close-click\" *ngIf=\"notification.allowClose\" (click)=\"hideNotification(notification)\">×</span>\r\n </div>\r\n </div>\r\n `,\r\n animations: [\r\n trigger('flyDown', [\r\n state('in', style({\r\n opacity: 1,\r\n transform: 'translateY(0)'\r\n })),\r\n transition('void => *', [\r\n style({\r\n opacity: 0,\r\n transform: 'translateY(-100%)'\r\n }),\r\n animate('600ms ease-in')\r\n ]),\r\n transition('* => void', [\r\n animate('200ms ease-out', style({\r\n opacity: 0,\r\n transform: 'translateY(-100%)'\r\n }))\r\n ])\r\n ])\r\n ]\r\n})\r\nexport class NotificationBarComponent implements OnInit, OnDestroy {\r\n\r\n notifications: Notification[] = [];\r\n\r\n defaults = {\r\n message: '',\r\n type: NotificationType.Info,\r\n autoHide: true,\r\n hideDelay: 3000,\r\n isHtml: false,\r\n allowClose: false,\r\n hideOnHover: true\r\n };\r\n\r\n subscription: Subscription;\r\n // closeSubscription: Subscription;\r\n constructor(\r\n private notificationBarService: NotificationBarService,\r\n @Inject(MESSAGES_CONFIG) @Optional() private config?: MessagesConfig\r\n ) {\r\n this.subscription = this.notificationBarService.onCreate.subscribe(this.addNotification.bind(this));\r\n this.notificationBarService.onClose.subscribe(this.hideNotification.bind(this));\r\n }\r\n\r\n ngOnInit() { }\r\n\r\n addNotification(notification: Notification) {\r\n const newNotification = Object.assign({}, this.defaults, notification);\r\n newNotification.typeValue = NotificationType[newNotification.type].toLowerCase();\r\n if (this.config && this.config.messages) {\r\n newNotification.message = this.config.messages[notification.message] || notification.message;\r\n }\r\n\r\n this.notifications.push(newNotification);\r\n\r\n if (newNotification.autoHide) {\r\n window.setTimeout(() => {\r\n this.hideNotification(newNotification);\r\n }, newNotification.hideDelay);\r\n }\r\n }\r\n\r\n hideNotification(notification: Notification) {\r\n const index = this.notifications.indexOf(notification);\r\n\r\n this.notifications.splice(index, 1);\r\n }\r\n\r\n ngOnDestroy() {\r\n this.subscription.unsubscribe();\r\n // this.closeSubscription.unsubscribe();\r\n }\r\n\r\n hideOnHover(notification: Notification) {\r\n if (notification.hideOnHover) {\r\n this.hideNotification(notification);\r\n }\r\n }\r\n}\r\n","import { NgModule, ModuleWithProviders } from '@angular/core';\r\nimport { CommonModule } from '@angular/common';\r\n\r\nimport { NotificationBarService } from './notification-bar.service';\r\nimport { NotificationBarComponent, MESSAGES_CONFIG } from './notification-bar.component';\r\nimport { MessagesConfig } from './message-config';\r\n\r\n\r\n\r\n@NgModule({\r\n imports: [\r\n CommonModule,\r\n ],\r\n declarations: [NotificationBarComponent],\r\n providers: [NotificationBarService],\r\n exports: [NotificationBarComponent]\r\n})\r\nexport class NotificationBarModule {\r\n\r\n static forRoot(config: MessagesConfig): ModuleWithProviders<NotificationBarModule> {\r\n return {\r\n ngModule: NotificationBarModule,\r\n providers: [\r\n { provide: MESSAGES_CONFIG, useValue: config }\r\n ]\r\n };\r\n }\r\n}\r\n","/*\n * Public API Surface of ngx-notification-bar\n */\nexport * from './lib/message-config';\nexport * from './lib/notification-bar.component';\nexport * from './lib/notification-bar.module';\nexport * from './lib/notification-bar.service';\nexport * from './lib/notification-bar.models';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;AAAY,IAAA,iBAAkD;AAA9D,CAAA,UAAY,gBAAgB,EAAA;IAAG,gBAAA,CAAA,gBAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;IAAE,gBAAA,CAAA,gBAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAO,CAAA;IAAE,gBAAA,CAAA,gBAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK,CAAA;IAAE,gBAAA,CAAA,gBAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAO,CAAA;AAAC,CAAC,EAAlD,gBAAgB,KAAhB,gBAAgB,GAAkC,EAAA,CAAA,CAAA;;ACI9D;;AAEG;MAEU,sBAAsB,CAAA;AAM/B,IAAA,WAAA,GAAA;AAHA,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,YAAY,EAAgB,CAAC;AAC5C,QAAA,IAAA,CAAA,OAAO,GAAG,IAAI,YAAY,EAAgB,CAAC;KAG1C;AAED,IAAA,MAAM,CAAC,YAA0B,EAAA;AAC7B,QAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACpC;AAED,IAAA,KAAK,CAAC,YAA0B,EAAA;AAC5B,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACnC;;sIAfQ,sBAAsB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAA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