Skip to content

Commit a9f1f79

Browse files
committed
improve transitions
1 parent 477a144 commit a9f1f79

File tree

2 files changed

+94
-22
lines changed

2 files changed

+94
-22
lines changed

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If you are a **try and learn** developer, you can start trying the **vue-wait**
2929
```bash
3030
yarn add vue-wait
3131
```
32-
32+
3333
### 2. Require:
3434
```js
3535
import VueWait from 'vue-wait'
@@ -69,9 +69,9 @@ new Vue({
6969
async created() {
7070
// start waiting
7171
this.$wait.start('my list is to load');
72-
72+
7373
this.myList = await fetch('/my-list-url');
74-
74+
7575
// stop waiting
7676
this.$wait.end('my list is to load');
7777
},
@@ -434,7 +434,7 @@ import { mapWaitingActions, mapWaitingGetters } from 'vue-wait'
434434
createUser: { action: 'createUser', loader: 'creating user'},
435435
createSuperUser: { action: 'createUser', loader: 'creating super user' },
436436
}),
437-
},
437+
},
438438
// ...
439439
```
440440

@@ -447,7 +447,7 @@ There is also possibility to use array as a second argument to mapWaitingActions
447447
{ method: 'createUser', action: 'createUser', loader: 'creating user'},
448448
{ method: 'createSuperUser', action: 'createUser', loader: 'creating super user' },
449449
]),
450-
},
450+
},
451451
// ...
452452

453453

@@ -541,6 +541,27 @@ Better example for a `button` with loading state:
541541
</button>
542542
```
543543

544+
## 🔁 Transitions
545+
546+
You can use transitions with `v-wait` component.
547+
548+
Just pass `<transition>` props and listeners to the `v-wait` with `transition` prop.
549+
550+
```vue
551+
<v-wait for="users"
552+
transition="fade"
553+
mode="out-in"
554+
:duration="1000"
555+
enter-active-class="enter-active"
556+
@leave='someAwesomeFinish()'
557+
>
558+
<template slot="waiting">
559+
<p>Loading...</p>
560+
</template>
561+
My content
562+
</v-wait>
563+
```
564+
544565
## ⚡️ Making Reusable Loader Components
545566

546567
With reusable loader components, you will be able to use custom loader components as example below. This will allow you to create better **user loading experience**.

src/components/v-wait.vue

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<template lang="html">
2-
<transition :name='transition' :mode='mode'>
2+
<transition
3+
:name='transition'
4+
:mode='mode'
5+
:duration='duration'
6+
:enter-class='transitionClass(enterClass)'
7+
:enter-active-class='transitionClass(enterActiveClass)'
8+
:enter-to-class='transitionClass(enterToClass)'
9+
:leave-class='transitionClass(leaveClass)'
10+
:leave-active-class='transitionClass(leaveActiveClass)'
11+
:leave-to-class='transitionClass(leaveToClass)'
12+
@beforeEnter='$emit("beforeEnter")'
13+
@enter='$emit("enter")'
14+
@afterAnter='$emit("afterEnter")'
15+
@enterCancelled='$emit("enterCancelled")'
16+
@beforeLeave='$emit("beforeLeave")'
17+
@leave='$emit("leave")'
18+
@afterLeave='$emit("afterLeave")'
19+
@leaveCancelled='$emit("leaveCancelled")'
20+
>
321
<span v-if='waitsFor'>
422
<slot name='waiting'></slot>
523
<span v-if='message'>{{ message }}</span>
@@ -8,24 +26,57 @@
826
</transition>
927
</template>
1028
<script>
11-
export default {
12-
props: {
13-
visible: Boolean,
14-
transition: String,
15-
mode: String,
16-
for: String,
17-
message: String,
29+
export default {
30+
props: {
31+
visible: Boolean,
32+
for: String,
33+
message: String,
34+
transition: String,
35+
duration: Number,
36+
mode: {
37+
type: String,
38+
default: 'out-in'
1839
},
19-
computed: {
20-
waitsFor() {
21-
if (this.visible) {
22-
return this.visible;
23-
}
24-
if (this.for) {
25-
return this.__$waitInstance.is(this.for);
26-
}
27-
return this.__$waitInstance.any;
40+
enterClass: {
41+
type: String,
42+
default: 'enter'
43+
},
44+
enterActiveClass: {
45+
type: String,
46+
default: 'enter-active'
47+
},
48+
enterToClass: {
49+
type: String,
50+
default: 'enter-to'
51+
},
52+
leaveClass: {
53+
type: String,
54+
default: 'leave'
55+
},
56+
leaveActiveClass: {
57+
type: String,
58+
default: 'leave-active'
59+
},
60+
leaveToClass: {
61+
type: String,
62+
default: 'leave-to'
63+
},
64+
},
65+
methods: {
66+
transitionClass(className) {
67+
return `${this.transition}-${className}`;
68+
}
69+
},
70+
computed: {
71+
waitsFor() {
72+
if (this.visible) {
73+
return this.visible;
74+
}
75+
if (this.for) {
76+
return this.__$waitInstance.is(this.for);
2877
}
78+
return this.__$waitInstance.any;
2979
}
3080
}
81+
};
3182
</script>

0 commit comments

Comments
 (0)