Skip to content

Commit ff9f359

Browse files
Merge pull request #7 from SchnapsterDog/develop
feat: adjusted code, refactoring
2 parents 02bb6e6 + 2dc6e77 commit ff9f359

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/components/vue-preloader.vue

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<template>
22
<div
33
:class="$style.preloader"
4-
:style="preloader"
4+
:style="[
5+
preloaderBackgroundColor,
6+
preloaderTransition,
7+
preloaderWidth
8+
]"
59
>
6-
<slot v-bind="{ percent }">
10+
<slot v-bind="{ color, percent }">
711
<div
812
v-if="percent < 100"
913
:class="$style.percentBar"
10-
:style="percentBackgroundColor"
14+
:style="{ color }"
1115
>
1216
{{ percent }} %
1317
</div>
@@ -18,7 +22,7 @@
1822
<div
1923
ref="loadingbar"
2024
:class="$style.loadingBar"
21-
:style="barBackgroundColor"
25+
:style="{ backgroundColor: color }"
2226
/>
2327
</div>
2428
</slot>
@@ -31,9 +35,8 @@ export default {
3135
name: "VuePreloader",
3236
props: {
3337
backgroundColor: VueTypes.string.def('#091a28'),
34-
barColor: VueTypes.string.def('#ffffff'),
35-
percentColor: VueTypes.string.def('#ffffff'),
36-
percentSpeed: VueTypes.number.def(15),
38+
color: VueTypes.string.def('#ffffff'),
39+
loadingSpeed: VueTypes.number.def(15),
3740
transitionOn: VueTypes.bool.def(true),
3841
transitionSpeed: VueTypes.number.def(1400)
3942
},
@@ -43,16 +46,14 @@ export default {
4346
};
4447
},
4548
computed: {
46-
barBackgroundColor() {
47-
return `background-color: ${this.barColor};`;
49+
preloaderBackgroundColor() {
50+
return { backgroundColor: this.backgroundColor };
4851
},
49-
percentBackgroundColor() {
50-
return `color: ${this.percentColor};`;
52+
preloaderTransition() {
53+
return { transition: `all ${this.transitionSpeed}ms ease-in-out` };
5154
},
52-
preloader() {
53-
return this.percent >= 100
54-
? `width: 0%; background-color: ${this.backgroundColor}; transition: all ${this.transitionSpeed}ms ease-in-out`
55-
: `background-color: ${this.backgroundColor}; transition: all ${this.transitionSpeed}ms ease-in-out`;
55+
preloaderWidth() {
56+
return this.percent >= 100 ? { width: '0%' } : '';
5657
}
5758
},
5859
watch: {
@@ -62,20 +63,20 @@ export default {
6263
setTimeout(() => {
6364
this.percent = percent += 1
6465
this.$refs.loadingbar.style.width = `${this.percent}%`
65-
}, this.percentSpeed)
66+
}, this.loadingSpeed)
6667
} else {
6768
this.transitionIsOver()
6869
}
6970
},
7071
},
7172
},
7273
methods: {
73-
setOverflowHidden() {
74-
document.body.style.overflow = 'hidden'
75-
},
7674
setOverflowAuto() {
7775
document.body.style.overflow = 'auto'
7876
},
77+
setOverflowHidden() {
78+
document.body.style.overflow = 'hidden'
79+
},
7980
transitionIsOver() {
8081
setTimeout(() => {
8182
this.$emit('finish-loading')

0 commit comments

Comments
 (0)