@@ -3,7 +3,14 @@ import Notifications from './Notifications.js'
3
3
const NotificationStore = {
4
4
state : [ ] , // here the notifications will be added
5
5
settings : {
6
- overlap : false
6
+ overlap : false ,
7
+ verticalAlign : 'top' ,
8
+ horizontalAlign : 'right' ,
9
+ type : 'info' ,
10
+ timeout : 5000
11
+ } ,
12
+ setOptions ( options ) {
13
+ this . settings = { ...this . settings , ...options }
7
14
} ,
8
15
removeNotification ( timestamp ) {
9
16
const indexToDelete = this . state . findIndex ( n => n . timestamp === timestamp )
@@ -12,8 +19,12 @@ const NotificationStore = {
12
19
}
13
20
} ,
14
21
addNotification ( notification ) {
22
+ if ( typeof notification === 'string' || notification instanceof String ) {
23
+ notification = { message : notification }
24
+ }
15
25
notification . timestamp = new Date ( )
16
26
notification . timestamp . setMilliseconds ( notification . timestamp . getMilliseconds ( ) + this . state . length )
27
+ notification = { ...this . settings , ...notification }
17
28
this . state . push ( notification )
18
29
} ,
19
30
notify ( notification ) {
@@ -29,7 +40,7 @@ const NotificationStore = {
29
40
}
30
41
31
42
var NotificationsPlugin = {
32
- install ( Vue ) {
43
+ install ( Vue , options ) {
33
44
Vue . mixin ( {
34
45
data ( ) {
35
46
return {
@@ -53,6 +64,9 @@ var NotificationsPlugin = {
53
64
}
54
65
} )
55
66
Vue . component ( 'Notifications' , Notifications )
67
+ if ( options ) {
68
+ NotificationStore . setOptions ( options )
69
+ }
56
70
}
57
71
}
58
72
0 commit comments