@fiscozen/tab 0.1.6 → 0.1.7-beta

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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@fiscozen/tab",
3
- "version": "0.1.6",
3
+ "version": "0.1.7-beta",
4
4
  "description": "Design System Tab component",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
7
7
  "keywords": [],
8
8
  "author": "Cristian Barraco",
9
9
  "dependencies": {
10
- "@fiscozen/badge": "^0.1.0",
11
- "@fiscozen/composables": "^0.1.8"
10
+ "@fiscozen/badge": "^0.1.1",
11
+ "@fiscozen/composables": "^0.1.25"
12
12
  },
13
13
  "peerDependencies": {
14
14
  "tailwindcss": "^3.4.1",
@@ -34,9 +34,9 @@
34
34
  "@fortawesome/fontawesome-svg-core": "^6.5.1",
35
35
  "@fortawesome/vue-fontawesome": "^3.0.6",
36
36
  "@fiscozen/eslint-config": "^0.1.0",
37
- "@fiscozen/prettier-config": "^0.1.0",
38
- "@fiscozen/icons": "^0.1.4",
39
- "@fiscozen/tsconfig": "^0.1.0"
37
+ "@fiscozen/tsconfig": "^0.1.0",
38
+ "@fiscozen/icons": "^0.1.10",
39
+ "@fiscozen/prettier-config": "^0.1.0"
40
40
  },
41
41
  "license": "MIT",
42
42
  "scripts": {
package/src/FzTabs.vue CHANGED
@@ -27,7 +27,17 @@
27
27
  </template>
28
28
 
29
29
  <script setup lang="ts">
30
- import { computed, ref, onMounted, provide, useSlots, watch, VNode } from "vue";
30
+ import {
31
+ computed,
32
+ ref,
33
+ onMounted,
34
+ provide,
35
+ useSlots,
36
+ watch,
37
+ VNode,
38
+ onUnmounted,
39
+ onBeforeUnmount,
40
+ } from "vue";
31
41
  import { FzTabsProps, FzTabProps } from "./types";
32
42
  import FzTabPicker from "./components/FzTabPicker.vue";
33
43
  import FzTabName from "./components/FzTabName.vue";
@@ -42,7 +52,8 @@ const emit = defineEmits(["change"]);
42
52
 
43
53
  const slots = useSlots();
44
54
 
45
- const tabContainer = ref<HTMLElement | null>(null);
55
+ const tabContainer = ref<HTMLElement>();
56
+ const isOverflowing = ref(false);
46
57
  const selectedTab = ref("");
47
58
  provide("selectedTab", selectedTab);
48
59
 
@@ -58,8 +69,8 @@ const tabs = computed(() => {
58
69
  if (tab.type === FzTab) return tab.props as FzTabProps;
59
70
 
60
71
  if (typeof tab.type === "symbol") {
61
- const children = tab.children as VNode[];
62
- if (!children) return null;
72
+ const children = tab.children as VNode[] | "v-if";
73
+ if (!children || children === "v-if") return null;
63
74
 
64
75
  return children
65
76
  .filter((child) => child.type === FzTab)
@@ -70,13 +81,6 @@ const tabs = computed(() => {
70
81
  .filter((el): el is FzTabProps => el != null);
71
82
  });
72
83
 
73
- const isOverflowing = computed(() => {
74
- if (!tabContainer.value) return false;
75
-
76
- const parent = tabContainer.value.parentElement ?? document.body;
77
- return tabContainer.value.scrollWidth > parent.clientWidth;
78
- });
79
-
80
84
  const staticTabContainerClass =
81
85
  "tab-container flex rounded-lg gap-8 p-2 bg-grey-100 w-fit max-w-full overflow-x-auto";
82
86
 
@@ -96,30 +100,43 @@ function onWheel(e: WheelEvent) {
96
100
  else tabContainer.value!.scrollLeft -= 100;
97
101
  }
98
102
 
103
+ function updateIsOverflowing() {
104
+ if (!tabContainer.value) return false;
105
+
106
+ const parent = tabContainer.value.parentElement ?? document.body;
107
+ isOverflowing.value = tabContainer.value.scrollWidth > parent.clientWidth;
108
+ }
109
+
99
110
  onMounted(() => {
100
111
  if (tabs.value.length === 0) {
101
- console.error(
112
+ console.warn(
102
113
  "[Fiscozen Design System]: FzTabs must have at least one FzTab child",
103
114
  );
104
- return;
105
- }
106
-
107
- const findSelected = tabs.value.find((tab) => tab.initialSelected);
108
- if (findSelected) {
109
- selectedTab.value = findSelected.title;
110
115
  } else {
111
- selectedTab.value = tabs.value[0].title;
112
- }
116
+ const findSelected = tabs.value.find((tab) => tab.initialSelected);
117
+ if (findSelected) {
118
+ selectedTab.value = findSelected.title;
119
+ } else {
120
+ selectedTab.value = tabs.value[0].title;
121
+ }
113
122
 
114
- const duplicateTitles = tabs.value
115
- .map((tab) => tab.title)
116
- .filter((title, index, self) => self.indexOf(title) !== index);
123
+ const duplicateTitles = tabs.value
124
+ .map((tab) => tab.title)
125
+ .filter((title, index, self) => self.indexOf(title) !== index);
117
126
 
118
- if (duplicateTitles.length) {
119
- console.warn(
120
- `[Fiscozen Design System]: FzTabs has duplicate titles: ${duplicateTitles.join(", ")}, this may cause unexpected behavior.`,
121
- );
127
+ if (duplicateTitles.length) {
128
+ console.warn(
129
+ `[Fiscozen Design System]: FzTabs has duplicate titles: ${duplicateTitles.join(", ")}, this may cause unexpected behavior.`,
130
+ );
131
+ }
122
132
  }
133
+
134
+ updateIsOverflowing();
135
+ window.addEventListener("resize", updateIsOverflowing);
136
+ });
137
+
138
+ onBeforeUnmount(() => {
139
+ window.removeEventListener("resize", updateIsOverflowing);
123
140
  });
124
141
 
125
142
  watch(
@@ -136,7 +153,7 @@ watch(
136
153
  `button[title="${selectedTab.value}"]`,
137
154
  );
138
155
 
139
- if (selectedTabElement) {
156
+ if (selectedTabElement && isOverflowing.value) {
140
157
  selectedTabElement.scrollIntoView({
141
158
  behavior: "smooth",
142
159
  block: "nearest",
@@ -20,7 +20,7 @@ exports[`FzTabs > renders with badgeContent on tab1 1`] = `
20
20
  <div data-v-97c498eb="" class="flex flex-row">
21
21
  <div data-v-97c498eb="" class="tab-container flex rounded-lg gap-8 p-2 bg-grey-100 w-fit max-w-full overflow-x-auto flex-row"><button data-v-97c498eb="" class="w-auto flex font-medium items-center max-w-[136px] rounded-md text-sm h-40 gap-6 py-8 px-12 bg-white text-blue-500 cursor-pointer" title="tab1" badgecontent="1">
22
22
  <!--v-if--><span class="text-ellipsis whitespace-nowrap overflow-hidden">tab1</span>
23
- <div class="text-xs px-12 rounded-xl w-fit h-20 flex items-center font-medium bg-blue-500 text-core-white" size="sm">1</div>
23
+ <div class="flex items-center justify-center font-medium text-xs px-8 h-16 w-16 bg-blue-500 text-core-white rounded-full !px-0">1</div>
24
24
  </button><button data-v-97c498eb="" class="w-auto flex font-medium items-center max-w-[136px] rounded-md text-sm h-40 gap-6 py-8 px-12 text-grey-500 bg-grey-100 hover:bg-background-alice-blue active:bg-white active:text-blue-500 cursor-pointer" title="tab2">
25
25
  <!--v-if--><span class="text-ellipsis whitespace-nowrap overflow-hidden">tab2</span>
26
26
  <!--v-if-->
@@ -50,7 +50,7 @@ exports[`FzTabs > renders with icon on tab1 1`] = `
50
50
  <div data-v-97c498eb="" class="flex flex-row">
51
51
  <div data-v-97c498eb="" class="tab-container flex rounded-lg gap-8 p-2 bg-grey-100 w-fit max-w-full overflow-x-auto flex-row"><button data-v-97c498eb="" class="w-auto flex font-medium items-center max-w-[136px] rounded-md text-sm h-40 gap-6 py-8 px-12 bg-white text-blue-500 cursor-pointer" title="tab1" icon="bell">
52
52
  <div class="flex items-center justify-center w-[15px] h-[15px]"><svg class="svg-inline--fa fa-bell fa-sm h-[12px]" aria-hidden="true" focusable="false" data-prefix="far" data-icon="bell" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
53
- <path class="" fill="currentColor" d="M224 0c-17.7 0-32 14.3-32 32V51.2C119 66 64 130.6 64 208v25.4c0 45.4-15.5 89.5-43.8 124.9L5.3 377c-5.8 7.2-6.9 17.1-2.9 25.4S14.8 416 24 416H424c9.2 0 17.6-5.3 21.6-13.6s2.9-18.2-2.9-25.4l-14.9-18.6C399.5 322.9 384 278.8 384 233.4V208c0-77.4-55-142-128-156.8V32c0-17.7-14.3-32-32-32zm0 96c61.9 0 112 50.1 112 112v25.4c0 47.9 13.9 94.6 39.7 134.6H72.3C98.1 328 112 281.3 112 233.4V208c0-61.9 50.1-112 112-112zm64 352H224 160c0 17 6.7 33.3 18.7 45.3s28.3 18.7 45.3 18.7s33.3-6.7 45.3-18.7s18.7-28.3 18.7-45.3z"></path>
53
+ <path class="" fill="currentColor" d="M224 0c-17.7 0-32 14.3-32 32l0 19.2C119 66 64 130.6 64 208l0 25.4c0 45.4-15.5 89.5-43.8 124.9L5.3 377c-5.8 7.2-6.9 17.1-2.9 25.4S14.8 416 24 416l400 0c9.2 0 17.6-5.3 21.6-13.6s2.9-18.2-2.9-25.4l-14.9-18.6C399.5 322.9 384 278.8 384 233.4l0-25.4c0-77.4-55-142-128-156.8L256 32c0-17.7-14.3-32-32-32zm0 96c61.9 0 112 50.1 112 112l0 25.4c0 47.9 13.9 94.6 39.7 134.6L72.3 368C98.1 328 112 281.3 112 233.4l0-25.4c0-61.9 50.1-112 112-112zm64 352l-64 0-64 0c0 17 6.7 33.3 18.7 45.3s28.3 18.7 45.3 18.7s33.3-6.7 45.3-18.7s18.7-28.3 18.7-45.3z"></path>
54
54
  </svg></div><span class="text-ellipsis whitespace-nowrap overflow-hidden">tab1</span>
55
55
  <!--v-if-->
56
56
  </button><button data-v-97c498eb="" class="w-auto flex font-medium items-center max-w-[136px] rounded-md text-sm h-40 gap-6 py-8 px-12 text-grey-500 bg-grey-100 hover:bg-background-alice-blue active:bg-white active:text-blue-500 cursor-pointer" title="tab2">
@@ -1,5 +1,10 @@
1
1
  <template>
2
- <FzFloating position="bottom" :isOpen class="w-full overflow-hidden" contentClass="bg-transparent">
2
+ <FzFloating
3
+ position="bottom"
4
+ :isOpen
5
+ class="w-full overflow-hidden"
6
+ contentClass="bg-transparent"
7
+ >
3
8
  <template #opener>
4
9
  <button
5
10
  @click="isOpen = !isOpen"