-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdialog-choose.vue
73 lines (71 loc) · 2.19 KB
/
dialog-choose.vue
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
73
<style lang="css">
.vac.dialog-vac.dialog-choose ul {
list-style: none;
margin: 0;
padding: 0;
}
.vac.dialog-vac.dialog-choose ul li {
padding: 10px;
background-color: #439dd2;
margin-bottom: 10px;
color: white;
font-size: 16px;
}
</style>
<template lang="html">
<div> <!-- initial wrapper required by Vue2 -->
<!-- Embedded blackayer on main element, where wrapper is the real content -->
<div class="vac dialog-vac dialog-choose" v-bind:class="{ active: active }" v-bind:style="{ zIndex: zIndex }">
<div class="wrapper">
<h1>{{title}}</h1>
<p>{{message}}</p>
<ul>
<li v-for="(button, index) in buttons" v-on:click="choose(index, button.label)" v-bind:style="{ backgroundColor: button.bgColor || '#439dd2'}">{{button.label}}</li>
</ul>
<div class="buttons">
<button class="cancel" v-on:click="cancel">{{buttonCancel}}</button>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
props: {
active: Boolean,
zIndex: Number,
title: String,
message: String,
buttons: Array,
buttonCancel: {
type: String,
default: "Cancel",
},
callback: {
type: Function,
default() {
console.log("No callback specified. Default executed.");
}
},
},
methods: {
choose(btnIndex, label) {
this.active = false;
this.zIndex = -1;
if(this.callback) this.callback(btnIndex, label);
},
cancel() {
this.zIndex = -1;
this.active = false;
}
},
created() {
var self = this;
window.addEventListener("click", function(e) {
if(new RegExp("dialog-vac").test(e.target.className)) {
self.cancel();
}
});
}
}
</script>