-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.js
167 lines (133 loc) · 3.14 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*! Copyright (c) 2016 Naufal Rabbani (http://github.com/BosNaufal)
* Licensed Under MIT (http://opensource.org/licenses/MIT)
*
* Vue 2 Loading Bar - Version 0.0.1
*
*/
module.exports = {
name: "LoadingBar",
props: {
id: String,
customClass: String,
progress: {
type: Number,
default: 0
},
// the direction of loading bar
direction: {
type: String,
default: "right"
},
error: Boolean, // Loading Bar error state
onErrorDone: {
type: Function,
required: true
},
onProgressDone: {
type: Function,
required: true
},
},
data() {
return {
// To show
show: true,
// binding class when it end
full: '',
// state to animate the width of loading bar
width: 0,
// indicate the loading bar is in 100% ( so, wait it till gone )
wait: false,
// Error State
myError: false
}
},
render(h) {
let {
direction, customClass, id,
width, show, full, myError,
styling } = this
return(
<div>
{ show ?
<div
id={ id ? id : null }
class={
'LoadingBar LoadingBar--to_' + direction + ' ' +
( customClass ? customClass : '' ) +
( myError ? 'LoadingBar--error' : '' ) +
( full ? 'LoadingBar--full' : '')
}
style={ styling() }>
<div class="LoadingBar-glow"></div>
</div>
: null }
</div>
)
},
watch:{
progress(val,old){
if(old !== val){
this.width = val
setTimeout(() => {
this.isFull()
})
}
},
error(val,old){
if(old !== val) {
if(val) {
this.width = 100
this.myError = true
setTimeout(() => {
this.isFull()
})
}
}
}
},
methods: {
// Check whether the proggress is full
isFull() {
// Full Indicator
let isFull = this.width === 100
// When the progress end or full
if(isFull){
// Prevent new progress change
this.wait = true
// Start animate it
setTimeout(() => {
// animate when element removed
this.full = true
this.myError = false
this.onErrorDone()
setTimeout(() => {
//remove bar element
this.show = false
// New Element is available to create now
this.width = 0
this.wait = false
setTimeout(() => {
// Show Bar
this.full = ''
this.show = true
this.onProgressDone()
});
// Duration to Waiting for slick hiding animation
},250);
// Duration is depend on css animation-duration of loading-bar
},700);
}
},
styling(){
// When loading bar still in progress
if(!this.wait){
return { width: `${this.width}%` };
// When loading bar end
}else{
// Make it stuck at 100 to waiting the animation
return{ width: `100%` };
}
}
},
};