debian-mirror-gitlab/app/assets/javascripts/vue_shared/components/navigation_tabs.vue

78 lines
1.6 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2018-10-15 14:42:47 +05:30
import $ from 'jquery';
2018-05-09 12:01:36 +05:30
2018-10-15 14:42:47 +05:30
/**
* Given an array of tabs, renders non linked bootstrap tabs.
* When a tab is clicked it will trigger an event and provide the clicked scope.
*
* This component is used in apps that handle the API call.
* If you only need to change the URL this component should not be used.
*
* @example
* <navigation-tabs
* :tabs="[
* {
* name: String,
* scope: String,
* count: Number || Undefined || Null,
* isActive: Boolean,
* },
* ]"
* @onChangeTab="onChangeTab"
* />
*/
export default {
name: 'NavigationTabs',
props: {
tabs: {
type: Array,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-10-15 14:42:47 +05:30
scope: {
type: String,
required: false,
default: '',
},
},
mounted() {
$(document).trigger('init.scrolling-tabs');
},
methods: {
shouldRenderBadge(count) {
// 0 is valid in a badge, but evaluates to false, we need to check for undefined or null
return !(count === undefined || count === null);
2018-03-17 18:26:18 +05:30
},
2018-10-15 14:42:47 +05:30
onTabClick(tab) {
this.$emit('onChangeTab', tab.scope);
2018-03-17 18:26:18 +05:30
},
2018-10-15 14:42:47 +05:30
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<ul class="nav-links scrolling-tabs separator">
<li
v-for="(tab, i) in tabs"
:key="i"
:class="{
active: tab.isActive,
}"
>
<a
role="button"
@click="onTabClick(tab)"
:class="`js-${scope}-tab-${tab.scope}`"
>
{{ tab.name }}
<span
v-if="shouldRenderBadge(tab.count)"
class="badge"
>
{{ tab.count }}
</span>
</a>
</li>
</ul>
</template>