54 lines
1.4 KiB
Vue
54 lines
1.4 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from "vue";
|
|
import { TabsContent, useForwardExpose } from "reka-ui";
|
|
import { useTabs, tabsWireKey, type TabsKey } from "./context";
|
|
defineOptions({ inheritAttrs: false });
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
value?: TabsKey;
|
|
id?: TabsKey;
|
|
as?: string;
|
|
shouldForceMount?: boolean;
|
|
}>(),
|
|
{ as: "div", shouldForceMount: false },
|
|
);
|
|
const ctx = useTabs();
|
|
const value = computed(() => {
|
|
const v = props.value ?? props.id;
|
|
if (v === undefined)
|
|
throw new Error("TabsPanel requires value (or id alias).");
|
|
return v;
|
|
});
|
|
const { forwardRef } = useForwardExpose();
|
|
</script>
|
|
<template>
|
|
<TabsContent
|
|
:ref="forwardRef"
|
|
v-bind="$attrs"
|
|
:value="tabsWireKey(value)"
|
|
as-child
|
|
:as="as"
|
|
:force-mount="shouldForceMount"
|
|
:hidden="ctx.selected.value !== value"
|
|
class="hv-tabs__panel"
|
|
data-slot="tabs-panel"
|
|
:data-orientation="ctx.orientation.value"
|
|
>
|
|
<component
|
|
:is="as"
|
|
:id="ctx.domId('panel', value)"
|
|
:hidden="ctx.selected.value !== value"
|
|
:aria-labelledby="
|
|
'aria-labelledby' in $attrs
|
|
? ($attrs['aria-labelledby'] as string)
|
|
: ctx.domId('tab', value)
|
|
"
|
|
>
|
|
<slot
|
|
v-if="shouldForceMount || ctx.selected.value === value"
|
|
:is-selected="ctx.selected.value === value"
|
|
/>
|
|
</component>
|
|
</TabsContent>
|
|
</template>
|