woodpecker/web/src/components/tabs/Tabs.vue
Anbraten 58838f225c
Rewrite of WebUI (#245)
Rewrite of the UI using Typescript, Vue3, Windicss and Vite. The design should  be close to the current one with some changes:
- latest pipeline in a sidebar on the right
- secrets and registry as part of the repo-settings (secrets and registry entries shouldn't be used as much so they can be "hidden" under settings IMO)
- start page shows list of active repositories with button to enable / add new ones (currently you see all repositories and in most cases you only add new repositories once in a while)
2021-11-03 17:40:31 +01:00

108 lines
2.3 KiB
Vue

<template>
<div class="flex flex-col">
<div class="flex w-full pt-4 mb-4">
<div
v-for="tab in tabs"
:key="tab.id"
class="
flex
cursor-pointer
pb-2
px-8
border-b-2
text-gray-500
hover:text-gray-700
dark:text-gray-500 dark:hover:text-gray-400
"
:class="{
'border-gray-400 dark:border-gray-600': activeTab === tab.id,
'border-transparent': activeTab !== tab.id,
}"
@click="selectTab(tab)"
>
<span>{{ tab.title }}</span>
</div>
</div>
<div>
<slot />
</div>
</div>
</template>
<script lang="ts">
import { computed, defineComponent, onMounted, provide, ref, toRef } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { Tab } from './types';
export default defineComponent({
name: 'Tabs',
props: {
// used by toRef
// eslint-disable-next-line vue/no-unused-properties
disableHashMode: {
type: Boolean,
},
// used by toRef
// eslint-disable-next-line vue/no-unused-properties
modelValue: {
type: String,
default: '',
},
},
emits: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
'update:modelValue': (_value: string): boolean => true,
},
setup(props, { emit }) {
const router = useRouter();
const route = useRoute();
const disableHashMode = toRef(props, 'disableHashMode');
const modelValue = toRef(props, 'modelValue');
const tabs = ref<Tab[]>([]);
const activeTab = ref();
provide('tabs', tabs);
provide(
'active-tab',
computed(() => activeTab.value),
);
async function selectTab(tab: Tab) {
if (tab.id === undefined) {
return;
}
activeTab.value = tab.id;
emit('update:modelValue', activeTab.value);
if (!disableHashMode.value) {
await router.replace({ params: route.params, hash: `#${tab.id}` });
}
}
onMounted(() => {
if (modelValue.value) {
activeTab.value = modelValue.value;
return;
}
const hashTab = route.hash.replace(/^#/, '');
if (hashTab) {
activeTab.value = hashTab;
return;
}
activeTab.value = tabs.value[0].id;
});
return { tabs, activeTab, selectTab };
},
});
</script>