Files
dbx/src/composables/useTabScroll.ts
T
t8y2 bdd8b3fa03 refactor: split App.vue into composables and layout components
Extract 11 composables and 5 layout components from App.vue, reducing it
from 1921 to 327 lines. Unify dialog overlay style across DialogContent
and DialogScrollContent for consistent backdrop appearance.
2026-05-05 04:14:00 +08:00

27 lines
840 B
TypeScript

import { ref, type Ref } from "vue";
export function useTabScroll(tabsContainerRef: Ref<HTMLElement | null>) {
const canScrollLeft = ref(false);
const canScrollRight = ref(false);
function updateScrollButtons() {
const el = tabsContainerRef.value;
if (!el) {
canScrollLeft.value = false;
canScrollRight.value = false;
return;
}
canScrollLeft.value = el.scrollLeft > 0;
canScrollRight.value = el.scrollLeft < el.scrollWidth - el.clientWidth - 1;
}
function scrollTabs(direction: "left" | "right") {
const el = tabsContainerRef.value;
if (!el) return;
const scrollAmount = el.clientWidth * 0.8;
el.scrollBy({ left: direction === "left" ? -scrollAmount : scrollAmount, behavior: "smooth" });
}
return { canScrollLeft, canScrollRight, updateScrollButtons, scrollTabs };
}