2024-05-25 14:10:21 +00:00
|
|
|
<script setup lang="ts">
|
2024-08-16 14:20:18 +00:00
|
|
|
import type { TabsEmits, TabsProps } from './types';
|
2024-05-25 14:10:21 +00:00
|
|
|
|
2024-08-16 14:20:18 +00:00
|
|
|
import { useForwardPropsEmits } from '@vben-core/composables';
|
2024-08-15 15:30:07 +00:00
|
|
|
import { ChevronLeft, ChevronRight } from '@vben-core/icons';
|
2024-08-16 14:20:18 +00:00
|
|
|
import { VbenScrollbar } from '@vben-core/shadcn-ui';
|
2024-05-25 14:10:21 +00:00
|
|
|
|
2024-07-14 10:32:37 +00:00
|
|
|
import { Tabs, TabsChrome } from './components';
|
2024-08-16 14:20:18 +00:00
|
|
|
import { useTabsDrag } from './use-tabs-drag';
|
2024-08-15 15:30:07 +00:00
|
|
|
import { useTabsViewScroll } from './use-tabs-view-scroll';
|
2024-05-25 14:10:21 +00:00
|
|
|
|
|
|
|
interface Props extends TabsProps {}
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
name: 'TabsView',
|
|
|
|
});
|
|
|
|
|
2024-07-14 07:18:02 +00:00
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
contentClass: 'vben-tabs-content',
|
|
|
|
dragable: true,
|
2024-07-14 10:32:37 +00:00
|
|
|
styleType: 'chrome',
|
2024-07-14 07:18:02 +00:00
|
|
|
});
|
2024-05-25 14:10:21 +00:00
|
|
|
|
2024-08-16 14:20:18 +00:00
|
|
|
const emit = defineEmits<TabsEmits>();
|
2024-05-25 14:10:21 +00:00
|
|
|
|
|
|
|
const forward = useForwardPropsEmits(props, emit);
|
2024-07-14 07:18:02 +00:00
|
|
|
|
2024-08-16 14:20:18 +00:00
|
|
|
const {
|
|
|
|
handleScrollAt,
|
|
|
|
scrollbarRef,
|
|
|
|
scrollDirection,
|
|
|
|
scrollIsAtLeft,
|
|
|
|
scrollIsAtRight,
|
|
|
|
showScrollButton,
|
|
|
|
} = useTabsViewScroll(props);
|
2024-07-14 07:18:02 +00:00
|
|
|
|
2024-08-16 14:20:18 +00:00
|
|
|
useTabsDrag(props, emit);
|
2024-05-25 14:10:21 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-08-16 14:20:18 +00:00
|
|
|
<div class="flex h-full flex-1 overflow-hidden">
|
2024-08-15 15:30:07 +00:00
|
|
|
<!-- 左侧滚动按钮 -->
|
|
|
|
<span
|
2024-08-16 14:20:18 +00:00
|
|
|
v-show="showScrollButton"
|
|
|
|
:class="{
|
|
|
|
'hover:bg-muted text-muted-foreground cursor-pointer': !scrollIsAtLeft,
|
|
|
|
'pointer-events-none opacity-30': scrollIsAtLeft,
|
|
|
|
}"
|
|
|
|
class="border-r px-2"
|
2024-08-15 15:30:07 +00:00
|
|
|
@click="scrollDirection('left')"
|
|
|
|
>
|
|
|
|
<ChevronLeft class="size-4 h-full" />
|
|
|
|
</span>
|
|
|
|
|
2024-08-16 14:20:18 +00:00
|
|
|
<div
|
|
|
|
:class="{
|
|
|
|
'pt-[3px]': styleType === 'chrome',
|
|
|
|
}"
|
|
|
|
class="size-full flex-1 overflow-hidden"
|
|
|
|
>
|
|
|
|
<VbenScrollbar
|
|
|
|
ref="scrollbarRef"
|
2024-08-17 13:11:07 +00:00
|
|
|
:shadow-bottom="false"
|
|
|
|
:shadow-top="false"
|
2024-08-16 14:20:18 +00:00
|
|
|
class="h-full"
|
|
|
|
horizontal
|
2024-08-17 13:11:07 +00:00
|
|
|
scroll-bar-class="z-10 hidden "
|
2024-08-16 14:20:18 +00:00
|
|
|
shadow
|
|
|
|
shadow-left
|
|
|
|
shadow-right
|
|
|
|
@scroll-at="handleScrollAt"
|
|
|
|
>
|
|
|
|
<TabsChrome
|
|
|
|
v-if="styleType === 'chrome'"
|
|
|
|
v-bind="{ ...forward, ...$attrs, ...$props }"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Tabs v-else v-bind="{ ...forward, ...$attrs, ...$props }" />
|
|
|
|
</VbenScrollbar>
|
|
|
|
</div>
|
2024-08-15 15:30:07 +00:00
|
|
|
|
2024-08-21 10:27:34 +00:00
|
|
|
<!-- 右侧滚动按钮 -->
|
2024-08-15 15:30:07 +00:00
|
|
|
<span
|
2024-08-16 14:20:18 +00:00
|
|
|
v-show="showScrollButton"
|
|
|
|
:class="{
|
|
|
|
'hover:bg-muted text-muted-foreground cursor-pointer': !scrollIsAtRight,
|
|
|
|
'pointer-events-none opacity-30': scrollIsAtRight,
|
|
|
|
}"
|
2024-08-15 15:30:07 +00:00
|
|
|
class="hover:bg-muted text-muted-foreground cursor-pointer border-l px-2"
|
|
|
|
@click="scrollDirection('right')"
|
|
|
|
>
|
|
|
|
<ChevronRight class="size-4 h-full" />
|
|
|
|
</span>
|
|
|
|
</div>
|
2024-05-25 14:10:21 +00:00
|
|
|
</template>
|