ng2-yk-notifier
Advanced tools
Comparing version 1.0.0-beta.10 to 1.0.0-beta.11
import { ActionReducer } from "@ngrx/store"; | ||
import { INotifierMessage } from "./notifier.model"; | ||
export declare const ADD_MESSAGE: string; | ||
export declare const REMOVE_MESSAGE: string; | ||
import { Notice } from "./notifier-notice"; | ||
export declare const ADD_NOTICE: string; | ||
export declare const REMOVE_NOTICE: string; | ||
export declare const REMOVE_ALL: string; | ||
export declare const messagesReducer: ActionReducer<Array<INotifierMessage>>; | ||
export declare const messagesReducer: ActionReducer<Array<Notice>>; |
"use strict"; | ||
exports.ADD_MESSAGE = 'ADD_MESSAGE'; | ||
exports.REMOVE_MESSAGE = 'REMOVE_MESSAGE'; | ||
exports.ADD_NOTICE = 'ADD_NOTICE'; | ||
exports.REMOVE_NOTICE = 'REMOVE_NOTICE'; | ||
exports.REMOVE_ALL = 'REMOVE_ALL'; | ||
@@ -8,5 +8,5 @@ exports.messagesReducer = function (state, action) { | ||
switch (action.type) { | ||
case exports.ADD_MESSAGE: | ||
case exports.ADD_NOTICE: | ||
return state.concat([Object.assign({}, action.payload)]); | ||
case exports.REMOVE_MESSAGE: | ||
case exports.REMOVE_NOTICE: | ||
return state.filter(function (message) { return message.id !== action.payload.id; }); | ||
@@ -13,0 +13,0 @@ case exports.REMOVE_ALL: |
import { OnInit, OnDestroy } from "@angular/core"; | ||
import { Store } from "@ngrx/store"; | ||
import { INotifierMessage } from "./notifier.model"; | ||
import { Notice } from "./notifier-notice"; | ||
import { NotifierOptions } from "./notifier-options.service"; | ||
export declare class NotifierContainerComponent implements OnInit, OnDestroy { | ||
private store; | ||
notices: INotifierMessage[]; | ||
notices: Notice[]; | ||
animate: 'fromRight' | 'fromLeft' | 'rotate' | 'scale' | 'fade'; | ||
@@ -16,8 +16,8 @@ clickToClose: boolean; | ||
private selectNoticesSub; | ||
constructor(store: Store<INotifierMessage[]>, options: NotifierOptions); | ||
constructor(store: Store<Notice[]>, options: NotifierOptions); | ||
ngOnInit(): void; | ||
ngOnDestroy(): void; | ||
addNotice(notice: INotifierMessage): void; | ||
removeNotice(notice?: INotifierMessage): void; | ||
addNotice(notice: Notice): void; | ||
removeNotice(notice?: Notice): void; | ||
anyNotices(): boolean; | ||
} |
@@ -39,7 +39,7 @@ "use strict"; | ||
NotifierContainerComponent.prototype.addNotice = function (notice) { | ||
this.store.dispatch({ type: messages_reducer_1.ADD_MESSAGE, payload: notice }); | ||
this.store.dispatch({ type: messages_reducer_1.ADD_NOTICE, payload: notice }); | ||
}; | ||
NotifierContainerComponent.prototype.removeNotice = function (notice) { | ||
if (notice) { | ||
this.store.dispatch({ type: messages_reducer_1.REMOVE_MESSAGE, payload: notice }); | ||
this.store.dispatch({ type: messages_reducer_1.REMOVE_NOTICE, payload: notice }); | ||
} | ||
@@ -56,3 +56,3 @@ else { | ||
selector: 'app-notifier-container', | ||
template: "<div class=\"notifier-wrapper\" *ngIf=\"notices\" [ngClass]=\"position\"><ng2-notifier-message *ngFor=\"let message of notices| max: maxStack\" [animate]=\"animate\" [theClass]=\"theClass\" [timeDelay]=\"timeDelay\" [clickToClose]=\"clickToClose\" [pauseOnHover]=\"pauseOnHover\" [message]=\"message\"></ng2-notifier-message></div>", | ||
template: "<div class=\"notifier-wrapper\" *ngIf=\"notices\" [ngClass]=\"position\"><ng2-notifier-message *ngFor=\"let message of notices| max: maxStack\" [notice]=\"message\"></ng2-notifier-message></div>", | ||
styles: [".notifier-wrapper{position:fixed}.notifier-wrapper.left{left:16px;left:1rem}.notifier-wrapper.bottom{bottom:16px;bottom:1rem}.notifier-wrapper.right{right:16px;right:1rem}.notifier-wrapper.top{top:16px;top:1rem}.notifier-wrapper.center{left:50%;-webkit-transform:translateX(-50%);-moz-transform:translateX(-50%);-ms-transform:translateX(-50%);transform:translateX(-50%)}"], | ||
@@ -59,0 +59,0 @@ }), |
import { OnInit, OnDestroy, AnimationTransitionEvent } from '@angular/core'; | ||
import { INotifierMessage } from "./notifier.model"; | ||
import { Notice } from "./notifier-notice"; | ||
import { DomSanitizer } from "@angular/platform-browser"; | ||
@@ -8,8 +8,3 @@ import { NotifierService } from "./notifier.service"; | ||
private notifierService; | ||
message: INotifierMessage; | ||
animate: string; | ||
clickToClose: boolean; | ||
pauseOnHover: boolean; | ||
theClass: string; | ||
timeDelay: number; | ||
notice: Notice; | ||
private safeSvg; | ||
@@ -22,3 +17,3 @@ private timerId; | ||
ngOnDestroy(): void; | ||
animationDone(event: AnimationTransitionEvent, message: INotifierMessage): void; | ||
animationDone(event: AnimationTransitionEvent): void; | ||
onEnter(): void; | ||
@@ -25,0 +20,0 @@ onLeave(): void; |
@@ -12,2 +12,3 @@ "use strict"; | ||
var core_1 = require('@angular/core'); | ||
var notifier_notice_1 = require("./notifier-notice"); | ||
var platform_browser_1 = require("@angular/platform-browser"); | ||
@@ -22,5 +23,5 @@ var notifier_service_1 = require("./notifier.service"); | ||
NotifierMessageComponent.prototype.ngOnInit = function () { | ||
this.safeSvg = this.domSanitizer.bypassSecurityTrustHtml(this.message.icon); | ||
this.message.state = this.animate; | ||
if (this.timeDelay > 0) { | ||
this.safeSvg = this.domSanitizer.bypassSecurityTrustHtml(this.notice.icon); | ||
this.notice.state = this.notice.config.animate; | ||
if (this.notice.config.timeDelay > 0) { | ||
this.startTimer(); | ||
@@ -32,10 +33,10 @@ } | ||
}; | ||
NotifierMessageComponent.prototype.animationDone = function (event, message) { | ||
if (event.toState == message.state + 'Out') { | ||
this.notifierService.clear(message); | ||
NotifierMessageComponent.prototype.animationDone = function (event) { | ||
if (event.toState == this.notice.config.animate + 'Out') { | ||
this.notifierService.clear(this.notice); | ||
} | ||
}; | ||
NotifierMessageComponent.prototype.onEnter = function () { | ||
if (this.pauseOnHover) { | ||
this.timeLeft = this.timeDelay; | ||
if (this.notice.config.pauseOnHover) { | ||
this.timeLeft = this.notice.config.timeDelay; | ||
this.timeLeft -= new Date().getTime() - this.start; | ||
@@ -47,5 +48,5 @@ this.clearTimer(); | ||
var _this = this; | ||
if (this.pauseOnHover) { | ||
if (this.notice.config.pauseOnHover) { | ||
if (!this.timeLeft) { | ||
this.timeLeft = this.timeDelay; | ||
this.timeLeft = this.notice.config.timeDelay; | ||
} | ||
@@ -58,3 +59,3 @@ this.timerId = window.setTimeout(function () { | ||
NotifierMessageComponent.prototype.onClick = function () { | ||
if (this.clickToClose) { | ||
if (this.notice.config.clickToClose) { | ||
this.setStateOut(); | ||
@@ -68,3 +69,3 @@ } | ||
_this.setStateOut(); | ||
}, this.timeDelay); | ||
}, this.notice.config.timeDelay); | ||
}; | ||
@@ -75,3 +76,3 @@ NotifierMessageComponent.prototype.clearTimer = function () { | ||
NotifierMessageComponent.prototype.setStateOut = function () { | ||
this.animate = this.animate + 'Out'; | ||
this.notice.state = this.notice.config.animate + 'Out'; | ||
this.clearTimer(); | ||
@@ -81,28 +82,8 @@ }; | ||
core_1.Input(), | ||
__metadata('design:type', Object) | ||
], NotifierMessageComponent.prototype, "message", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', String) | ||
], NotifierMessageComponent.prototype, "animate", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', Boolean) | ||
], NotifierMessageComponent.prototype, "clickToClose", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', Boolean) | ||
], NotifierMessageComponent.prototype, "pauseOnHover", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', String) | ||
], NotifierMessageComponent.prototype, "theClass", void 0); | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata('design:type', Number) | ||
], NotifierMessageComponent.prototype, "timeDelay", void 0); | ||
__metadata('design:type', notifier_notice_1.Notice) | ||
], NotifierMessageComponent.prototype, "notice", void 0); | ||
NotifierMessageComponent = __decorate([ | ||
core_1.Component({ | ||
selector: 'ng2-notifier-message', | ||
template: "<div [@enterLeave]=\"animate\" (@enterLeave.done)=\"animationDone($event, message)\" (click)=\"onClick()\" (mouseenter)=\"onEnter()\" (mouseleave)=\"onLeave()\" [class]=\"theClass\" class=\"notifier-message {{message.type}}\"><div class=\"timer\" *ngIf=\"showProcess\"><div class=\"bar\" [style.width]=\"getPercentage()\"></div></div><div class=\"title\">{{message.title}}</div><div class=\"content\">{{message.content}}</div><div [innerHTML]=\"safeSvg\"></div></div>", | ||
template: "<div [@enterLeave]=\"notice.state\" (@enterLeave.done)=\"animationDone($event)\" (click)=\"onClick()\" (mouseenter)=\"onEnter()\" (mouseleave)=\"onLeave()\" [class]=\"notice.config.theClass\" class=\"notifier-message {{notice.type}}\"><div class=\"title\">{{notice.title}}</div><div class=\"content\">{{notice.content}}</div><div [innerHTML]=\"safeSvg\"></div></div>", | ||
styles: [".notifier-message,.timer{-moz-border-radius:.3rem}.notifier-message{font-size:12px;font-size:.75rem;line-height:20px;line-height:1.25rem;position:relative;width:272px;width:17rem;min-height:48px;min-height:3rem;border-radius:.3rem;margin-bottom:10px;margin-bottom:.625rem;padding:10px;padding:.625rem;color:#333;background-color:#fff;border-color:#ccc;-moz-box-shadow:0 0 8px 3px rgba(255,254,247,.75);box-shadow:0 0 8px 3px rgba(255,254,247,.75);cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.notifier-message .title{font-size:16px;font-size:1rem;line-height:20px;line-height:1.25rem}.notifier-message .content,.notifier-message .title{padding-right:48px;padding-right:3rem}.notifier-message.primary{color:#fff;background-color:#337ab7;border-color:#2e6da4}.notifier-message.success{color:#fff;background-color:#5cb85c;border-color:#4cae4c}.notifier-message.danger{color:#fff;background-color:#d9534f;border-color:#d43f3a}.notifier-message.warning{color:#fff;background-color:#f0ad4e;border-color:#eea236}:host /deep/ .notifier-message svg{position:absolute;-moz-box-sizing:border-box;box-sizing:border-box;top:0;right:0;width:48px;width:3rem;height:48px;height:3rem;padding:10px;padding:.625rem;fill:#fff}.timer{position:absolute;top:0;left:0;width:100%;height:4px;border-radius:.3rem}.timer .bar{display:block;position:relative;height:100%;-moz-border-radius:.3rem;border-radius:.3rem;background:rgba(0,0,0,.3);-webkit-transition:width .1s ease;-moz-transition:width .1s ease;transition:width .1s ease}"], | ||
@@ -109,0 +90,0 @@ animations: [ |
import { ComponentRef, ViewContainerRef, ComponentFactoryResolver, ApplicationRef } from '@angular/core'; | ||
import { INotifierMessage } from "./notifier.model"; | ||
import { Notice } from "./notifier-notice"; | ||
import { NotifierOptions } from "./notifier-options.service"; | ||
@@ -13,9 +13,9 @@ export declare class NotifierService { | ||
setRootViewContainerRef(vRef: ViewContainerRef): void; | ||
set(message: INotifierMessage): INotifierMessage; | ||
set(notice: Notice, options?: Object): Notice; | ||
dispose(): void; | ||
clear(notice?: INotifierMessage): void; | ||
info(content: string, title?: string): INotifierMessage; | ||
success(content: string, title?: string): INotifierMessage; | ||
error(content: string, title?: string): INotifierMessage; | ||
alert(content: string, title?: string): INotifierMessage; | ||
clear(notice?: Notice): void; | ||
info(content: string, title?: string, options?: Object): Notice; | ||
success(content: string, title?: string, options?: Object): Notice; | ||
error(content: string, title?: string, options?: Object): Notice; | ||
alert(content: string, title?: string, options?: Object): Notice; | ||
} |
@@ -15,3 +15,3 @@ "use strict"; | ||
var core_1 = require('@angular/core'); | ||
var uuid_1 = require("./uuid"); | ||
var notifier_notice_1 = require("./notifier-notice"); | ||
var icons_1 = require('./icons'); | ||
@@ -33,3 +33,4 @@ var notifier_options_service_1 = require("./notifier-options.service"); | ||
}; | ||
NotifierService.prototype.set = function (message) { | ||
NotifierService.prototype.set = function (notice, options) { | ||
var _this = this; | ||
if (!this.container) { | ||
@@ -51,7 +52,12 @@ if (!this._rootViewContainerRef) { | ||
} | ||
if (!message.id) { | ||
message.id = uuid_1.uuid(); | ||
} | ||
this.container.instance.addNotice(message); | ||
return message; | ||
Object.keys(notice.config).forEach(function (k) { | ||
if (_this.options.hasOwnProperty(k)) { | ||
notice.config[k] = _this.options[k]; | ||
} | ||
if (options && options.hasOwnProperty(k)) { | ||
notice.config[k] = options[k]; | ||
} | ||
}); | ||
this.container.instance.addNotice(notice); | ||
return notice; | ||
}; | ||
@@ -74,37 +80,17 @@ NotifierService.prototype.dispose = function () { | ||
}; | ||
NotifierService.prototype.info = function (content, title) { | ||
var message = { | ||
title: title, | ||
content: content, | ||
type: 'primary', | ||
icon: this.icons.info, | ||
}; | ||
return this.set(message); | ||
NotifierService.prototype.info = function (content, title, options) { | ||
var notice = new notifier_notice_1.Notice('primary', content, title, this.icons.info); | ||
return this.set(notice, options); | ||
}; | ||
NotifierService.prototype.success = function (content, title) { | ||
var message = { | ||
title: title, | ||
content: content, | ||
type: 'success', | ||
icon: this.icons.success, | ||
}; | ||
return this.set(message); | ||
NotifierService.prototype.success = function (content, title, options) { | ||
var notice = new notifier_notice_1.Notice('success', content, title, this.icons.success); | ||
return this.set(notice, options); | ||
}; | ||
NotifierService.prototype.error = function (content, title) { | ||
var message = { | ||
title: title, | ||
content: content, | ||
type: 'danger', | ||
icon: this.icons.error, | ||
}; | ||
return this.set(message); | ||
NotifierService.prototype.error = function (content, title, options) { | ||
var notice = new notifier_notice_1.Notice('danger', content, title, this.icons.error); | ||
return this.set(notice, options); | ||
}; | ||
NotifierService.prototype.alert = function (content, title) { | ||
var message = { | ||
title: title, | ||
content: content, | ||
type: 'warning', | ||
icon: this.icons.alert, | ||
}; | ||
return this.set(message); | ||
NotifierService.prototype.alert = function (content, title, options) { | ||
var notice = new notifier_notice_1.Notice('warning', content, title, this.icons.alert); | ||
return this.set(notice, options); | ||
}; | ||
@@ -111,0 +97,0 @@ NotifierService = __decorate([ |
{ | ||
"name": "ng2-yk-notifier", | ||
"version": "1.0.0-beta.10", | ||
"version": "1.0.0-beta.11", | ||
"description": "Angular2 Notification Component", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -6,14 +6,14 @@ /** | ||
import { ActionReducer, Action } from "@ngrx/store"; | ||
import { INotifierMessage } from "./notifier.model"; | ||
import { Notice } from "./notifier-notice"; | ||
export const ADD_MESSAGE = 'ADD_MESSAGE'; | ||
export const REMOVE_MESSAGE = 'REMOVE_MESSAGE'; | ||
export const ADD_NOTICE = 'ADD_NOTICE'; | ||
export const REMOVE_NOTICE = 'REMOVE_NOTICE'; | ||
export const REMOVE_ALL = 'REMOVE_ALL'; | ||
export const messagesReducer: ActionReducer<Array<INotifierMessage>> = ( state: Array<INotifierMessage> = [], action: Action ) => { | ||
export const messagesReducer: ActionReducer<Array<Notice>> = ( state: Array<Notice> = [], action: Action ) => { | ||
switch (action.type) { | ||
case ADD_MESSAGE: | ||
case ADD_NOTICE: | ||
return [...state, Object.assign({}, action.payload)]; | ||
case REMOVE_MESSAGE: | ||
case REMOVE_NOTICE: | ||
return state.filter(message => message.id !== action.payload.id); | ||
@@ -20,0 +20,0 @@ |
@@ -7,4 +7,4 @@ /** | ||
import { Store } from "@ngrx/store"; | ||
import { INotifierMessage } from "./notifier.model"; | ||
import { ADD_MESSAGE, REMOVE_MESSAGE, REMOVE_ALL } from "./messages.reducer"; | ||
import { Notice } from "./notifier-notice"; | ||
import { ADD_NOTICE, REMOVE_NOTICE, REMOVE_ALL } from "./messages.reducer"; | ||
import { Subscription } from "rxjs"; | ||
@@ -21,3 +21,3 @@ import { NotifierOptions } from "./notifier-options.service"; | ||
selector: 'app-notifier-container', | ||
template: `<div class="notifier-wrapper" *ngIf="notices" [ngClass]="position"><ng2-notifier-message *ngFor="let message of notices| max: maxStack" [animate]="animate" [theClass]="theClass" [timeDelay]="timeDelay" [clickToClose]="clickToClose" [pauseOnHover]="pauseOnHover" [message]="message"></ng2-notifier-message></div>`, | ||
template: `<div class="notifier-wrapper" *ngIf="notices" [ngClass]="position"><ng2-notifier-message *ngFor="let message of notices| max: maxStack" [notice]="message"></ng2-notifier-message></div>`, | ||
styles: [`.notifier-wrapper{position:fixed}.notifier-wrapper.left{left:16px;left:1rem}.notifier-wrapper.bottom{bottom:16px;bottom:1rem}.notifier-wrapper.right{right:16px;right:1rem}.notifier-wrapper.top{top:16px;top:1rem}.notifier-wrapper.center{left:50%;-webkit-transform:translateX(-50%);-moz-transform:translateX(-50%);-ms-transform:translateX(-50%);transform:translateX(-50%)}`], | ||
@@ -28,3 +28,3 @@ }) | ||
notices: INotifierMessage[]; | ||
notices: Notice[]; | ||
animate: 'fromRight' | 'fromLeft' | 'rotate' | 'scale' | 'fade' = 'fromRight'; | ||
@@ -41,3 +41,3 @@ clickToClose: boolean = true; | ||
constructor( private store: Store<INotifierMessage[]>, | ||
constructor( private store: Store<Notice[]>, | ||
@Optional() options: NotifierOptions ) { | ||
@@ -51,3 +51,3 @@ if (options) { | ||
this.selectNoticesSub = this.store.select('messages').subscribe( | ||
( data: INotifierMessage[] ) => this.notices = data | ||
( data: Notice[] ) => this.notices = data | ||
); | ||
@@ -60,9 +60,9 @@ } | ||
addNotice( notice: INotifierMessage ): void { | ||
this.store.dispatch({type: ADD_MESSAGE, payload: notice}); | ||
addNotice( notice: Notice ): void { | ||
this.store.dispatch({type: ADD_NOTICE, payload: notice}); | ||
} | ||
removeNotice( notice?: INotifierMessage ): void { | ||
removeNotice( notice?: Notice ): void { | ||
if (notice) { | ||
this.store.dispatch({type: REMOVE_MESSAGE, payload: notice}); | ||
this.store.dispatch({type: REMOVE_NOTICE, payload: notice}); | ||
} else { | ||
@@ -69,0 +69,0 @@ this.store.dispatch({type: REMOVE_ALL}); |
@@ -9,3 +9,3 @@ /** | ||
} from '@angular/core'; | ||
import { INotifierMessage } from "./notifier.model"; | ||
import { Notice } from "./notifier-notice"; | ||
import { DomSanitizer, SafeHtml } from "@angular/platform-browser"; | ||
@@ -22,3 +22,3 @@ import { NotifierService } from "./notifier.service"; | ||
selector: 'ng2-notifier-message', | ||
template: `<div [@enterLeave]="animate" (@enterLeave.done)="animationDone($event, message)" (click)="onClick()" (mouseenter)="onEnter()" (mouseleave)="onLeave()" [class]="theClass" class="notifier-message {{message.type}}"><div class="timer" *ngIf="showProcess"><div class="bar" [style.width]="getPercentage()"></div></div><div class="title">{{message.title}}</div><div class="content">{{message.content}}</div><div [innerHTML]="safeSvg"></div></div>`, | ||
template: `<div [@enterLeave]="notice.state" (@enterLeave.done)="animationDone($event)" (click)="onClick()" (mouseenter)="onEnter()" (mouseleave)="onLeave()" [class]="notice.config.theClass" class="notifier-message {{notice.type}}"><div class="title">{{notice.title}}</div><div class="content">{{notice.content}}</div><div [innerHTML]="safeSvg"></div></div>`, | ||
styles: [`.notifier-message,.timer{-moz-border-radius:.3rem}.notifier-message{font-size:12px;font-size:.75rem;line-height:20px;line-height:1.25rem;position:relative;width:272px;width:17rem;min-height:48px;min-height:3rem;border-radius:.3rem;margin-bottom:10px;margin-bottom:.625rem;padding:10px;padding:.625rem;color:#333;background-color:#fff;border-color:#ccc;-moz-box-shadow:0 0 8px 3px rgba(255,254,247,.75);box-shadow:0 0 8px 3px rgba(255,254,247,.75);cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.notifier-message .title{font-size:16px;font-size:1rem;line-height:20px;line-height:1.25rem}.notifier-message .content,.notifier-message .title{padding-right:48px;padding-right:3rem}.notifier-message.primary{color:#fff;background-color:#337ab7;border-color:#2e6da4}.notifier-message.success{color:#fff;background-color:#5cb85c;border-color:#4cae4c}.notifier-message.danger{color:#fff;background-color:#d9534f;border-color:#d43f3a}.notifier-message.warning{color:#fff;background-color:#f0ad4e;border-color:#eea236}:host /deep/ .notifier-message svg{position:absolute;-moz-box-sizing:border-box;box-sizing:border-box;top:0;right:0;width:48px;width:3rem;height:48px;height:3rem;padding:10px;padding:.625rem;fill:#fff}.timer{position:absolute;top:0;left:0;width:100%;height:4px;border-radius:.3rem}.timer .bar{display:block;position:relative;height:100%;-moz-border-radius:.3rem;border-radius:.3rem;background:rgba(0,0,0,.3);-webkit-transition:width .1s ease;-moz-transition:width .1s ease;transition:width .1s ease}`], | ||
@@ -90,8 +90,3 @@ animations: [ | ||
@Input() message: INotifierMessage; | ||
@Input() animate: string; | ||
@Input() clickToClose: boolean; | ||
@Input() pauseOnHover: boolean; | ||
@Input() theClass: string; | ||
@Input() timeDelay: number; | ||
@Input() notice: Notice; | ||
@@ -108,6 +103,6 @@ private safeSvg: SafeHtml; | ||
ngOnInit() { | ||
this.safeSvg = this.domSanitizer.bypassSecurityTrustHtml(this.message.icon); | ||
this.message.state = this.animate; | ||
this.safeSvg = this.domSanitizer.bypassSecurityTrustHtml(this.notice.icon); | ||
this.notice.state = this.notice.config.animate; | ||
if (this.timeDelay > 0) { | ||
if (this.notice.config.timeDelay > 0) { | ||
this.startTimer(); | ||
@@ -121,5 +116,5 @@ } | ||
animationDone( event: AnimationTransitionEvent, message: INotifierMessage ): void { | ||
if (event.toState == message.state + 'Out') { | ||
this.notifierService.clear(message); | ||
animationDone( event: AnimationTransitionEvent ): void { | ||
if (event.toState == this.notice.config.animate + 'Out') { | ||
this.notifierService.clear(this.notice); | ||
} | ||
@@ -129,4 +124,4 @@ } | ||
onEnter(): void { | ||
if (this.pauseOnHover) { | ||
this.timeLeft = this.timeDelay; | ||
if (this.notice.config.pauseOnHover) { | ||
this.timeLeft = this.notice.config.timeDelay; | ||
this.timeLeft -= new Date().getTime() - this.start; | ||
@@ -138,5 +133,5 @@ this.clearTimer(); | ||
onLeave(): void { | ||
if (this.pauseOnHover) { | ||
if (this.notice.config.pauseOnHover) { | ||
if (!this.timeLeft) { | ||
this.timeLeft = this.timeDelay; | ||
this.timeLeft = this.notice.config.timeDelay; | ||
} | ||
@@ -150,3 +145,3 @@ this.timerId = window.setTimeout(() => { | ||
onClick(): void { | ||
if (this.clickToClose) { | ||
if (this.notice.config.clickToClose) { | ||
this.setStateOut(); | ||
@@ -160,3 +155,3 @@ } | ||
this.setStateOut(); | ||
}, this.timeDelay); | ||
}, this.notice.config.timeDelay); | ||
} | ||
@@ -169,5 +164,5 @@ | ||
private setStateOut(): void { | ||
this.animate = this.animate + 'Out'; | ||
this.notice.state = this.notice.config.animate + 'Out'; | ||
this.clearTimer(); | ||
} | ||
} |
@@ -14,4 +14,3 @@ /** | ||
} from '@angular/core'; | ||
import { uuid } from "./uuid"; | ||
import { INotifierMessage } from "./notifier.model"; | ||
import { Notice } from "./notifier-notice"; | ||
import { Icons, defaultIcons } from './icons'; | ||
@@ -42,3 +41,3 @@ import { NotifierOptions } from "./notifier-options.service"; | ||
set( message: INotifierMessage ): INotifierMessage { | ||
set( notice: Notice, options?: Object ): Notice { | ||
@@ -64,7 +63,15 @@ if (!this.container) { | ||
} | ||
if (!message.id) { | ||
message.id = uuid(); | ||
} | ||
this.container.instance.addNotice(message); | ||
return message; | ||
Object.keys(notice.config).forEach(k => { | ||
if (this.options.hasOwnProperty(k)) { | ||
notice.config[k] = this.options[k]; | ||
} | ||
if (options && options.hasOwnProperty(k)) { | ||
notice.config[k] = options[k]; | ||
} | ||
}); | ||
this.container.instance.addNotice(notice); | ||
return notice; | ||
} | ||
@@ -81,3 +88,3 @@ | ||
clear( notice?: INotifierMessage ): void { | ||
clear( notice?: Notice ): void { | ||
if (!this.container) return; | ||
@@ -90,41 +97,21 @@ this.container.instance.removeNotice(notice); | ||
info( content: string, title?: string ) { | ||
let message = { | ||
title: title, | ||
content: content, | ||
type: 'primary', | ||
icon: this.icons.info, | ||
}; | ||
return this.set(message); | ||
info( content: string, title?: string, options?: Object ) { | ||
let notice = new Notice('primary', content, title, this.icons.info); | ||
return this.set(notice, options); | ||
} | ||
success( content: string, title?: string ) { | ||
let message = { | ||
title: title, | ||
content: content, | ||
type: 'success', | ||
icon: this.icons.success, | ||
}; | ||
return this.set(message); | ||
success( content: string, title?: string, options?: Object ) { | ||
let notice = new Notice('success', content, title, this.icons.success); | ||
return this.set(notice, options); | ||
} | ||
error( content: string, title?: string ) { | ||
let message = { | ||
title: title, | ||
content: content, | ||
type: 'danger', | ||
icon: this.icons.error, | ||
}; | ||
return this.set(message); | ||
error( content: string, title?: string, options?: Object ) { | ||
let notice = new Notice('danger', content, title, this.icons.error); | ||
return this.set(notice, options); | ||
} | ||
alert( content: string, title?: string ) { | ||
let message = { | ||
title: title, | ||
content: content, | ||
type: 'warning', | ||
icon: this.icons.alert, | ||
}; | ||
return this.set(message); | ||
alert( content: string, title?: string, options?: Object ) { | ||
let notice = new Notice('warning', content, title, this.icons.alert); | ||
return this.set(notice, options); | ||
} | ||
} |
38
53906
1089