blob: 476853cf3dfc5627e6fc8498560a52deec0be322 [file] [log] [blame]
Israel Lavi1994c982018-05-21 17:42:00 +03001import { Component, Input, Output, EventEmitter, OnInit, ViewContainerRef, ViewChild } from "@angular/core";
2import { NotificationSettings } from "../utilities/notification.config";
3import { CreateDynamicComponentService } from "../../utils/create-dynamic-component.service";
4import template from "./notification.component.html";
5
6@Component({
7 selector: 'sdc-notification',
8 template: template
9})
10
11export class NotificationComponent implements OnInit {
12
13 @Input() notificationSetting:NotificationSettings;
14 @Output() destroyComponent = new EventEmitter<any>();
15 @ViewChild("dynamicContentContainer", {read: ViewContainerRef}) contentContainer:ViewContainerRef;
16 private fade: boolean = false;
17
18 constructor(private createDynamicComponentService: CreateDynamicComponentService) {
19 }
20
21 public ngOnInit() {
22 if(this.notificationSetting.hasCustomContent){
23 this.createDynamicComponentService.insertComponentDynamically(this.notificationSetting.innerComponentType, this.notificationSetting.innerComponentOptions, this.contentContainer);
24 }
25
26 if(!this.notificationSetting.sticky){
27 setTimeout(() => this.fadeOut(), this.notificationSetting.duration);
28 }
29 }
30
31 private fadeOut = ():void => {
32 this.fade = true;
33 }
34
35 private destroyMe() {
36 /*Only destroy on fade out, not on entry animation */
37 if(this.fade){
38 this.destroyComponent.emit(this.notificationSetting);
39 }
40 }
41
42}