vueless 0.0.729 → 0.0.730
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 +1 -1
- package/ui.navigation-tab/config.ts +1 -1
- package/ui.navigation-tabs/UTabs.vue +88 -17
- package/ui.navigation-tabs/config.ts +27 -1
- package/ui.navigation-tabs/constants.ts +2 -0
- package/ui.navigation-tabs/storybook/stories.ts +13 -0
- package/ui.navigation-tabs/types.ts +5 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default /*tw*/ {
|
|
2
2
|
tabButton: {
|
|
3
3
|
base: `
|
|
4
|
-
{UButton}
|
|
4
|
+
{UButton} rounded-none border-0 border-b-2 border-transparent
|
|
5
5
|
hover:bg-transparent dark:hover:bg-transparent
|
|
6
6
|
active:bg-transparent dark:active:bg-transparent
|
|
7
7
|
`,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, provide } from "vue";
|
|
2
|
+
import { ref, computed, provide, onMounted, onUnmounted, useTemplateRef } from "vue";
|
|
3
3
|
|
|
4
4
|
import useUI from "../composables/useUI.ts";
|
|
5
5
|
import { getDefaults } from "../utils/ui.ts";
|
|
6
6
|
|
|
7
7
|
import UTab from "../ui.navigation-tab/UTab.vue";
|
|
8
|
+
import UButton from "../ui.button/UButton.vue";
|
|
8
9
|
|
|
9
|
-
import { COMPONENT_NAME } from "./constants.ts";
|
|
10
|
+
import { COMPONENT_NAME, SCROLL_OFFSET } from "./constants.ts";
|
|
10
11
|
import defaultConfig from "./config.ts";
|
|
11
12
|
|
|
12
13
|
import type { Props, Config } from "./types.ts";
|
|
@@ -32,6 +33,45 @@ const selectedItem = computed({
|
|
|
32
33
|
set: (value) => emit("update:modelValue", value),
|
|
33
34
|
});
|
|
34
35
|
|
|
36
|
+
const scrollContainerRef = useTemplateRef<HTMLDivElement | null>("scroll-container");
|
|
37
|
+
const showLeftArrow = ref(false);
|
|
38
|
+
const showRightArrow = ref(false);
|
|
39
|
+
|
|
40
|
+
function checkScroll() {
|
|
41
|
+
if (!scrollContainerRef.value) return;
|
|
42
|
+
|
|
43
|
+
const { scrollLeft, scrollWidth, clientWidth } = scrollContainerRef.value;
|
|
44
|
+
|
|
45
|
+
showLeftArrow.value = scrollLeft > 0;
|
|
46
|
+
showRightArrow.value = scrollLeft < scrollWidth - clientWidth;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function scrollPrev() {
|
|
50
|
+
if (!scrollContainerRef.value) return;
|
|
51
|
+
|
|
52
|
+
scrollContainerRef.value.scrollBy({ left: -SCROLL_OFFSET, behavior: "smooth" });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function scrollNext() {
|
|
56
|
+
if (!scrollContainerRef.value) return;
|
|
57
|
+
|
|
58
|
+
scrollContainerRef.value.scrollBy({ left: SCROLL_OFFSET, behavior: "smooth" });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
onMounted(() => {
|
|
62
|
+
if (scrollContainerRef.value) {
|
|
63
|
+
scrollContainerRef.value.addEventListener("scroll", checkScroll, { passive: true });
|
|
64
|
+
|
|
65
|
+
checkScroll();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
onUnmounted(() => {
|
|
70
|
+
if (scrollContainerRef.value) {
|
|
71
|
+
scrollContainerRef.value.removeEventListener("scroll", checkScroll);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
35
75
|
provide("getUTabsSize", () => props.size);
|
|
36
76
|
provide("getUTabsBlock", () => props.block);
|
|
37
77
|
provide("getUTabsSquare", () => props.square);
|
|
@@ -42,23 +82,54 @@ provide("setUTabsSelectedItem", (value: string) => (selectedItem.value = value))
|
|
|
42
82
|
* Get element / nested component attributes for each config token ✨
|
|
43
83
|
* Applies: `class`, `config`, redefined default `props` and dev `vl-...` attributes.
|
|
44
84
|
*/
|
|
45
|
-
const {
|
|
85
|
+
const {
|
|
86
|
+
config,
|
|
87
|
+
wrapperAttrs,
|
|
88
|
+
tabsAttrs,
|
|
89
|
+
tabAttrs,
|
|
90
|
+
prevAttrs,
|
|
91
|
+
nextAttrs,
|
|
92
|
+
nextButtonAttrs,
|
|
93
|
+
prevButtonAttrs,
|
|
94
|
+
} = useUI<Config>(defaultConfig);
|
|
46
95
|
</script>
|
|
47
96
|
|
|
48
97
|
<template>
|
|
49
|
-
<div v-bind="
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
98
|
+
<div v-bind="wrapperAttrs">
|
|
99
|
+
<div v-if="scrollable && showLeftArrow" v-bind="prevAttrs" @click="scrollPrev">
|
|
100
|
+
<!--
|
|
101
|
+
@slot Use it to add something instead of the "prev" button.
|
|
102
|
+
@binding {string} icon-name
|
|
103
|
+
-->
|
|
104
|
+
<slot name="prev" :icon-name="config.defaults.prevIcon">
|
|
105
|
+
<UButton :icon="config.defaults.prevIcon" v-bind="prevButtonAttrs" />
|
|
106
|
+
</slot>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<div ref="scroll-container" v-bind="tabsAttrs" :data-test="dataTest" @scroll="checkScroll">
|
|
110
|
+
<!-- @slot Use it to add the UTab component. -->
|
|
111
|
+
<slot>
|
|
112
|
+
<UTab
|
|
113
|
+
v-for="(item, index) in options"
|
|
114
|
+
:key="item.value"
|
|
115
|
+
:label="item.label"
|
|
116
|
+
:value="item.value"
|
|
117
|
+
:disabled="item.disabled"
|
|
118
|
+
:size="size"
|
|
119
|
+
v-bind="tabAttrs"
|
|
120
|
+
:data-test="`${dataTest}-item-${index}`"
|
|
121
|
+
/>
|
|
122
|
+
</slot>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div v-if="scrollable && showRightArrow" v-bind="nextAttrs" @click="scrollNext">
|
|
126
|
+
<!--
|
|
127
|
+
@slot Use it to add something instead of the "next" button.
|
|
128
|
+
@binding {string} icon-name
|
|
129
|
+
-->
|
|
130
|
+
<slot name="next" :icon-name="config.defaults.nextIcon">
|
|
131
|
+
<UButton :icon="config.defaults.nextIcon" v-bind="nextButtonAttrs" />
|
|
132
|
+
</slot>
|
|
133
|
+
</div>
|
|
63
134
|
</div>
|
|
64
135
|
</template>
|
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
export default /*tw*/ {
|
|
2
|
+
wrapper: "mb-6 flex gap-1",
|
|
2
3
|
tabs: {
|
|
3
|
-
base: "
|
|
4
|
+
base: "flex flex-nowrap border-b border-gray-200 dark:border-gray-700",
|
|
4
5
|
variants: {
|
|
5
6
|
block: {
|
|
6
7
|
true: "w-full",
|
|
7
8
|
},
|
|
9
|
+
scrollable: {
|
|
10
|
+
true: "overflow-hidden scroll-smooth",
|
|
11
|
+
},
|
|
8
12
|
},
|
|
9
13
|
},
|
|
10
14
|
tab: "{UTab}",
|
|
15
|
+
prev: "",
|
|
16
|
+
next: "",
|
|
17
|
+
scrollButton: {
|
|
18
|
+
base: "{UButton}",
|
|
19
|
+
defaults: {
|
|
20
|
+
size: {
|
|
21
|
+
"2xs": "xs",
|
|
22
|
+
xs: "xs",
|
|
23
|
+
sm: "sm",
|
|
24
|
+
md: "sm",
|
|
25
|
+
lg: "md",
|
|
26
|
+
xl: "md",
|
|
27
|
+
},
|
|
28
|
+
variant: "thirdary",
|
|
29
|
+
square: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
nextButton: "{>scrollButton}",
|
|
33
|
+
prevButton: "{>scrollButton}",
|
|
11
34
|
defaults: {
|
|
12
35
|
size: "md",
|
|
13
36
|
block: false,
|
|
14
37
|
square: false,
|
|
38
|
+
/* icons */
|
|
39
|
+
nextIcon: "chevron_right",
|
|
40
|
+
prevIcon: "chevron_left",
|
|
15
41
|
},
|
|
16
42
|
};
|
|
@@ -37,6 +37,13 @@ export default {
|
|
|
37
37
|
},
|
|
38
38
|
} as Meta;
|
|
39
39
|
|
|
40
|
+
function getOptionsArray(count = 40) {
|
|
41
|
+
return Array.from({ length: count }, (_, index) => ({
|
|
42
|
+
label: `Tab ${index + 1}`,
|
|
43
|
+
value: (index + 1).toString(),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
const DefaultTemplate: StoryFn<UTabsArgs> = (args: UTabsArgs) => ({
|
|
41
48
|
components: { UTabs },
|
|
42
49
|
setup() {
|
|
@@ -86,3 +93,9 @@ DisabledTab.args = {
|
|
|
86
93
|
{ label: "Tab 3", value: 3 },
|
|
87
94
|
],
|
|
88
95
|
};
|
|
96
|
+
|
|
97
|
+
export const Scrollable = DefaultTemplate.bind({});
|
|
98
|
+
Scrollable.args = {
|
|
99
|
+
options: getOptionsArray(),
|
|
100
|
+
scrollable: true,
|
|
101
|
+
};
|