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