design-system-next 1.2.4 → 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,46 +1,52 @@
1
1
  <template>
2
- <div class="flex">
2
+ <div class="relative flex">
3
3
  <div
4
4
  v-for="(tab, index) in list"
5
5
  :key="index"
6
+ ref="tabElements"
6
7
  :class="[
7
8
  tabsClasses,
8
- 'body-sm-regular text-color-strong cursor-pointer border-solid',
9
9
  {
10
- // Active tab without underline
11
- 'background-color-single-active border': !underlined && selectedTabIndex === index,
10
+ // Regular Tab
11
+ 'rounded-l-md': !underlined && index === 0,
12
+ 'rounded-r-md': !underlined && index === tabElements.length - 1,
12
13
 
13
- // Inactive tab without underline
14
- 'border-color-weak hover:background-color-hover border-x-[0.5px] border-y':
15
- !underlined && selectedTabIndex !== index,
14
+ // Regular Tab - Active
15
+ 'text-color-brand-base border-color-success-base cursor-pointer border border-solid':
16
+ !underlined && activeTab.index === index,
16
17
 
17
- // Underlined tab that is not selected
18
- 'border-color-base border-b': underlined && selectedTabIndex !== index,
18
+ // Regular Tab - Inactive
19
+ 'border-color-weak hover:background-color-hover cursor-pointer border-x-[0.5px] border-y border-solid':
20
+ !underlined && activeTab.index !== index,
19
21
 
20
- // Underlined and selected tab
21
- 'border-b-2': underlined && selectedTabIndex === index,
22
+ // Regular Tab - Disabled
23
+ 'background-color-base !cursor-not-allowed': !underlined && tab.disabled,
22
24
 
23
- // Disabled tab with underline
24
- 'border-color-disabled text-color-disabled !cursor-not-allowed border-b': underlined && tab.disabled,
25
-
26
- // Regular text for non-selected tabs
27
- 'body-sm-regular': selectedTabIndex !== index,
25
+ // Underlined Tab - Active
26
+ 'text-color-brand-base cursor-pointer': underlined && activeTab.index === index,
28
27
 
29
- // Active tab with custom text and border styles
30
- 'body-sm-regular text-color-brand-base border-color-success-base': selectedTabIndex === index,
28
+ // Underlined Tab - Inactive
29
+ 'border-color-base cursor-pointer border-b border-solid': underlined && activeTab.index !== index,
30
+ 'hover:background-color-hover cursor-pointer': underlined && activeTab.index !== index && !tab.disabled,
31
31
 
32
- // Border adjustments for previous and next tab
33
- 'border-l-0': selectedTabIndex - index === -1,
34
- 'border-r-0': selectedTabIndex - index === 1,
32
+ // Underlined Tab - Disabled
33
+ 'border-color-disabled text-color-disabled !cursor-not-allowed border-b': underlined && tab.disabled,
35
34
  },
36
35
  ]"
37
36
  @click="updateSelectedTabIndex(index, tab.disabled)"
38
37
  >
39
- <div class="flex items-center gap-size-spacing-5xs leading-none">
38
+ <div
39
+ :class="{
40
+ 'flex items-center gap-size-spacing-5xs leading-none': true,
41
+ 'transition duration-150 ease-in-out': true,
42
+ 'cursor-pointer group-active:scale-75': !tab.disabled,
43
+ 'cursor-not-allowed': tab.disabled,
44
+ }"
45
+ >
40
46
  <div v-if="!!tab.icon">
41
47
  <Icon
42
- :icon="selectedTabIndex === index && !!tab.iconFill ? tab.iconFill : tab.icon"
43
48
  class="body-sm-regular"
49
+ :icon="activeTab.index === index && typeof tab.iconFill === 'string' ? tab.iconFill : tab.icon"
44
50
  />
45
51
  </div>
46
52
  <div v-if="!!tab.label">
@@ -48,17 +54,48 @@
48
54
  </div>
49
55
  </div>
50
56
  </div>
57
+
58
+ <!-- Regular Tab Background Active Indicator -->
59
+ <div
60
+ v-if="!underlined"
61
+ :class="[
62
+ 'background-color-single-active absolute bottom-0 left-0 z-[5] block',
63
+ 'transition-left duration-150 ease-in-out',
64
+ {
65
+ 'rounded-l-md': activeTab.index === 0,
66
+ 'rounded-r-md': activeTab.index === tabElements.length - 1,
67
+ },
68
+ ]"
69
+ :style="{
70
+ height: `${activeTab.height}px`,
71
+ width: `${activeTab.width}px`,
72
+ left: `${activeTab.undelineLeftOffset}px`,
73
+ }"
74
+ />
75
+
76
+ <!-- Underlined Tab Active Indicator -->
77
+ <div
78
+ v-if="underlined"
79
+ :class="[
80
+ 'background-color-success-base absolute bottom-0 left-0 z-10 block h-0.5 rounded-full',
81
+ 'transition-left duration-150 ease-in-out',
82
+ ]"
83
+ :style="{
84
+ width: `${activeTab.width}px`,
85
+ left: `calc(${activeTab.undelineLeftOffset}px - 2.3px)`,
86
+ }"
87
+ />
51
88
  </div>
52
89
  </template>
53
90
 
54
91
  <script lang="ts" setup>
92
+ import { Icon } from '@iconify/vue';
93
+
55
94
  import { tabsPropTypes, tabsEmitTypes } from './tabs';
56
95
  import { useTabs } from './use-tabs';
57
96
 
58
- import { Icon } from '@iconify/vue';
59
-
60
97
  const emit = defineEmits(tabsEmitTypes);
61
98
  const props = defineProps(tabsPropTypes);
62
99
 
63
- const { updateSelectedTabIndex, selectedTabIndex, tabsClasses } = useTabs(props, emit);
100
+ const { tabsClasses, activeTab, tabElements, updateSelectedTabIndex } = useTabs(props, emit);
64
101
  </script>
@@ -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
  };