From 45631562565760add7a7c52a6137e891f3a0c8f4 Mon Sep 17 00:00:00 2001
From: Filipa Lacerda <filipa@gitlab.com>
Date: Thu, 23 Nov 2017 12:04:03 +0000
Subject: Improve environments performance

---
 .../vue_shared/components/navigation_tabs.vue      | 76 ++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 app/assets/javascripts/vue_shared/components/navigation_tabs.vue

(limited to 'app/assets/javascripts/vue_shared/components/navigation_tabs.vue')

diff --git a/app/assets/javascripts/vue_shared/components/navigation_tabs.vue b/app/assets/javascripts/vue_shared/components/navigation_tabs.vue
new file mode 100644
index 00000000000..a2ddd565170
--- /dev/null
+++ b/app/assets/javascripts/vue_shared/components/navigation_tabs.vue
@@ -0,0 +1,76 @@
+<script>
+  /**
+   * 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,
+   *      isActive: Boolean,
+   *    },
+   *   ]"
+   *   @onChangeTab="onChangeTab"
+   *   />
+   */
+  export default {
+    name: 'NavigationTabs',
+    props: {
+      tabs: {
+        type: Array,
+        required: true,
+      },
+      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
+        return count !== undefined;
+      },
+
+      onTabClick(tab) {
+        this.$emit('onChangeTab', tab.scope);
+      },
+    },
+};
+</script>
+<template>
+  <ul class="nav-links scrolling-tabs">
+    <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>
-- 
cgit v1.2.1

