Skip to content

Commit 70b3aa2

Browse files
Samuell1marcosmoura
authored andcommitted
feat(MdRipple): multiple waves (#1419)
* feat(MdRipple): multiple waves * feat(MdRipple): add transition-group to remove ripple after transition * feat(MdRipple): changed handling of clearing waves * feat(MdRipple): move debounce to utils
1 parent af0dc0a commit 70b3aa2

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

src/components/MdRipple/MdRipple.vue

+21-24
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
<template>
22
<div
3-
class="md-ripple"
4-
:class="rippleClasses"
3+
:class="['md-ripple', rippleClasses]"
54
@touchstart.passive.stop="touchStartCheck"
65
@touchmove.passive.stop="touchMoveCheck"
7-
@mousedown.passive.stop="startRipple">
6+
@touchend.passive.stop="clearWave"
7+
@mousedown.passive.stop="startRipple"
8+
@mouseup.passive.stop="clearWave">
89
<slot />
910

10-
<transition name="md-ripple" @after-enter="clearWave" v-if="!isDisabled">
11-
<span class="md-ripple-wave" :class="waveClasses" :style="waveStyles" v-if="animating" ref="rippleWave" />
12-
</transition>
11+
<transition-group name="md-ripple" v-if="!isDisabled">
12+
<span v-for="(ripple, index) in ripples" :key="'ripple'+index" :class="['md-ripple-wave', waveClasses]" :style="ripple.waveStyles" />
13+
</transition-group>
1314
</div>
1415
</template>
1516

1617
<script>
1718
import raf from 'raf'
1819
import MdComponent from 'core/MdComponent'
20+
import debounce from 'core/utils/MdDebounce'
1921
2022
export default new MdComponent({
2123
name: 'MdRipple',
@@ -25,10 +27,9 @@
2527
mdCentered: Boolean
2628
},
2729
data: () => ({
28-
eventType: null,
29-
waveStyles: null,
30-
animating: false,
31-
touchTimeout: null
30+
ripples: [],
31+
touchTimeout: null,
32+
eventType: null
3233
}),
3334
computed: {
3435
isDisabled () {
@@ -84,29 +85,26 @@
8485
position = this.getHitPosition($event, size)
8586
}
8687
87-
await this.clearWave()
88-
8988
this.eventType = $event.type
90-
this.animating = true
91-
this.applyStyles(position, size)
89+
this.ripples.push({
90+
animating: true,
91+
waveStyles: this.applyStyles(position, size)
92+
})
9293
}
9394
})
9495
},
9596
applyStyles (position, size) {
9697
size += 'px'
9798
98-
this.waveStyles = {
99+
return {
99100
...position,
100101
width: size,
101102
height: size
102103
}
103104
},
104-
clearWave () {
105-
this.waveStyles = null
106-
this.animating = false
107-
108-
return this.$nextTick()
109-
},
105+
clearWave: debounce(function () {
106+
this.ripples = []
107+
}, 2000),
110108
getSize () {
111109
const { offsetWidth, offsetHeight } = this.$el
112110
@@ -161,11 +159,11 @@
161159
transform: scale(2) translateZ(0);
162160
163161
&.md-centered {
162+
animation-duration: 1.2s;
164163
top: 50%;
165164
left: 50%;
166165
}
167-
168-
~ * {
166+
~ *:not(.md-ripple-wave) {
169167
position: relative;
170168
z-index: 2;
171169
}
@@ -175,7 +173,6 @@
175173
transition: .8s $md-transition-stand-timing;
176174
transition-property: opacity, transform;
177175
will-change: opacity, transform;
178-
179176
&.md-centered {
180177
transition-duration: 1.2s;
181178
}

src/core/utils/MdDebounce.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default (fn, time) => {
2+
let timeout
3+
return function() {
4+
const functionCall = () => fn.apply(this, arguments)
5+
clearTimeout(timeout)
6+
timeout = setTimeout(functionCall, time)
7+
}
8+
}

0 commit comments

Comments
 (0)