Welcome to mirror list, hosted at ThFree Co, Russian Federation.

top_nav_menu_sections.vue « components « nav « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 97e63c7324e45d2edc1170976a452256b260c5be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<script>
import TopNavMenuItem from './top_nav_menu_item.vue';

const BORDER_CLASSES = 'gl-pt-3 gl-border-1 gl-border-t-solid gl-border-gray-50';

export default {
  components: {
    TopNavMenuItem,
  },
  props: {
    sections: {
      type: Array,
      required: true,
    },
    withTopBorder: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  methods: {
    onClick(menuItem) {
      // If we're a link, let's just do the default behavior so the view won't change
      if (menuItem.href) {
        return;
      }

      this.$emit('menu-item-click', menuItem);
    },
    getMenuSectionClasses(index) {
      // This is a method instead of a computed so we don't have to incur the cost of
      // creating a whole new array/object.
      return {
        [BORDER_CLASSES]: this.withTopBorder || index > 0,
        'gl-mt-3': index > 0,
      };
    },
  },
  // Expose for unit tests
  BORDER_CLASSES,
};
</script>

<template>
  <div class="gl-display-flex gl-align-items-stretch gl-flex-direction-column">
    <div
      v-for="({ id, menuItems }, sectionIndex) in sections"
      :key="id"
      :class="getMenuSectionClasses(sectionIndex)"
      data-testid="menu-section"
    >
      <template v-for="(menuItem, menuItemIndex) in menuItems">
        <strong
          v-if="menuItem.type == 'header'"
          :key="menuItem.title"
          class="gl-px-4 gl-py-2 gl-text-gray-900 gl-display-block"
          :class="{ 'gl-pt-3!': menuItemIndex > 0 }"
          data-testid="menu-header"
        >
          {{ menuItem.title }}
        </strong>
        <top-nav-menu-item
          v-else
          :key="menuItem.id"
          :menu-item="menuItem"
          data-testid="menu-item"
          class="gl-w-full"
          :class="{ 'gl-mt-1': menuItemIndex > 0 }"
          @click="onClick(menuItem)"
        />
      </template>
    </div>
  </div>
</template>