docs/.vitepress/theme/components/tabs/PluginTabsTab.vue
45 lines · 1124 bytes
1<script setup lang="ts">
2import { computed, inject, nextTick, watch } from 'vue'
3import { mediumZoomSymbol } from '../../composables/medium-zoom'
4import { useIsPrint } from './composables'
5import { useTabsRenderAll, useTabsSingleState } from './state'
6
7defineOptions({ name: 'PluginTabsTab' })
8
9const props = defineProps<{
10 anchor: string
11 label: string
12}>()
13
14const { selected, uid } = useTabsSingleState()
15const isPrint = useIsPrint()
16const renderAll = useTabsRenderAll()
17const isActive = computed(() =>
18 selected.value === props.label || Boolean(isPrint.value) || renderAll
19)
20
21const zoom = inject(mediumZoomSymbol)
22watch(isActive, async (active) => {
23 if (active) {
24 await nextTick()
25 zoom?.refresh()
26 }
27})
28const panelId = computed(() => `panel-${props.anchor}-${uid}`)
29const buttonId = computed(() => `tab-${props.anchor}-${uid}`)
30</script>
31
32<template>
33 <div
34 v-if="isActive"
35 :id="panelId"
36 class="plugin-tabs--content"
37 role="tabpanel"
38 tabindex="0"
39 :data-tab-anchor="anchor"
40 :aria-labelledby="buttonId"
41 :data-is-print="isPrint || undefined"
42 >
43 <slot />
44 </div>
45</template>