2018-03-17 18:26:18 +05:30
|
|
|
<script>
|
2021-03-08 18:12:59 +05:30
|
|
|
import { GlBadge, GlTabs, GlTab } from '@gitlab/ui';
|
2023-03-17 16:20:25 +05:30
|
|
|
import { initScrollingTabs } from '~/layout_nav';
|
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',
|
2021-03-08 18:12:59 +05:30
|
|
|
components: {
|
|
|
|
GlBadge,
|
|
|
|
GlTabs,
|
|
|
|
GlTab,
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
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() {
|
2023-03-17 16:20:25 +05:30
|
|
|
initScrollingTabs();
|
2018-10-15 14:42:47 +05:30
|
|
|
},
|
|
|
|
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>
|
2021-03-08 18:12:59 +05:30
|
|
|
<gl-tabs class="gl-display-flex gl-w-full" nav-class="gl-border-0!">
|
|
|
|
<gl-tab
|
2018-03-17 18:26:18 +05:30
|
|
|
v-for="(tab, i) in tabs"
|
|
|
|
:key="i"
|
2021-03-08 18:12:59 +05:30
|
|
|
:title-link-class="`js-${scope}-tab-${tab.scope} gl-display-inline-flex`"
|
2022-07-16 23:28:13 +05:30
|
|
|
:title-link-attributes="/* eslint-disable @gitlab/vue-no-new-non-primitive-in-template */ {
|
|
|
|
'data-testid': `${scope}-tab-${tab.scope}`,
|
|
|
|
} /* eslint-enable @gitlab/vue-no-new-non-primitive-in-template */"
|
2021-03-08 18:12:59 +05:30
|
|
|
:active="tab.isActive"
|
|
|
|
@click="onTabClick(tab)"
|
2018-03-17 18:26:18 +05:30
|
|
|
>
|
2021-03-08 18:12:59 +05:30
|
|
|
<template #title>
|
|
|
|
<span class="gl-mr-2"> {{ tab.name }} </span>
|
|
|
|
<gl-badge v-if="shouldRenderBadge(tab.count)" size="sm" class="gl-tab-counter-badge">{{
|
|
|
|
tab.count
|
|
|
|
}}</gl-badge>
|
|
|
|
</template>
|
|
|
|
</gl-tab>
|
|
|
|
</gl-tabs>
|
2018-03-17 18:26:18 +05:30
|
|
|
</template>
|