2019-08-14 09:48:44 +00:00
|
|
|
/* eslint no-unused-vars: ["error", { "args": "none" }] */
|
|
|
|
/* eslint prefer-template: 0 */
|
|
|
|
/* eslint no-console: 0 */
|
|
|
|
/* eslint func-names: 0 */
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
const that = this;
|
|
|
|
new TWEEN.Tween({ tweeningNumber: oldValue })
|
|
|
|
.easing(TWEEN.Easing.Quadratic.Out)
|
|
|
|
.to({ tweeningNumber: newValue }, 500)
|
2019-08-21 07:29:56 +00:00
|
|
|
.onUpdate(function() {
|
2019-08-14 09:48:44 +00:00
|
|
|
that.animatedNumber = this.tweeningNumber.toFixed(0);
|
|
|
|
})
|
|
|
|
.onComplete(() => {
|
|
|
|
window.cancelAnimationFrame(animationFrame);
|
|
|
|
})
|
|
|
|
.start();
|
|
|
|
animationFrame = window.requestAnimationFrame(animate);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
render(h) {
|
|
|
|
return (
|
2019-08-21 07:29:56 +00:00
|
|
|
<li
|
|
|
|
class={{
|
|
|
|
'tabs-title': true,
|
|
|
|
'is-active': this.active,
|
|
|
|
'uk-disabled': this.disabled,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
on-click={event => {
|
|
|
|
event.preventDefault();
|
|
|
|
if (!this.disabled) {
|
|
|
|
this.$parent.$emit('change', this.index);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2020-03-22 06:14:40 +00:00
|
|
|
{`${this.name}`}
|
|
|
|
<span class="badge">{this.getItemCount}</span>
|
2019-08-14 09:48:44 +00:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|