design-system-next 1.2.5 → 1.2.6

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.
@@ -1,33 +1,60 @@
1
- import { ref, computed, SetupContext } from 'vue';
1
+ import { ref, computed, onMounted, SetupContext } from 'vue';
2
2
  import type { TabsPropTypes, TabsEmitTypes } from './tabs';
3
3
 
4
4
  import classNames from 'classnames';
5
5
 
6
6
  export const useTabs = (props: TabsPropTypes, emit: SetupContext<TabsEmitTypes>['emit']) => {
7
- const selectedTabIndex = ref(0);
8
- const { underlined } = props;
7
+ const tabsClasses = computed(() => {
8
+ return classNames({
9
+ 'relative z-[10] px-size-spacing-xs py-size-spacing-3xs body-sm text-color-strong group': true,
10
+ 'transition-left duration-150 ease-in-out': true,
11
+ capitalize: !props.underlined,
12
+ 'uppercase border-x-0 border-t-0': props.underlined,
13
+ });
14
+ });
15
+
16
+ const activeTab = ref({
17
+ index: 0,
18
+ previousIndex: -1,
19
+ height: 0,
20
+ width: 0,
21
+ undelineLeftOffset: 0,
22
+ });
23
+
24
+ const tabElements = ref<HTMLElement[]>([]);
9
25
 
10
- function updateSelectedTabIndex(index: number, disabled = false) {
26
+ const updateSelectedTabIndex = (index: number, disabled = false) => {
11
27
  if (disabled) return;
12
28
 
13
- if (selectedTabIndex.value === index) return;
29
+ activeTab.value.previousIndex = activeTab.value.index;
14
30
 
15
- selectedTabIndex.value = index;
31
+ if (activeTab.value.index === index) return;
32
+
33
+ activeTab.value.index = index;
34
+
35
+ // Update underline left offset based on previous index
36
+ const indexDifference = Math.abs(activeTab.value.index - activeTab.value.previousIndex);
37
+
38
+ if (activeTab.value.index > activeTab.value.previousIndex) {
39
+ // Moving right: increase the offset by the width of each tab
40
+ activeTab.value.undelineLeftOffset += indexDifference * activeTab.value.width;
41
+ } else {
42
+ // Moving left: decrease the offset by the width of each tab
43
+ activeTab.value.undelineLeftOffset -= indexDifference * activeTab.value.width;
44
+ }
16
45
 
17
46
  emit('tabIndex', index);
18
- }
47
+ };
19
48
 
20
- const tabsClasses = computed(() => {
21
- return classNames({
22
- 'px-size-spacing-xs py-size-spacing-3xs capitalize text-color-strong first:rounded-l-md first:border-l last:border-r last:rounded-r-md':
23
- !underlined,
24
- 'p-size-spacing-xs uppercase border-x-0 border-t-0': underlined,
25
- });
49
+ onMounted(() => {
50
+ activeTab.value.height = tabElements.value[activeTab.value.index].offsetHeight;
51
+ activeTab.value.width = tabElements.value[activeTab.value.index].offsetWidth;
26
52
  });
27
53
 
28
54
  return {
29
55
  tabsClasses,
30
- selectedTabIndex,
56
+ activeTab,
57
+ tabElements,
31
58
  updateSelectedTabIndex,
32
59
  };
33
60
  };