woodpecker/web/src/components/layout/scaffold/Tab.vue
Divya Jain d785d05718
Use pipeline wrapper and improve scaffold UI (#1368)
Co-authored-by: Anbraten <anton@ju60.de>
Co-authored-by: 6543 <6543@obermui.de>
2022-11-15 10:13:52 +01:00

36 lines
823 B
Vue

<template>
<div v-if="$slots.default" v-show="isActive" :aria-hidden="!isActive">
<slot />
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { Tab, useTabsClient } from '~/compositions/useTabs';
export interface Props {
id?: string;
title: string;
}
const props = defineProps<Props>();
const { tabs, activeTab } = useTabsClient();
const tab = ref<Tab>();
onMounted(() => {
tab.value = {
id: props.id || props.title.toLocaleLowerCase().replace(' ', '-') || tabs.value.length.toString(),
title: props.title,
};
// don't add tab if tab id is already present
if (!tabs.value.find(({ id }) => id === props.id)) {
tabs.value.push(tab.value);
}
});
const isActive = computed(() => tab.value && tab.value.id === activeTab.value);
</script>