2020-05-21 11:08:18 -04:00
|
|
|
<script>
|
|
|
|
import { GlTooltipDirective, GlIcon } from '@gitlab/ui';
|
2021-02-02 19:09:41 -05:00
|
|
|
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
|
2020-05-21 11:08:18 -04:00
|
|
|
import { SIDE_RIGHT } from '../constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { otherSide } from '../utils';
|
2020-05-21 11:08:18 -04:00
|
|
|
|
|
|
|
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) {
|
2020-12-23 19:10:25 -05:00
|
|
|
return this.isOpen && tab.views.some((view) => view.name === this.currentView);
|
2020-05-21 11:08:18 -04:00
|
|
|
},
|
|
|
|
buttonClasses(tab) {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
'is-right': this.side === SIDE_RIGHT,
|
|
|
|
active: this.isActiveTab(tab),
|
|
|
|
},
|
|
|
|
...(tab.buttonClasses || []),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
clickTab(e, tab) {
|
|
|
|
e.currentTarget.blur();
|
2021-02-02 19:09:41 -05:00
|
|
|
this.$root.$emit(BV_HIDE_TOOLTIP);
|
2020-05-21 11:08:18 -04:00
|
|
|
|
|
|
|
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>
|