vueless 0.0.728 → 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.
@@ -54,7 +54,6 @@ export default function useUI<T>(
54
54
 
55
55
  const firstClassKey = Object.keys(defaultConfig || {})[0];
56
56
  const config = ref({}) as Ref<ComponentConfigFull<T>>;
57
- const attrs = useAttrs();
58
57
 
59
58
  watchEffect(() => {
60
59
  const propsConfig = props.config as ComponentConfigFull<T>;
@@ -91,7 +90,7 @@ export default function useUI<T>(
91
90
  }
92
91
 
93
92
  if (key === (topLevelClassKey || firstClassKey)) {
94
- classes = cx([DEFAULT_BASE_CLASSES, vuelessConfig.baseClasses, classes, attrs.class]);
93
+ classes = cx([DEFAULT_BASE_CLASSES, vuelessConfig.baseClasses, classes]);
95
94
  }
96
95
 
97
96
  classes = classes.replaceAll(EXTENDS_PATTERN_REG_EXP, "");
@@ -150,18 +149,21 @@ export default function useUI<T>(
150
149
 
151
150
  const commonAttrs: KeyAttrs = {
152
151
  ...(isTopLevelKey ? attrs : {}),
152
+ "data-vl-child": attrs["data-vl-child"] ? null : true,
153
153
  "vl-component": isDev ? attrs["vl-component"] || componentName || null : null,
154
154
  "vl-key": isDev ? attrs["vl-key"] || configKey || null : null,
155
155
  "vl-child-component": isDev && attrs["vl-component"] ? nestedComponent : null,
156
156
  "vl-child-key": isDev && attrs["vl-component"] ? configKey : null,
157
157
  };
158
158
 
159
+ const topLevelClasses = (!attrs["data-vl-child"] && commonAttrs.class) || "";
160
+
159
161
  /* Delete value key to prevent v-model overwrite. */
160
162
  delete commonAttrs.value;
161
163
 
162
164
  vuelessAttrs.value = {
163
165
  ...commonAttrs,
164
- class: cx([...extendsClasses, toValue(classes)]),
166
+ class: cx([...extendsClasses, toValue(classes), topLevelClasses]),
165
167
  config: getMergedConfig({
166
168
  defaultConfig: extendsKeyConfig,
167
169
  globalConfig: keyConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.728",
3
+ "version": "0.0.730",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
package/types.ts CHANGED
@@ -310,11 +310,12 @@ export type KeyAttrsWithConfig<T> = {
310
310
  } & KeyAttrs;
311
311
 
312
312
  export interface KeyAttrs extends VueAttrs {
313
+ "data-vl-child"?: boolean | null;
313
314
  "vl-component"?: string | null;
314
315
  "vl-key"?: string | null;
315
316
  "vl-child-component"?: string | null;
316
317
  "vl-child-key"?: string | null;
317
- [key: string]: string | undefined | null;
318
+ [key: string]: string | boolean | undefined | null;
318
319
  }
319
320
 
320
321
  export interface VueAttrs {
@@ -1,7 +1,7 @@
1
1
  export default /*tw*/ {
2
2
  tabButton: {
3
3
  base: `
4
- {UButton} -mb-px rounded-none border-0 border-b-2 border-transparent
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 { tabsAttrs, tabAttrs } = useUI<Config>(defaultConfig);
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="tabsAttrs" :data-test="dataTest">
50
- <!-- @slot Use it to add the UTab component. -->
51
- <slot>
52
- <UTab
53
- v-for="(item, index) in options"
54
- :key="item.value"
55
- :label="item.label"
56
- :value="item.value"
57
- :disabled="item.disabled"
58
- :size="size"
59
- v-bind="tabAttrs"
60
- :data-test="`${dataTest}-item-${index}`"
61
- />
62
- </slot>
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: "mb-6 flex flex-nowrap border-b border-gray-200 dark:border-gray-700",
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
  };
@@ -3,3 +3,5 @@
3
3
  `defineProps` is referencing locally declared variables. (vue/valid-define-props)
4
4
  */
5
5
  export const COMPONENT_NAME = "UTabs";
6
+
7
+ export const SCROLL_OFFSET = 200;
@@ -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
+ };
@@ -30,6 +30,11 @@ export interface Props {
30
30
  */
31
31
  size?: "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
32
32
 
33
+ /**
34
+ * Make the Tabs scrollable.
35
+ */
36
+ scrollable?: boolean;
37
+
33
38
  /**
34
39
  * Make the Tabs fill the width with its container.
35
40
  */