@anglr/notifications
Version:
Angular module for displaying notifications
104 lines • 5.57 kB
JavaScript
import { Component, Input, Optional, PLATFORM_ID, Inject, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { isPlatformBrowser, NgClass } from '@angular/common';
import { extend } from '@jscrpt/common/extend';
import { Subscription } from 'rxjs';
import { NOTIFICATIONS_OPTIONS } from '../../common/notifications.interface';
import { LocalNotificationsService } from '../../common/notifications.service';
import { NotificationMessageComponent } from '../notificationMessage/notificationMessage.component';
import { MessageRendererDirective } from '../../directives';
import * as i0 from "@angular/core";
import * as i1 from "../../common/notifications.service";
/**
* Default options for notifications component
* @internal
*/
const defaultOptions = {
cssClasses: {
rootDiv: 'notifications',
},
getNotificationMessageComponent: () => NotificationMessageComponent
};
/**
* Notifications component for local messages
*/
export class NotificationsComponent {
//######################### public properties - template bindings #########################
/**
* Options used for notification message
*/
get options() {
return this.ɵoptions;
}
set options(options) {
this.ɵoptions = extend(true, this.ɵoptions, options);
}
//######################### constructor #########################
constructor(service, changeDetector, platformId, options) {
this.service = service;
this.changeDetector = changeDetector;
this.platformId = platformId;
//######################### protected fields #########################
/**
* Subscription all subscriptions created during initialization
*/
this.initSubscriptions = new Subscription();
//######################### public properties - template bindings #########################
/**
* Array of displayed notifications - displayed set
* @internal
*/
this.notifications = [];
this.ɵoptions = extend(true, {}, defaultOptions, options);
}
//######################### public methods - implementation of OnInit #########################
/**
* Initialize component
*/
ngOnInit() {
if (!isPlatformBrowser(this.platformId)) {
return;
}
this.notifications = this.service.notifications;
this.initSubscriptions.add(this.service.notificationsChange.subscribe(() => {
this.notifications = this.service.notifications;
this.changeDetector.detectChanges();
}));
}
//######################### public methods - implementation of OnDestroy #########################
/**
* Called when component is destroyed
*/
ngOnDestroy() {
this.initSubscriptions.unsubscribe();
}
//######################### public methods #########################
/**
* Removes notification item from list
* @param item - Item to be removed
*
* @internal
*/
removeItem(item) {
this.service.remove(item);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: NotificationsComponent, deps: [{ token: i1.LocalNotificationsService }, { token: i0.ChangeDetectorRef }, { token: PLATFORM_ID }, { token: NOTIFICATIONS_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.0", type: NotificationsComponent, isStandalone: true, selector: "notifications", inputs: { options: "options" }, ngImport: i0, template: "<div [ngClass]=\"options.cssClasses.rootDiv\">\r\n @for(itm of notifications; track itm)\r\n {\r\n <ng-template [messageRenderer]=\"itm\"\r\n [notificationsOptions]=\"options\"\r\n (closed)=\"removeItem($event)\"/>\r\n }\r\n</div>", dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: MessageRendererDirective, selector: "[messageRenderer]", inputs: ["messageRenderer", "notificationsOptions"], outputs: ["closed"], exportAs: ["messageRenderer"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: NotificationsComponent, decorators: [{
type: Component,
args: [{ selector: 'notifications', imports: [
NgClass,
MessageRendererDirective,
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [ngClass]=\"options.cssClasses.rootDiv\">\r\n @for(itm of notifications; track itm)\r\n {\r\n <ng-template [messageRenderer]=\"itm\"\r\n [notificationsOptions]=\"options\"\r\n (closed)=\"removeItem($event)\"/>\r\n }\r\n</div>" }]
}], ctorParameters: () => [{ type: i1.LocalNotificationsService }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
type: Inject,
args: [PLATFORM_ID]
}] }, { type: undefined, decorators: [{
type: Inject,
args: [NOTIFICATIONS_OPTIONS]
}, {
type: Optional
}] }], propDecorators: { options: [{
type: Input
}] } });
//# sourceMappingURL=notifications.component.js.map