-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
72 lines (63 loc) · 2.79 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import './src/css/notifier.css'
import './src/css/modal.css'
import './style.css'
import CreateElement, { h } from './src/createElement'
import Notifier, { notify } from './src/notifier'
import { confirmHandler } from './src/confirm.handler'
import { events } from './src/utils/constants'
import { doc } from './src/utils/doc'
class Notification extends CreateElement {
constructor ({ target, data }) {
super(target)
console.log(data)
this.confirmData = data
}
init () {
const confirmBtn = this.elm.create(h.button, { class: 'btn cbtn cblue' }, 'Confirm')
const showSuccess = this.elm.create(h.button, { class: ` cbtn btn-success` }, 'Success')
const showInfo = this.elm.create(h.button, { class: `cbtn btn-info` }, 'Info')
const showWarning = this.elm.create(h.button, { class: `cbtn btn-warning` }, 'Warning')
const showReminder = this.elm.create(h.button, { class: `cbtn btn-reminder` }, 'Reminder')
const showTodo = this.elm.create(h.button, { class: `cbtn btn-todo` }, 'Todo')
const showDanger = this.elm.create(h.button, { class: `cbtn btn-danger` }, 'Danger')
confirmBtn.addEventListener(events.click, this.showConfirmDialog.bind(this))
showSuccess.addEventListener(events.click, this.showNotification.bind(this, 'Success', notify.type.success, 'Something great happening 😄'))
showInfo.addEventListener(events.click, this.showNotification.bind(this, 'Info', notify.type.info, 'There is a new notification for you 🤓'))
showWarning.addEventListener(events.click, this.showNotification.bind(this, 'Warning', notify.type.warning, 'Something went wrong! 😱'))
showReminder.addEventListener(events.click, this.showNotification.bind(this, 'Reminder', notify.type.reminder, 'There is a new reminder'))
showTodo.addEventListener(events.click, this.showNotification.bind(this, 'Todo', notify.type.todo, 'To do something...'))
showDanger.addEventListener(events.click, this.showNotification.bind(this, 'Danger', notify.type.danger, 'Unexpected situation'))
this.elm.in(confirmBtn)
this.elm.in(showSuccess)
this.elm.in(showInfo)
this.elm.in(showWarning)
this.elm.in(showReminder)
this.elm.in(showTodo)
this.elm.in(showDanger)
}
showNotification (title, type, content) {
const notification = new Notifier({
title: title,
type: type,
content: content,
duration: 4000
})
notification.show()
}
showConfirmDialog () {
console.log(this.confirmData)
confirmHandler({
confirmData: this.confirmData,
callback: (data) => { console.log(data) },
data: 'confirmation callback data',
btnCaption: 'Okay'
})
}
}
const data = {
'deneme yap': 'data',
'Diger bir': 'data 2',
'deneme': 'data 3'
}
const app = doc.getId('app')
new Notification({ target: app, data: data }).init()