chore: Add showBadge prop to tabs-item component (#1096)

This commit is contained in:
Pranav Raj S
2020-07-26 17:46:29 +05:30
committed by GitHub
parent 89ed0b425b
commit 703027b834
2 changed files with 34 additions and 35 deletions

View File

@@ -1,5 +1,3 @@
/* eslint no-unused-vars: ["error", { "args": "none" }] */
export default { export default {
name: 'WootTabs', name: 'WootTabs',
props: { props: {
@@ -8,7 +6,7 @@ export default {
default: 0, default: 0,
}, },
}, },
render(h) { render() {
const Tabs = this.$slots.default const Tabs = this.$slots.default
.filter( .filter(
node => node =>

View File

@@ -1,7 +1,19 @@
/* eslint no-unused-vars: ["error", { "args": "none" }] */ <template>
/* eslint prefer-template: 0 */ <li
/* eslint no-console: 0 */ :class="{
/* eslint func-names: 0 */ 'tabs-title': true,
'is-active': active,
}"
>
<a @click="onTabClick">
{{ name }}
<span v-if="showBadge" class="badge">
{{ getItemCount }}
</span>
</a>
</li>
</template>
<script>
import TWEEN from 'tween.js'; import TWEEN from 'tween.js';
export default { export default {
@@ -23,6 +35,10 @@ export default {
type: Number, type: Number,
default: 0, default: 0,
}, },
showBadge: {
type: Boolean,
default: true,
},
}, },
data() { data() {
@@ -48,12 +64,12 @@ export default {
TWEEN.update(time); TWEEN.update(time);
animationFrame = window.requestAnimationFrame(animate); animationFrame = window.requestAnimationFrame(animate);
}; };
const that = this; const tweeningNumber = { value: oldValue };
new TWEEN.Tween({ tweeningNumber: oldValue }) new TWEEN.Tween(tweeningNumber)
.easing(TWEEN.Easing.Quadratic.Out) .easing(TWEEN.Easing.Quadratic.Out)
.to({ tweeningNumber: newValue }, 500) .to({ value: newValue }, 500)
.onUpdate(function() { .onUpdate(() => {
that.animatedNumber = this.tweeningNumber.toFixed(0); this.animatedNumber = tweeningNumber.value.toFixed(0);
}) })
.onComplete(() => { .onComplete(() => {
window.cancelAnimationFrame(animationFrame); window.cancelAnimationFrame(animationFrame);
@@ -62,28 +78,13 @@ export default {
animationFrame = window.requestAnimationFrame(animate); animationFrame = window.requestAnimationFrame(animate);
}, },
}, },
methods: {
render(h) { onTabClick(event) {
return ( event.preventDefault();
<li if (!this.disabled) {
class={{ this.$parent.$emit('change', this.index);
'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);
}
}}
>
{`${this.name}`}
<span class="badge">{this.getItemCount}</span>
</a>
</li>
);
}, },
}; };
</script>