Skip to content

Commit c9e3227

Browse files
committed
Add posibility to set notification options upon plugin initialization
Add a method to set options for all notifications
1 parent 0af1e46 commit c9e3227

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

example/App.vue

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
import Vue from 'vue'
1818
import Notifications from '../src/index'
19-
Vue.use(Notifications)
19+
Vue.use(Notifications, {type: 'danger'})
2020
export default{
2121
methods:{
2222
addNotification(verticalAlign='top', horizontalAlign='right'){
@@ -33,13 +33,7 @@
3333
}]
3434
this.$notify(notifications)*/
3535
36-
this.$notify( {
37-
horizontalAlign: 'right',
38-
verticalAlign: 'top',
39-
type: "info",
40-
component: msg
41-
},)
42-
36+
this.$notify({title: 'Hi', message: 'Some message'})
4337
}
4438
}
4539
}

src/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import Notifications from './Notifications.js'
33
const NotificationStore = {
44
state: [], // here the notifications will be added
55
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}
714
},
815
removeNotification (timestamp) {
916
const indexToDelete = this.state.findIndex(n => n.timestamp === timestamp)
@@ -12,8 +19,12 @@ const NotificationStore = {
1219
}
1320
},
1421
addNotification(notification){
22+
if (typeof notification === 'string' || notification instanceof String){
23+
notification = {message: notification}
24+
}
1525
notification.timestamp = new Date()
1626
notification.timestamp.setMilliseconds(notification.timestamp.getMilliseconds() + this.state.length)
27+
notification = {...this.settings, ...notification}
1728
this.state.push(notification)
1829
},
1930
notify (notification) {
@@ -29,7 +40,7 @@ const NotificationStore = {
2940
}
3041

3142
var NotificationsPlugin = {
32-
install (Vue) {
43+
install (Vue, options) {
3344
Vue.mixin({
3445
data(){
3546
return {
@@ -53,6 +64,9 @@ var NotificationsPlugin = {
5364
}
5465
})
5566
Vue.component('Notifications', Notifications)
67+
if(options){
68+
NotificationStore.setOptions(options)
69+
}
5670
}
5771
}
5872

0 commit comments

Comments
 (0)