debian-mirror-gitlab/app/assets/javascripts/ide/components/ide_sidebar_nav.vue

85 lines
1.8 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
import { GlTooltipDirective, GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
2020-06-23 00:09:42 +05:30
import { SIDE_RIGHT } from '../constants';
2021-03-11 19:13:27 +05:30
import { otherSide } from '../utils';
2020-06-23 00:09:42 +05:30
export default {
directives: {
tooltip: GlTooltipDirective,
},
components: {
GlIcon,
},
props: {
tabs: {
type: Array,
required: true,
},
side: {
type: String,
required: true,
},
currentView: {
type: String,
required: false,
default: '',
},
isOpen: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
otherSide() {
return otherSide(this.side);
},
},
methods: {
isActiveTab(tab) {
2021-03-08 18:12:59 +05:30
return this.isOpen && tab.views.some((view) => view.name === this.currentView);
2020-06-23 00:09:42 +05:30
},
buttonClasses(tab) {
return [
{
'is-right': this.side === SIDE_RIGHT,
active: this.isActiveTab(tab),
},
...(tab.buttonClasses || []),
];
},
clickTab(e, tab) {
e.currentTarget.blur();
2021-03-11 19:13:27 +05:30
this.$root.$emit(BV_HIDE_TOOLTIP);
2020-06-23 00:09:42 +05:30
if (this.isActiveTab(tab)) {
this.$emit('close');
} else {
this.$emit('open', tab.views[0]);
}
},
},
};
</script>
<template>
<nav class="ide-activity-bar">
<ul class="list-unstyled">
<li v-for="tab of tabs" :key="tab.title">
<button
v-tooltip="{ container: 'body', placement: otherSide }"
:title="tab.title"
:aria-label="tab.title"
:class="buttonClasses(tab)"
:data-qa-selector="`${tab.title.toLowerCase()}_tab_button`"
class="ide-sidebar-link"
type="button"
@click="clickTab($event, tab)"
>
<gl-icon :size="16" :name="tab.icon" />
</button>
</li>
</ul>
</nav>
</template>