42 lines
1.3 KiB
Vue
42 lines
1.3 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from "vue";
|
|
import { useTabs, useTabKey } from "./context";
|
|
defineOptions({ inheritAttrs: false });
|
|
withDefaults(defineProps<{ as?: string }>(), { as: "span" });
|
|
const ctx = useTabs(),
|
|
key = useTabKey();
|
|
const selected = computed(() => ctx.selected.value === key.value);
|
|
const style = computed(() => {
|
|
const active =
|
|
ctx.selected.value === undefined
|
|
? undefined
|
|
: ctx.boxes.value.get(ctx.selected.value);
|
|
const own = ctx.boxes.value.get(key.value);
|
|
const secondary = ctx.variant.value === "secondary",
|
|
vertical = ctx.orientation.value === "vertical";
|
|
return {
|
|
visibility: selected.value ? ("visible" as const) : ("hidden" as const),
|
|
transition: ctx.ready.value ? undefined : "none",
|
|
...(active && own
|
|
? {
|
|
translate: `${ctx.dir.value === "rtl" ? active.x + active.width - own.x - own.width : active.x - own.x}px ${active.y - own.y}px`,
|
|
width: secondary && vertical ? undefined : `${active.width}px`,
|
|
height: secondary && !vertical ? undefined : `${active.height}px`,
|
|
}
|
|
: {}),
|
|
};
|
|
});
|
|
</script>
|
|
<template>
|
|
<component
|
|
:is="as"
|
|
v-bind="$attrs"
|
|
class="hv-tabs__indicator"
|
|
data-slot="tabs-indicator"
|
|
aria-hidden="true"
|
|
:style="style"
|
|
>
|
|
<slot />
|
|
</component>
|
|
</template>
|