summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/nav/components/top_nav_menu_item.vue
blob: 08b2fbf2ed1ca6ed8173ae3979462d1447ba0f4f (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
<script>
import { GlButton, GlIcon } from '@gitlab/ui';
import { kebabCase, mapKeys } from 'lodash';

const getDataKey = (key) => `data-${kebabCase(key)}`;

const ACTIVE_CLASS = 'gl-shadow-none! gl-font-weight-bold! active';

export default {
  components: {
    GlButton,
    GlIcon,
  },
  props: {
    menuItem: {
      type: Object,
      required: true,
    },
    iconOnly: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  computed: {
    dataAttrs() {
      return mapKeys(this.menuItem.data || {}, (value, key) => getDataKey(key));
    },
  },
  ACTIVE_CLASS,
};
</script>

<template>
  <gl-button
    category="tertiary"
    :href="menuItem.href"
    class="top-nav-menu-item gl-display-block"
    :class="[menuItem.css_class, { [$options.ACTIVE_CLASS]: menuItem.active }]"
    :aria-label="menuItem.title"
    v-bind="dataAttrs"
    v-on="$listeners"
  >
    <span class="gl-display-flex">
      <gl-icon v-if="menuItem.icon" :name="menuItem.icon" :class="{ 'gl-mr-2!': !iconOnly }" />
      <template v-if="!iconOnly">
        {{ menuItem.title }}
        <gl-icon v-if="menuItem.view" name="chevron-right" class="gl-ml-auto" />
      </template>
    </span>
  </gl-button>
</template>