bge-ui 1.8.7 → 1.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +90 -75
- package/dist/tabs/index.vue.d.ts +8 -4
- package/package.json +1 -1
- package/src/tabs/index.vue +111 -83
package/dist/index.js
CHANGED
|
@@ -6656,16 +6656,18 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
6656
6656
|
__name: "index",
|
|
6657
6657
|
props: {
|
|
6658
6658
|
type: {
|
|
6659
|
+
type: String,
|
|
6659
6660
|
default: "bordered",
|
|
6660
|
-
|
|
6661
|
+
validator: (value) => ["bordered", "pills", "pills-elevated"].includes(value)
|
|
6661
6662
|
},
|
|
6662
6663
|
modelValue: {
|
|
6663
6664
|
type: String,
|
|
6664
6665
|
default: ""
|
|
6665
6666
|
},
|
|
6666
6667
|
size: {
|
|
6668
|
+
type: String,
|
|
6667
6669
|
default: "default",
|
|
6668
|
-
|
|
6670
|
+
validator: (value) => ["default", "large", "mini"].includes(value)
|
|
6669
6671
|
}
|
|
6670
6672
|
},
|
|
6671
6673
|
emits: ["update:modelValue"],
|
|
@@ -6673,76 +6675,29 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
6673
6675
|
const props = __props;
|
|
6674
6676
|
const emits = __emit;
|
|
6675
6677
|
const panes = ref([]);
|
|
6678
|
+
const barStyle = ref();
|
|
6679
|
+
const navOffset = ref(0);
|
|
6680
|
+
const scrollable = ref(false);
|
|
6681
|
+
const tabsRef = ref(null);
|
|
6682
|
+
const navScrollRef = ref(null);
|
|
6676
6683
|
function addPane(pane) {
|
|
6677
6684
|
panes.value.push(pane);
|
|
6678
6685
|
}
|
|
6679
|
-
watch(() => props.modelValue, () => {
|
|
6680
|
-
setTimeout(() => {
|
|
6681
|
-
update();
|
|
6682
|
-
}, 100);
|
|
6683
|
-
});
|
|
6684
6686
|
function changeValue(value) {
|
|
6685
6687
|
emits("update:modelValue", value);
|
|
6686
|
-
|
|
6688
|
+
nextTick(() => {
|
|
6687
6689
|
update();
|
|
6688
|
-
}, 100);
|
|
6689
|
-
}
|
|
6690
|
-
const scrollPrev = () => {
|
|
6691
|
-
if (!navScrollRef.value)
|
|
6692
|
-
return;
|
|
6693
|
-
let newOffset;
|
|
6694
|
-
const currentOffset = navOffset.value;
|
|
6695
|
-
const navScrollBounding = navScrollRef.value.getBoundingClientRect();
|
|
6696
|
-
const maxOffset = navScrollBounding.width;
|
|
6697
|
-
panes.value.some((tab, index2) => {
|
|
6698
|
-
const $el = tab.ref;
|
|
6699
|
-
if (!$el)
|
|
6700
|
-
return false;
|
|
6701
|
-
const activeTabBounding = $el.getBoundingClientRect();
|
|
6702
|
-
if (activeTabBounding.left >= navScrollBounding.left && index2 > 0) {
|
|
6703
|
-
const tabBounding = panes.value[index2 - 1].ref.getBoundingClientRect();
|
|
6704
|
-
if (index2 - 1 === 0) {
|
|
6705
|
-
newOffset = -navScrollBounding.left;
|
|
6706
|
-
return true;
|
|
6707
|
-
}
|
|
6708
|
-
newOffset = currentOffset - (navScrollBounding.left - tabBounding.left);
|
|
6709
|
-
return true;
|
|
6710
|
-
}
|
|
6711
6690
|
});
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
};
|
|
6717
|
-
const scrollNext = () => {
|
|
6718
|
-
if (!navScrollRef.value)
|
|
6719
|
-
return;
|
|
6720
|
-
let newOffset;
|
|
6721
|
-
const currentOffset = navOffset.value;
|
|
6722
|
-
const navScrollBounding = navScrollRef.value.getBoundingClientRect();
|
|
6723
|
-
const maxOffset = navScrollBounding.width;
|
|
6724
|
-
panes.value.some((tab, index2) => {
|
|
6725
|
-
const $el = tab.ref;
|
|
6726
|
-
if (!$el)
|
|
6727
|
-
return false;
|
|
6728
|
-
const activeTabBounding = $el.getBoundingClientRect();
|
|
6729
|
-
if (activeTabBounding.right > navScrollBounding.right) {
|
|
6730
|
-
newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
|
|
6731
|
-
return true;
|
|
6732
|
-
}
|
|
6691
|
+
}
|
|
6692
|
+
watch(() => props.modelValue, () => {
|
|
6693
|
+
nextTick(() => {
|
|
6694
|
+
update();
|
|
6733
6695
|
});
|
|
6734
|
-
|
|
6735
|
-
newOffset = Math.max(newOffset, 0);
|
|
6736
|
-
navOffset.value = Math.min(newOffset, maxOffset);
|
|
6737
|
-
}
|
|
6738
|
-
};
|
|
6696
|
+
});
|
|
6739
6697
|
provide(tabsKey$1, {
|
|
6740
6698
|
addPane,
|
|
6741
6699
|
changeValue
|
|
6742
6700
|
});
|
|
6743
|
-
const barStyle = ref();
|
|
6744
|
-
const navOffset = ref(0);
|
|
6745
|
-
const scrollable = ref(false);
|
|
6746
6701
|
const getBarStyle = () => {
|
|
6747
6702
|
let offset2 = 0;
|
|
6748
6703
|
let tabSize = 0;
|
|
@@ -6752,9 +6707,9 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
6752
6707
|
if (!$el)
|
|
6753
6708
|
return false;
|
|
6754
6709
|
if ($el.clientWidth === 0 && index2 === 0) {
|
|
6755
|
-
|
|
6710
|
+
nextTick(() => {
|
|
6756
6711
|
update();
|
|
6757
|
-
}
|
|
6712
|
+
});
|
|
6758
6713
|
return false;
|
|
6759
6714
|
}
|
|
6760
6715
|
if (tab.value !== props.modelValue) {
|
|
@@ -6771,8 +6726,10 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
6771
6726
|
transform: `translateX(${offset2}px)`
|
|
6772
6727
|
};
|
|
6773
6728
|
};
|
|
6774
|
-
const navScrollRef = ref();
|
|
6775
6729
|
const getNavOffset = () => {
|
|
6730
|
+
const navScrollElement = navScrollRef.value;
|
|
6731
|
+
if (!navScrollElement)
|
|
6732
|
+
return;
|
|
6776
6733
|
panes.value.forEach((tab, index2) => {
|
|
6777
6734
|
const $el = tab.ref;
|
|
6778
6735
|
if (!$el)
|
|
@@ -6781,7 +6738,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
6781
6738
|
const currentOffset = navOffset.value;
|
|
6782
6739
|
let newOffset = currentOffset;
|
|
6783
6740
|
const activeTabBounding = $el.getBoundingClientRect();
|
|
6784
|
-
const navScrollBounding =
|
|
6741
|
+
const navScrollBounding = navScrollElement.getBoundingClientRect();
|
|
6785
6742
|
const maxOffset = navScrollBounding.width;
|
|
6786
6743
|
if (activeTabBounding.left < navScrollBounding.left) {
|
|
6787
6744
|
newOffset = currentOffset - (navScrollBounding.left - activeTabBounding.left);
|
|
@@ -6795,28 +6752,86 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
6795
6752
|
return false;
|
|
6796
6753
|
});
|
|
6797
6754
|
};
|
|
6755
|
+
const scrollPrev = () => {
|
|
6756
|
+
const navScrollElement = navScrollRef.value;
|
|
6757
|
+
if (!navScrollElement)
|
|
6758
|
+
return;
|
|
6759
|
+
let newOffset;
|
|
6760
|
+
const currentOffset = navOffset.value;
|
|
6761
|
+
const navScrollBounding = navScrollElement.getBoundingClientRect();
|
|
6762
|
+
const maxOffset = navScrollBounding.width;
|
|
6763
|
+
panes.value.some((tab, index2) => {
|
|
6764
|
+
const $el = tab.ref;
|
|
6765
|
+
if (!$el)
|
|
6766
|
+
return false;
|
|
6767
|
+
const activeTabBounding = $el.getBoundingClientRect();
|
|
6768
|
+
if (activeTabBounding.left >= navScrollBounding.left && index2 > 0) {
|
|
6769
|
+
const prevTab = panes.value[index2 - 1];
|
|
6770
|
+
if (prevTab && prevTab.ref) {
|
|
6771
|
+
const tabBounding = prevTab.ref.getBoundingClientRect();
|
|
6772
|
+
if (index2 - 1 === 0) {
|
|
6773
|
+
newOffset = -navScrollBounding.left;
|
|
6774
|
+
return true;
|
|
6775
|
+
}
|
|
6776
|
+
newOffset = currentOffset - (navScrollBounding.left - tabBounding.left);
|
|
6777
|
+
return true;
|
|
6778
|
+
}
|
|
6779
|
+
}
|
|
6780
|
+
});
|
|
6781
|
+
if (newOffset) {
|
|
6782
|
+
newOffset = Math.max(newOffset, 0);
|
|
6783
|
+
navOffset.value = Math.min(newOffset, maxOffset);
|
|
6784
|
+
}
|
|
6785
|
+
};
|
|
6786
|
+
const scrollNext = () => {
|
|
6787
|
+
const navScrollElement = navScrollRef.value;
|
|
6788
|
+
if (!navScrollElement)
|
|
6789
|
+
return;
|
|
6790
|
+
let newOffset;
|
|
6791
|
+
const currentOffset = navOffset.value;
|
|
6792
|
+
const navScrollBounding = navScrollElement.getBoundingClientRect();
|
|
6793
|
+
const maxOffset = navScrollBounding.width;
|
|
6794
|
+
panes.value.some((tab, index2) => {
|
|
6795
|
+
const $el = tab.ref;
|
|
6796
|
+
if (!$el)
|
|
6797
|
+
return false;
|
|
6798
|
+
const activeTabBounding = $el.getBoundingClientRect();
|
|
6799
|
+
if (activeTabBounding.right > navScrollBounding.right) {
|
|
6800
|
+
newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
|
|
6801
|
+
return true;
|
|
6802
|
+
}
|
|
6803
|
+
});
|
|
6804
|
+
if (newOffset) {
|
|
6805
|
+
newOffset = Math.max(newOffset, 0);
|
|
6806
|
+
navOffset.value = Math.min(newOffset, maxOffset);
|
|
6807
|
+
}
|
|
6808
|
+
};
|
|
6798
6809
|
const panesStyle = computed(() => {
|
|
6799
6810
|
return {
|
|
6800
6811
|
transform: `translateX(-${navOffset.value}px)`
|
|
6801
6812
|
};
|
|
6802
6813
|
});
|
|
6803
6814
|
const update = () => {
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
const
|
|
6807
|
-
const
|
|
6808
|
-
if (
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6815
|
+
const navScrollElement = navScrollRef.value;
|
|
6816
|
+
if (panes.value.length > 0 && navScrollElement) {
|
|
6817
|
+
const lastPane = panes.value[panes.value.length - 1];
|
|
6818
|
+
const firstPane = panes.value[0];
|
|
6819
|
+
if (lastPane && lastPane.ref && firstPane && firstPane.ref) {
|
|
6820
|
+
const right2 = lastPane.ref.getBoundingClientRect().right;
|
|
6821
|
+
const left2 = firstPane.ref.getBoundingClientRect().left;
|
|
6822
|
+
const navScrollBounding = navScrollElement.getBoundingClientRect();
|
|
6823
|
+
if (left2 < navScrollBounding.left) {
|
|
6824
|
+
scrollable.value = true;
|
|
6825
|
+
} else if (right2 > navScrollBounding.right) {
|
|
6826
|
+
scrollable.value = true;
|
|
6827
|
+
} else {
|
|
6828
|
+
scrollable.value = false;
|
|
6829
|
+
}
|
|
6814
6830
|
}
|
|
6815
6831
|
}
|
|
6816
6832
|
barStyle.value = getBarStyle();
|
|
6817
6833
|
getNavOffset();
|
|
6818
6834
|
};
|
|
6819
|
-
const tabsRef = ref();
|
|
6820
6835
|
useResizeObserver(tabsRef, update);
|
|
6821
6836
|
onMounted(() => {
|
|
6822
6837
|
update();
|
package/dist/tabs/index.vue.d.ts
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
2
2
|
type: {
|
|
3
|
+
type: StringConstructor;
|
|
3
4
|
default: string;
|
|
4
|
-
value: string
|
|
5
|
+
validator: (value: string) => boolean;
|
|
5
6
|
};
|
|
6
7
|
modelValue: {
|
|
7
8
|
type: StringConstructor;
|
|
8
9
|
default: string;
|
|
9
10
|
};
|
|
10
11
|
size: {
|
|
12
|
+
type: StringConstructor;
|
|
11
13
|
default: string;
|
|
12
|
-
value: string
|
|
14
|
+
validator: (value: string) => boolean;
|
|
13
15
|
};
|
|
14
16
|
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
15
17
|
"update:modelValue": (...args: any[]) => void;
|
|
16
18
|
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
17
19
|
type: {
|
|
20
|
+
type: StringConstructor;
|
|
18
21
|
default: string;
|
|
19
|
-
value: string
|
|
22
|
+
validator: (value: string) => boolean;
|
|
20
23
|
};
|
|
21
24
|
modelValue: {
|
|
22
25
|
type: StringConstructor;
|
|
23
26
|
default: string;
|
|
24
27
|
};
|
|
25
28
|
size: {
|
|
29
|
+
type: StringConstructor;
|
|
26
30
|
default: string;
|
|
27
|
-
value: string
|
|
31
|
+
validator: (value: string) => boolean;
|
|
28
32
|
};
|
|
29
33
|
}>> & {
|
|
30
34
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
package/package.json
CHANGED
package/src/tabs/index.vue
CHANGED
|
@@ -12,118 +12,84 @@
|
|
|
12
12
|
</template>
|
|
13
13
|
<script setup lang="ts">
|
|
14
14
|
import { useResizeObserver } from "@vueuse/core"
|
|
15
|
-
import { provide, ref, onMounted, watch, computed,
|
|
15
|
+
import { provide, ref, onMounted, watch, computed, nextTick } from "vue"
|
|
16
16
|
defineOptions({
|
|
17
17
|
name: "Tabs",
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
const props = defineProps({
|
|
21
21
|
type: {
|
|
22
|
+
type: String,
|
|
22
23
|
default: 'bordered',
|
|
23
|
-
value: ['bordered', 'pills', 'pills-elevated']
|
|
24
|
+
validator: (value: string) => ['bordered', 'pills', 'pills-elevated'].includes(value)
|
|
24
25
|
},
|
|
25
26
|
modelValue: {
|
|
26
27
|
type: String,
|
|
27
28
|
default: '',
|
|
28
29
|
},
|
|
29
30
|
size: {
|
|
31
|
+
type: String,
|
|
30
32
|
default: 'default',
|
|
31
|
-
value: ['default', 'large', 'mini']
|
|
33
|
+
validator: (value: string) => ['default', 'large', 'mini'].includes(value)
|
|
32
34
|
}
|
|
33
35
|
})
|
|
34
36
|
|
|
35
37
|
const emits = defineEmits(['update:modelValue'])
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
// 类型定义
|
|
40
|
+
interface TabPane {
|
|
41
|
+
ref: HTMLElement | null
|
|
42
|
+
value: string
|
|
43
|
+
setActive: (active: boolean) => void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 状态管理
|
|
47
|
+
const panes = ref<TabPane[]>([])
|
|
48
|
+
const barStyle = ref<{ width: string; transform: string } | undefined>()
|
|
49
|
+
const navOffset = ref(0)
|
|
50
|
+
const scrollable = ref(false)
|
|
51
|
+
|
|
52
|
+
// 引用
|
|
53
|
+
const tabsRef = ref<HTMLElement | null>(null)
|
|
54
|
+
const navScrollRef = ref<HTMLElement | null>(null)
|
|
38
55
|
|
|
39
|
-
|
|
56
|
+
// 方法
|
|
57
|
+
function addPane(pane: TabPane) {
|
|
40
58
|
panes.value.push(pane)
|
|
41
59
|
}
|
|
42
60
|
|
|
43
|
-
watch(() => props.modelValue, () => {
|
|
44
|
-
setTimeout(() => {
|
|
45
|
-
update()
|
|
46
|
-
}, 100)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
61
|
function changeValue(value: string) {
|
|
50
62
|
emits('update:modelValue', value)
|
|
51
|
-
|
|
63
|
+
nextTick(() => {
|
|
52
64
|
update()
|
|
53
|
-
}, 100)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const scrollPrev = () => {
|
|
57
|
-
if (!navScrollRef.value) return
|
|
58
|
-
let newOffset
|
|
59
|
-
const currentOffset = navOffset.value
|
|
60
|
-
const navScrollBounding = navScrollRef.value.getBoundingClientRect()
|
|
61
|
-
const maxOffset = navScrollBounding.width
|
|
62
|
-
panes.value.some((tab: any, index: number) => {
|
|
63
|
-
const $el = tab.ref as HTMLElement
|
|
64
|
-
if (!$el) return false
|
|
65
|
-
const activeTabBounding = $el.getBoundingClientRect()
|
|
66
|
-
if (activeTabBounding.left >= navScrollBounding.left && index > 0) {
|
|
67
|
-
const tabBounding = panes.value[index - 1].ref.getBoundingClientRect()
|
|
68
|
-
if (index - 1 === 0) {
|
|
69
|
-
newOffset = -navScrollBounding.left
|
|
70
|
-
return true
|
|
71
|
-
}
|
|
72
|
-
newOffset =
|
|
73
|
-
currentOffset - (navScrollBounding.left - tabBounding.left)
|
|
74
|
-
return true
|
|
75
|
-
}
|
|
76
65
|
})
|
|
77
|
-
if (newOffset) {
|
|
78
|
-
newOffset = Math.max(newOffset, 0)
|
|
79
|
-
navOffset.value = Math.min(newOffset, maxOffset)
|
|
80
|
-
}
|
|
81
66
|
}
|
|
82
67
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const currentOffset = navOffset.value
|
|
87
|
-
const navScrollBounding = navScrollRef.value.getBoundingClientRect()
|
|
88
|
-
const maxOffset = navScrollBounding.width
|
|
89
|
-
panes.value.some((tab: any, index: number) => {
|
|
90
|
-
const $el = tab.ref as HTMLElement
|
|
91
|
-
if (!$el) return false
|
|
92
|
-
const activeTabBounding = $el.getBoundingClientRect()
|
|
93
|
-
if (activeTabBounding.right > navScrollBounding.right) {
|
|
94
|
-
newOffset =
|
|
95
|
-
currentOffset + activeTabBounding.right - navScrollBounding.right
|
|
96
|
-
return true
|
|
97
|
-
}
|
|
68
|
+
watch(() => props.modelValue, () => {
|
|
69
|
+
nextTick(() => {
|
|
70
|
+
update()
|
|
98
71
|
})
|
|
99
|
-
|
|
100
|
-
newOffset = Math.max(newOffset, 0)
|
|
101
|
-
navOffset.value = Math.min(newOffset, maxOffset)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
72
|
+
})
|
|
104
73
|
|
|
105
74
|
const tabsKey = 'bge-tabs-context'
|
|
106
75
|
provide(tabsKey, {
|
|
107
76
|
addPane,
|
|
108
77
|
changeValue
|
|
109
78
|
})
|
|
110
|
-
const barStyle = ref<any>()
|
|
111
|
-
const navOffset = ref(0)
|
|
112
|
-
const scrollable = ref(false)
|
|
113
79
|
|
|
114
|
-
const getBarStyle
|
|
80
|
+
const getBarStyle = (): { width: string; transform: string } => {
|
|
115
81
|
let offset = 0
|
|
116
82
|
let tabSize = 0
|
|
117
83
|
|
|
118
84
|
const sizeName = 'width'
|
|
119
85
|
|
|
120
|
-
panes.value.forEach((tab:
|
|
121
|
-
const $el = tab.ref
|
|
86
|
+
panes.value.forEach((tab: TabPane, index: number) => {
|
|
87
|
+
const $el = tab.ref
|
|
122
88
|
if (!$el) return false
|
|
123
89
|
if ($el.clientWidth === 0 && index === 0) {
|
|
124
|
-
|
|
90
|
+
nextTick(() => {
|
|
125
91
|
update()
|
|
126
|
-
}
|
|
92
|
+
})
|
|
127
93
|
return false
|
|
128
94
|
}
|
|
129
95
|
if (tab.value !== props.modelValue) {
|
|
@@ -143,16 +109,17 @@ const getBarStyle: any = () => {
|
|
|
143
109
|
}
|
|
144
110
|
}
|
|
145
111
|
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
112
|
+
const getNavOffset = () => {
|
|
113
|
+
const navScrollElement = navScrollRef.value
|
|
114
|
+
if (!navScrollElement) return
|
|
115
|
+
panes.value.forEach((tab: TabPane, index: number) => {
|
|
116
|
+
const $el = tab.ref
|
|
150
117
|
if (!$el) return false
|
|
151
118
|
if (tab.value === props.modelValue) {
|
|
152
119
|
const currentOffset = navOffset.value
|
|
153
120
|
let newOffset = currentOffset
|
|
154
121
|
const activeTabBounding = $el.getBoundingClientRect()
|
|
155
|
-
const navScrollBounding =
|
|
122
|
+
const navScrollBounding = navScrollElement.getBoundingClientRect()
|
|
156
123
|
const maxOffset = navScrollBounding.width
|
|
157
124
|
if (activeTabBounding.left < navScrollBounding.left) {
|
|
158
125
|
newOffset =
|
|
@@ -168,28 +135,89 @@ const getNavOffset: any = () => {
|
|
|
168
135
|
return false
|
|
169
136
|
})
|
|
170
137
|
}
|
|
138
|
+
|
|
139
|
+
const scrollPrev = () => {
|
|
140
|
+
const navScrollElement = navScrollRef.value
|
|
141
|
+
if (!navScrollElement) return
|
|
142
|
+
let newOffset
|
|
143
|
+
const currentOffset = navOffset.value
|
|
144
|
+
const navScrollBounding = navScrollElement.getBoundingClientRect()
|
|
145
|
+
const maxOffset = navScrollBounding.width
|
|
146
|
+
panes.value.some((tab: TabPane, index: number) => {
|
|
147
|
+
const $el = tab.ref
|
|
148
|
+
if (!$el) return false
|
|
149
|
+
const activeTabBounding = $el.getBoundingClientRect()
|
|
150
|
+
if (activeTabBounding.left >= navScrollBounding.left && index > 0) {
|
|
151
|
+
const prevTab = panes.value[index - 1]
|
|
152
|
+
if (prevTab && prevTab.ref) {
|
|
153
|
+
const tabBounding = prevTab.ref.getBoundingClientRect()
|
|
154
|
+
if (index - 1 === 0) {
|
|
155
|
+
newOffset = -navScrollBounding.left
|
|
156
|
+
return true
|
|
157
|
+
}
|
|
158
|
+
newOffset =
|
|
159
|
+
currentOffset - (navScrollBounding.left - tabBounding.left)
|
|
160
|
+
return true
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
if (newOffset) {
|
|
165
|
+
newOffset = Math.max(newOffset, 0)
|
|
166
|
+
navOffset.value = Math.min(newOffset, maxOffset)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const scrollNext = () => {
|
|
171
|
+
const navScrollElement = navScrollRef.value
|
|
172
|
+
if (!navScrollElement) return
|
|
173
|
+
let newOffset
|
|
174
|
+
const currentOffset = navOffset.value
|
|
175
|
+
const navScrollBounding = navScrollElement.getBoundingClientRect()
|
|
176
|
+
const maxOffset = navScrollBounding.width
|
|
177
|
+
panes.value.some((tab: TabPane, index: number) => {
|
|
178
|
+
const $el = tab.ref
|
|
179
|
+
if (!$el) return false
|
|
180
|
+
const activeTabBounding = $el.getBoundingClientRect()
|
|
181
|
+
if (activeTabBounding.right > navScrollBounding.right) {
|
|
182
|
+
newOffset =
|
|
183
|
+
currentOffset + activeTabBounding.right - navScrollBounding.right
|
|
184
|
+
return true
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
if (newOffset) {
|
|
188
|
+
newOffset = Math.max(newOffset, 0)
|
|
189
|
+
navOffset.value = Math.min(newOffset, maxOffset)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
171
193
|
const panesStyle = computed(() => {
|
|
172
194
|
return {
|
|
173
195
|
transform: `translateX(-${navOffset.value}px)`,
|
|
174
196
|
}
|
|
175
197
|
})
|
|
198
|
+
|
|
176
199
|
const update = () => {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
200
|
+
const navScrollElement = navScrollRef.value
|
|
201
|
+
if (panes.value.length > 0 && navScrollElement) {
|
|
202
|
+
const lastPane = panes.value[panes.value.length - 1]
|
|
203
|
+
const firstPane = panes.value[0]
|
|
204
|
+
if (lastPane && lastPane.ref && firstPane && firstPane.ref) {
|
|
205
|
+
const right = lastPane.ref.getBoundingClientRect().right
|
|
206
|
+
const left = firstPane.ref.getBoundingClientRect().left
|
|
207
|
+
const navScrollBounding = navScrollElement.getBoundingClientRect()
|
|
208
|
+
if (left < navScrollBounding.left) {
|
|
209
|
+
scrollable.value = true
|
|
210
|
+
} else if (right > navScrollBounding.right) {
|
|
211
|
+
scrollable.value = true
|
|
212
|
+
} else {
|
|
213
|
+
scrollable.value = false
|
|
214
|
+
}
|
|
187
215
|
}
|
|
188
216
|
}
|
|
189
217
|
barStyle.value = getBarStyle()
|
|
190
218
|
getNavOffset()
|
|
191
219
|
}
|
|
192
|
-
|
|
220
|
+
|
|
193
221
|
useResizeObserver(tabsRef, update)
|
|
194
222
|
|
|
195
223
|
onMounted(() => {
|