2020-07-26 12:16:29 +00:00
|
|
|
<template>
|
|
|
|
<li
|
|
|
|
:class="{
|
|
|
|
'tabs-title': true,
|
|
|
|
'is-active': active,
|
|
|
|
}"
|
|
|
|
>
|
|
|
|
<a @click="onTabClick">
|
|
|
|
{{ name }}
|
|
|
|
<span v-if="showBadge" class="badge">
|
|
|
|
{{ getItemCount }}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
<script>
|
2019-08-14 09:48:44 +00:00
|
|
|
import TWEEN from 'tween.js';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'WootTabsItem',
|
|
|
|
props: {
|
|
|
|
index: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
count: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
|
|
|
},
|
2020-07-26 12:16:29 +00:00
|
|
|
showBadge: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
animatedNumber: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
active() {
|
|
|
|
return this.index === this.$parent.index;
|
|
|
|
},
|
|
|
|
|
|
|
|
getItemCount() {
|
|
|
|
return this.animatedNumber || this.count;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
count(newValue, oldValue) {
|
|
|
|
let animationFrame;
|
2019-08-21 07:29:56 +00:00
|
|
|
const animate = time => {
|
2019-08-14 09:48:44 +00:00
|
|
|
TWEEN.update(time);
|
|
|
|
animationFrame = window.requestAnimationFrame(animate);
|
|
|
|
};
|
2020-07-26 12:16:29 +00:00
|
|
|
const tweeningNumber = { value: oldValue };
|
|
|
|
new TWEEN.Tween(tweeningNumber)
|
2019-08-14 09:48:44 +00:00
|
|
|
.easing(TWEEN.Easing.Quadratic.Out)
|
2020-07-26 12:16:29 +00:00
|
|
|
.to({ value: newValue }, 500)
|
|
|
|
.onUpdate(() => {
|
|
|
|
this.animatedNumber = tweeningNumber.value.toFixed(0);
|
2019-08-14 09:48:44 +00:00
|
|
|
})
|
|
|
|
.onComplete(() => {
|
|
|
|
window.cancelAnimationFrame(animationFrame);
|
|
|
|
})
|
|
|
|
.start();
|
|
|
|
animationFrame = window.requestAnimationFrame(animate);
|
|
|
|
},
|
|
|
|
},
|
2020-07-26 12:16:29 +00:00
|
|
|
methods: {
|
|
|
|
onTabClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
if (!this.disabled) {
|
|
|
|
this.$parent.$emit('change', this.index);
|
|
|
|
}
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
};
|
2020-07-26 12:16:29 +00:00
|
|
|
</script>
|