@destyler/tabs 0.0.3 → 0.0.4

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/dist/index.mjs CHANGED
@@ -1,347 +1,8 @@
1
- import { defineComponent, toRefs, ref, h, computed, onMounted, withDirectives, watch, nextTick, mergeProps, withModifiers } from 'vue';
2
- import { useDirection, useForwardExpose, useVModel, useId, useResizeObserver } from '@destyler/composition';
3
- import { DestylerPresence } from '@destyler/presence';
4
- import { DestylerPrimitive } from '@destyler/primitive';
5
- import { BindOnceDirective } from '@destyler/directives';
6
- import { createContext } from '@destyler/shared';
7
- import { DestylerRovingFocusGroup, DestylerRovingFocusItem } from '@destyler/roving-focus';
8
-
9
- function makeTriggerId(baseId, value) {
10
- return `${baseId}-trigger-${value}`;
11
- }
12
- function makeContentId(baseId, value) {
13
- return `${baseId}-content-${value}`;
14
- }
15
-
16
- const destylerTabsRootProps = {
17
- as: {
18
- type: [String, Object],
19
- required: false,
20
- default: "div"
21
- },
22
- asChild: {
23
- type: Boolean,
24
- required: false,
25
- default: false
26
- },
27
- modelValue: {
28
- type: String,
29
- required: false
30
- },
31
- defaultValue: {
32
- type: String,
33
- required: false
34
- },
35
- activationMode: {
36
- type: String,
37
- required: false,
38
- default: "automatic"
39
- },
40
- dir: {
41
- type: String,
42
- required: false
43
- },
44
- orientation: {
45
- type: String,
46
- required: false,
47
- default: "horizontal"
48
- }
49
- };
50
- const [injectTabsRootContext, provideTabsRootContext] = createContext("DestylerTabsRoot");
51
- const DestylerTabsRoot = defineComponent({
52
- name: "DestylerTabsRoot",
53
- props: destylerTabsRootProps,
54
- emits: ["update:modelValue"],
55
- setup(props, { emit }) {
56
- const { orientation, dir: propDir } = toRefs(props);
57
- const dir = useDirection(propDir);
58
- useForwardExpose();
59
- const modelValue = useVModel(props, "modelValue", emit, {
60
- defaultValue: props.defaultValue,
61
- passive: props.modelValue === void 0
62
- });
63
- const tabsList = ref();
64
- provideTabsRootContext({
65
- modelValue,
66
- changeModelValue: (value) => {
67
- modelValue.value = value;
68
- },
69
- orientation,
70
- dir,
71
- activationMode: props.activationMode,
72
- baseId: useId(),
73
- tabsList
74
- });
75
- return {
76
- dir,
77
- orientation
78
- };
79
- },
80
- render() {
81
- return h(DestylerPrimitive, {
82
- "as": this.$props.as,
83
- "asChild": this.$props.asChild,
84
- "dir": this.dir,
85
- "data-orientation": this.orientation
86
- }, () => this.$slots.default?.());
87
- }
88
- });
89
-
90
- const destylerTabsContentProps = {
91
- as: {
92
- type: [String, Object],
93
- required: false,
94
- default: "div"
95
- },
96
- asChild: {
97
- type: Boolean,
98
- required: false,
99
- default: false
100
- },
101
- value: {
102
- type: String,
103
- required: true
104
- },
105
- forceMount: {
106
- type: Boolean,
107
- required: false
108
- }
109
- };
110
- const DestylerTabsContent = defineComponent({
111
- name: "DestylerTabsContent",
112
- props: destylerTabsContentProps,
113
- setup(props) {
114
- const { forwardRef } = useForwardExpose();
115
- const rootContext = injectTabsRootContext();
116
- const triggerId = computed(() => makeTriggerId(rootContext.baseId, props.value));
117
- const contentId = computed(() => makeContentId(rootContext.baseId, props.value));
118
- const isSelected = computed(() => props.value === rootContext.modelValue.value);
119
- const isMountAnimationPreventedRef = ref(isSelected.value);
120
- onMounted(() => {
121
- requestAnimationFrame(() => {
122
- isMountAnimationPreventedRef.value = false;
123
- });
124
- });
125
- return {
126
- forwardRef,
127
- rootContext,
128
- triggerId,
129
- contentId,
130
- isSelected,
131
- isMountAnimationPreventedRef
132
- };
133
- },
134
- render() {
135
- return h(DestylerPresence, {
136
- present: this.isSelected,
137
- forceMount: false
138
- }, {
139
- default: ({ present }) => {
140
- return [
141
- withDirectives(h(DestylerPrimitive, {
142
- "ref": (el) => this.forwardRef(el),
143
- "as": this.$props.as,
144
- "asChild": this.$props.asChild,
145
- "role": "tabpanel",
146
- "data-state": this.isSelected ? "active" : "inactive",
147
- "data-orientation": this.rootContext.orientation.value,
148
- "aria-labelledby": this.triggerId,
149
- "hidden": !present.value,
150
- "tabindex": "0",
151
- "style": {
152
- animationDuration: this.isMountAnimationPreventedRef ? "0s" : void 0
153
- }
154
- }, () => [
155
- this.$props.forceMount || this.isSelected ? this.$slots.default?.() : null
156
- ]), [
157
- [BindOnceDirective, { id: this.contentId }]
158
- ])
159
- ];
160
- }
161
- });
162
- }
163
- });
164
-
165
- const destylerTabsIndicatorProps = {
166
- as: {
167
- type: [String, Object],
168
- required: false,
169
- default: "button"
170
- },
171
- asChild: {
172
- type: Boolean,
173
- required: false,
174
- default: false
175
- }
176
- };
177
- const DestylerTabsIndicator = defineComponent({
178
- name: "DestylerTabsIndicator",
179
- props: destylerTabsIndicatorProps,
180
- setup() {
181
- const context = injectTabsRootContext();
182
- useForwardExpose();
183
- const indicatorStyle = ref({
184
- size: null,
185
- position: null
186
- });
187
- watch(() => context.modelValue.value, async () => {
188
- await nextTick();
189
- updateIndicatorStyle();
190
- }, { immediate: true });
191
- useResizeObserver(context.tabsList, updateIndicatorStyle);
192
- function updateIndicatorStyle() {
193
- const activeTab = context.tabsList.value?.querySelector('[role="tab"][data-state="active"]');
194
- if (!activeTab)
195
- return;
196
- if (context.orientation.value === "horizontal") {
197
- indicatorStyle.value = {
198
- size: activeTab.offsetWidth,
199
- position: activeTab.offsetLeft
200
- };
201
- } else {
202
- indicatorStyle.value = {
203
- size: activeTab.offsetHeight,
204
- position: activeTab.offsetTop
205
- };
206
- }
207
- }
208
- return {
209
- indicatorStyle
210
- };
211
- },
212
- render() {
213
- return [
214
- typeof this.indicatorStyle.size === "number" ? h(DestylerPrimitive, mergeProps(this.$props, {
215
- style: {
216
- "--destyler_tabs_indicator_size": `${this.indicatorStyle.size}px`,
217
- "--destyler_tabs_indicator_position": `${this.indicatorStyle.position}px`
218
- }
219
- }), () => this.$slots.default?.()) : null
220
- ];
221
- }
222
- });
223
-
224
- const destylerTabsListProps = {
225
- as: {
226
- type: [String, Object],
227
- required: false,
228
- default: "div"
229
- },
230
- asChild: {
231
- type: Boolean,
232
- required: false,
233
- default: false
234
- },
235
- loop: {
236
- type: Boolean,
237
- required: false,
238
- default: true
239
- }
240
- };
241
- const DestylerTabsList = defineComponent({
242
- name: "DestylerTabsList",
243
- props: destylerTabsListProps,
244
- setup(props) {
245
- const { loop } = toRefs(props);
246
- const { forwardRef, currentElement } = useForwardExpose();
247
- const context = injectTabsRootContext();
248
- context.tabsList = currentElement;
249
- return {
250
- forwardRef,
251
- loop,
252
- context
253
- };
254
- },
255
- render() {
256
- return h(DestylerRovingFocusGroup, {
257
- asChild: true,
258
- loop: this.loop,
259
- dir: this.context.dir.value,
260
- orientation: this.context.orientation.value
261
- }, () => h(DestylerPrimitive, {
262
- "ref": (el) => this.forwardRef(el),
263
- "role": "tablist",
264
- "asChild": this.$props.asChild,
265
- "as": this.$props.as,
266
- "aria-orientation": this.context.orientation.value
267
- }, {
268
- default: () => this.$slots.default?.()
269
- }));
270
- }
271
- });
272
-
273
- const destylerTabsTriggerProps = {
274
- as: {
275
- type: [String, Object],
276
- required: false,
277
- default: "button"
278
- },
279
- asChild: {
280
- type: Boolean,
281
- required: false,
282
- default: false
283
- },
284
- value: {
285
- type: String,
286
- required: true
287
- },
288
- disabled: {
289
- type: Boolean,
290
- required: false
291
- }
292
- };
293
- const DestylerTabsTrigger = defineComponent({
294
- name: "DestylerTabsTrigger",
295
- props: destylerTabsTriggerProps,
296
- setup(props) {
297
- const { forwardRef } = useForwardExpose();
298
- const rootContext = injectTabsRootContext();
299
- const triggerId = computed(() => makeTriggerId(rootContext.baseId, props.value));
300
- const contentId = computed(() => makeContentId(rootContext.baseId, props.value));
301
- const isSelected = computed(() => props.value === rootContext.modelValue.value);
302
- return {
303
- forwardRef,
304
- rootContext,
305
- triggerId,
306
- contentId,
307
- isSelected
308
- };
309
- },
310
- render() {
311
- return h(DestylerRovingFocusItem, {
312
- asChild: true,
313
- focusable: !this.$props.disabled,
314
- active: this.isSelected
315
- }, () => withDirectives(h(DestylerPrimitive, {
316
- "ref": (el) => this.forwardRef(el),
317
- "role": "tab",
318
- "type": this.$props.as === "button" ? "button" : void 0,
319
- "as": this.$props.as,
320
- "asChild": this.$props.asChild,
321
- "aria-selected": this.isSelected ? "true" : "false",
322
- "aria-controls": this.contentId,
323
- "data-state": this.isSelected ? "active" : "inactive",
324
- "disabled": this.$props.disabled,
325
- "data-disabled": this.$props.disabled ? "" : void 0,
326
- "data-orientation": this.rootContext.orientation.value,
327
- "onMousedown": withModifiers((event) => {
328
- if (!this.$props.disabled && event.ctrlKey === false)
329
- this.rootContext.changeModelValue(this.$props.value);
330
- else
331
- event.preventDefault();
332
- }, ["left"]),
333
- "onKeydown": withModifiers(() => {
334
- this.rootContext.changeModelValue(this.$props.value);
335
- }, ["enter", "space"]),
336
- "onFocus": () => {
337
- const isAutomaticActivation = this.rootContext.activationMode !== "manual";
338
- if (!this.isSelected && !this.$props.disabled && isAutomaticActivation)
339
- this.rootContext.changeModelValue(this.$props.value);
340
- }
341
- }, () => this.$slots.default?.()), [
342
- [BindOnceDirective, { id: this.triggerId }]
343
- ]));
344
- }
345
- });
346
-
347
- export { DestylerTabsContent, DestylerTabsIndicator, DestylerTabsList, DestylerTabsRoot, DestylerTabsTrigger };
1
+ export { TabsContent, TabsIndicator, TabsList, TabsRoot, TabsTrigger, tabsContentProps, tabsIndicatorProps, tabsListProps, tabsRootProps, tabsTriggerProps } from './component.mjs';
2
+ import 'vue';
3
+ import '@destyler/composition';
4
+ import '@destyler/presence';
5
+ import '@destyler/primitive';
6
+ import '@destyler/directives';
7
+ import '@destyler/shared';
8
+ import '@destyler/roving-focus';
package/dist/resolver.cjs CHANGED
@@ -3,18 +3,22 @@
3
3
  const name = "@destyler/tabs";
4
4
 
5
5
  const packageName = name;
6
- const destylerComponentName = [
7
- "DestylerTemplate"
6
+ const tabsComponentName = [
7
+ "TabsContent",
8
+ "TabsIndicator",
9
+ "TabsList",
10
+ "TabsRoot",
11
+ "TabsTrigger"
8
12
  ];
9
- function DestylerTemplateResolver() {
13
+ function TabsResolver() {
10
14
  return {
11
15
  type: "component",
12
16
  resolve: (name2) => {
13
- if (destylerComponentName.includes(name2))
17
+ if (tabsComponentName.includes(name2))
14
18
  return { name: name2, from: packageName };
15
19
  }
16
20
  };
17
21
  }
18
22
 
19
- exports.DestylerTemplateResolver = DestylerTemplateResolver;
20
- exports.destylerComponentName = destylerComponentName;
23
+ exports.TabsResolver = TabsResolver;
24
+ exports.tabsComponentName = tabsComponentName;
@@ -1,6 +1,6 @@
1
1
  import { ComponentResolver } from 'unplugin-vue-components';
2
2
 
3
- declare const destylerComponentName: string[];
4
- declare function DestylerTemplateResolver(): ComponentResolver;
3
+ declare const tabsComponentName: string[];
4
+ declare function TabsResolver(): ComponentResolver;
5
5
 
6
- export { DestylerTemplateResolver, destylerComponentName };
6
+ export { TabsResolver, tabsComponentName };
@@ -1,6 +1,6 @@
1
1
  import { ComponentResolver } from 'unplugin-vue-components';
2
2
 
3
- declare const destylerComponentName: string[];
4
- declare function DestylerTemplateResolver(): ComponentResolver;
3
+ declare const tabsComponentName: string[];
4
+ declare function TabsResolver(): ComponentResolver;
5
5
 
6
- export { DestylerTemplateResolver, destylerComponentName };
6
+ export { TabsResolver, tabsComponentName };
@@ -1,6 +1,6 @@
1
1
  import { ComponentResolver } from 'unplugin-vue-components';
2
2
 
3
- declare const destylerComponentName: string[];
4
- declare function DestylerTemplateResolver(): ComponentResolver;
3
+ declare const tabsComponentName: string[];
4
+ declare function TabsResolver(): ComponentResolver;
5
5
 
6
- export { DestylerTemplateResolver, destylerComponentName };
6
+ export { TabsResolver, tabsComponentName };
package/dist/resolver.mjs CHANGED
@@ -1,17 +1,21 @@
1
1
  const name = "@destyler/tabs";
2
2
 
3
3
  const packageName = name;
4
- const destylerComponentName = [
5
- "DestylerTemplate"
4
+ const tabsComponentName = [
5
+ "TabsContent",
6
+ "TabsIndicator",
7
+ "TabsList",
8
+ "TabsRoot",
9
+ "TabsTrigger"
6
10
  ];
7
- function DestylerTemplateResolver() {
11
+ function TabsResolver() {
8
12
  return {
9
13
  type: "component",
10
14
  resolve: (name2) => {
11
- if (destylerComponentName.includes(name2))
15
+ if (tabsComponentName.includes(name2))
12
16
  return { name: name2, from: packageName };
13
17
  }
14
18
  };
15
19
  }
16
20
 
17
- export { DestylerTemplateResolver, destylerComponentName };
21
+ export { TabsResolver, tabsComponentName };
package/package.json CHANGED
@@ -1,25 +1,22 @@
1
1
  {
2
2
  "name": "@destyler/tabs",
3
3
  "type": "module",
4
- "version": "0.0.3",
5
- "description": "unstyled tabs component for vue",
4
+ "version": "0.0.4",
5
+ "description": "a set of layered sections of content—known as tab panels—that are displayed one at a time.",
6
6
  "author": "Elone Hoo <elonehoo@gmail.com>",
7
7
  "license": "MIT",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.cjs"
10
+ "types": "./dist/index.d.mts",
11
+ "default": "./dist/index.mjs"
13
12
  },
14
13
  "./resolver": {
15
- "types": "./dist/resolver.d.ts",
16
- "import": "./dist/resolver.mjs",
17
- "require": "./dist/resolver.cjs"
14
+ "types": "./dist/resolver.d.mts",
15
+ "default": "./dist/resolver.mjs"
18
16
  },
19
17
  "./component": {
20
- "types": "./dist/component.d.ts",
21
- "import": "./dist/component.mjs",
22
- "require": "./dist/component.cjs"
18
+ "types": "./dist/component.d.mts",
19
+ "default": "./dist/component.mjs"
23
20
  },
24
21
  "./*": "./*"
25
22
  },
@@ -31,18 +28,19 @@
31
28
  "dist"
32
29
  ],
33
30
  "peerDependencies": {
34
- "vue": ">=3.3.4"
31
+ "vue": ">=3.4.21"
35
32
  },
36
33
  "dependencies": {
37
- "@destyler/composition": "0.0.3",
38
- "@destyler/directives": "0.0.3",
39
- "@destyler/shared": "0.0.3",
40
- "@destyler/roving-focus": "0.0.3",
41
- "@destyler/primitive": "0.0.3",
42
- "@destyler/presence": "0.0.3"
34
+ "@destyler/directives": "0.0.4",
35
+ "@destyler/presence": "0.0.4",
36
+ "@destyler/primitive": "0.0.4",
37
+ "@destyler/composition": "0.0.4",
38
+ "@destyler/shared": "0.0.4",
39
+ "@destyler/roving-focus": "0.0.4"
43
40
  },
44
41
  "scripts": {
45
42
  "clear": "rimraf ./dist",
46
- "build": "pnpm run clear && unbuild"
43
+ "build": "pnpm run clear && unbuild",
44
+ "stub": "unbuild --stub"
47
45
  }
48
46
  }