import { Component, OnInit, OnChanges, Input, Output, EventEmitter, ViewChild, ElementRef, SimpleChanges, NgZone, TemplateRef } from '@angular/core'; import { NotifyData,NotifyButton } from './notifiy.options'; @Component({ selector: 'farris-notify', template: `
{{ btn.text }} `, styles: [ ` .toast-title-beforeshow{ opacity:0; } @-webkit-keyframes farrisMoveUpIn { 0% { transform: translateY(-100%); transform-origin: 0 0; opacity: 0 } 100% { transform: translateY(0); transform-origin: 0 0; opacity: 1 } } @keyframes farrisMoveUpIn { 0% { transform: translateY(-100%); transform-origin: 0 0; opacity: 0 } 100% { transform: translateY(0); transform-origin: 0 0; opacity: 1 } } @-webkit-keyframes farrisMoveUpOut { 0% { transform: translateY(0); transform-origin: 0 0; opacity: 1 } 100% { transform: translateY(-100%); transform-origin: 0 0; opacity: 0 } } @keyframes farrisMoveUpOut { 0% { transform: translateY(0); transform-origin: 0 0; opacity: 1 } 100% { transform: translateY(-100%); transform-origin: 0 0; opacity: 0 } } .toast.fadeIn { -webkit-animation: farrisMoveUpIn 0.2s linear; animation: farrisMoveUpIn 0.2s linear; } .toast.fadeOut { -webkit-animation: farrisMoveUpOut 0.2s linear; animation: farrisMoveUpOut 0.2s linear; } ` ] }) export class NotifyComponent implements OnInit, OnChanges { @Input() toast: NotifyData; @Output() close = new EventEmitter(); @Output() btnClick = new EventEmitter(); @ViewChild('notifyDiv') notifyDiv: ElementRef; _state = false; @Input() animateCls: string; outCls = ''; inCls = {}; get state() { return this._state; } set state(value) { this._state = value; if (value) { this.inCls[this.animateCls] = false; this.inCls['animated'] = value; this.inCls[this.outCls] = value; // this.ngZone.runOutsideAngular(() => { setTimeout(() => { this.close.next(this.toast); }, 200); // }); } } constructor(private ngZone: NgZone) { } ngOnInit() { if (this.toast.buttons) { this.ngZone.runOutsideAngular(() => { setTimeout(() => { let closeEl = this.notifyDiv.nativeElement.querySelector('.toast-close'); let contentEl =this.notifyDiv.nativeElement.querySelector('.toast-title-btns-wrapper'); if(closeEl['clientHeight']+10