Skip to content

Commit 90e9fdc

Browse files
author
reco_luan
committed
refactor(vuepress-theme-reco): module transition
1 parent 5205fce commit 90e9fdc

File tree

4 files changed

+26
-30
lines changed

4 files changed

+26
-30
lines changed

packages/@vuepress-reco/core/src/components/ModuleTransition.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Vue from 'vue';
22
import Component from 'vue-class-component';
33

4-
import '../../stylus/ModuleTransition.styl'
5-
64
const ModuleTransitionProps = Vue.extend({
75
props: {
86
delay: {
@@ -12,20 +10,26 @@ const ModuleTransitionProps = Vue.extend({
1210
duration: {
1311
type: String,
1412
default: '.25'
13+
},
14+
transform: {
15+
type: Array,
16+
default () {
17+
return ['translateY(-20px)', 'translateY(0)']
18+
}
1519
}
1620
}
1721
})
1822

1923
@Component
2024
class ModuleTransition extends ModuleTransitionProps {
2125
setStyle (items) {
22-
items.style.transition = `all ${this.duration}s ease-in-out ${this.delay}s`
23-
items.style.transform = 'translateY(-20px)'
26+
items.style.transition = `transform ${this.duration}s ease-in-out ${this.delay}s, opacity ${this.duration}s ease-in-out ${this.delay}s`
27+
items.style.transform = this.transform[0]
2428
items.style.opacity = 0
2529
}
2630

2731
unsetStyle (items) {
28-
items.style.transform = 'translateY(0)'
32+
items.style.transform = this.transform[1]
2933
items.style.opacity = 1
3034
}
3135

@@ -34,13 +38,13 @@ class ModuleTransition extends ModuleTransitionProps {
3438
<transition
3539
{
3640
...{
37-
attrs: {
38-
name: 'module'
39-
},
41+
attrs: { name: 'module' },
4042
on: {
4143
enter: this.setStyle,
42-
'after-enter': this.unsetStyle,
43-
'before-leave': this.setStyle
44+
appear: this.setStyle,
45+
'before-leave': this.setStyle,
46+
'after-appear': this.unsetStyle,
47+
'after-enter': this.unsetStyle
4448
}
4549
}
4650
}

packages/@vuepress-reco/core/stylus/ModuleTransition.styl

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/vuepress-theme-reco/components/Mode/index.vue

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
<a class="color-button" @click.prevent="showMenu = !showMenu">
44
<reco-icon icon="reco-color" />
55
</a>
6-
<transition name="menu-transition" mode="out-in">
6+
<ModuleTransition :transform=" ['translate(-50%, 0)', 'translate(-50%, -10px)']">
77
<div v-show="showMenu" class="color-picker-menu">
88
<ModePicker />
99
</div>
10-
</transition>
10+
</ModuleTransition>
1111
</div>
1212
</template>
1313

1414
<script>
15-
import { RecoIcon } from '@vuepress-reco/core/lib/components'
15+
import { RecoIcon, ModuleTransition } from '@vuepress-reco/core/lib/components'
1616
import ClickOutside from 'vue-click-outside'
1717
import ModePicker from './ModePicker'
1818
import applyMode from './applyMode'
@@ -26,7 +26,8 @@ export default {
2626
2727
components: {
2828
ModePicker,
29-
RecoIcon
29+
RecoIcon,
30+
ModuleTransition
3031
},
3132
3233
data () {
@@ -80,17 +81,7 @@ export default {
8081
position: absolute;
8182
top: 40px;
8283
left: 50%;
83-
transform: translateX(-50%);
8484
z-index: 150;
85-
&.menu-transition-enter-active,
86-
&.menu-transition-leave-active {
87-
transition: all 0.25s ease-in-out;
88-
}
89-
&.menu-transition-enter,
90-
&.menu-transition-leave-to {
91-
top: 50px;
92-
opacity: 0;
93-
}
9485
9586
ul {
9687
list-style-type: none;

packages/vuepress-theme-reco/mixins/moduleTransiton.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ export default {
77
mounted () {
88
this.recoShowModule = true
99
},
10-
destroyed () {
11-
this.recoShowModule = false
10+
watch: {
11+
'$route' () {
12+
this.recoShowModule = false
13+
setTimeout(() => {
14+
this.recoShowModule = true
15+
}, 200)
16+
}
1217
}
1318
}

0 commit comments

Comments
 (0)