@destyler/tabs 0.0.6 → 0.0.7-beta.1

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.
@@ -1,371 +0,0 @@
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 { Presence } from '@destyler/presence';
4
- import { primitiveProps, Primitive } from '@destyler/primitive';
5
- import { BindOnceDirective } from '@destyler/directives';
6
- import { createContext } from '@destyler/shared';
7
- import { RovingFocusGroup, RovingFocusItem } 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 tabsRootProps = {
17
- ...primitiveProps,
18
- /**
19
- * The controlled value of the tab to activate. Can be bind as `v-model`.
20
- */
21
- modelValue: {
22
- type: String,
23
- required: false
24
- },
25
- /**
26
- * The value of the tab that should be active when initially rendered. Use when you do not need to control the state of the tabs
27
- */
28
- defaultValue: {
29
- type: String,
30
- required: false
31
- },
32
- /**
33
- * Whether a tab is activated automatically or manually.
34
- *
35
- * @default automatic
36
- */
37
- activationMode: {
38
- type: String,
39
- required: false,
40
- default: "automatic"
41
- },
42
- /**
43
- * The reading direction of the combobox when applicable.
44
- */
45
- dir: {
46
- type: String,
47
- required: false
48
- },
49
- /**
50
- * The orientation the tabs are layed out.
51
- * Mainly so arrow navigation is done accordingly (left & right vs. up & down)
52
- *
53
- * @default horizontal
54
- */
55
- orientation: {
56
- type: String,
57
- required: false,
58
- default: "horizontal"
59
- }
60
- };
61
- const tabsRootEmits = {
62
- /**
63
- * Event handler called when the value changes
64
- */
65
- "update:modelValue": (_value) => true
66
- };
67
- const [injectTabsRootContext, provideTabsRootContext] = createContext("DestylerTabsRoot");
68
- const TabsRoot = defineComponent({
69
- name: "DestylerTabsRoot",
70
- props: tabsRootProps,
71
- emits: tabsRootEmits,
72
- setup(props, { emit }) {
73
- const { orientation, dir: propDir } = toRefs(props);
74
- const dir = useDirection(propDir);
75
- useForwardExpose();
76
- const modelValue = useVModel(props, "modelValue", emit, {
77
- defaultValue: props.defaultValue,
78
- passive: props.modelValue === void 0
79
- });
80
- const tabsList = ref();
81
- provideTabsRootContext({
82
- modelValue,
83
- changeModelValue: (value) => {
84
- modelValue.value = value;
85
- },
86
- orientation,
87
- dir,
88
- activationMode: props.activationMode,
89
- baseId: useId(),
90
- tabsList
91
- });
92
- return {
93
- dir,
94
- orientation
95
- };
96
- },
97
- render() {
98
- return h(Primitive, {
99
- "as": this.$props.as,
100
- "asChild": this.$props.asChild,
101
- "dir": this.dir,
102
- "data-orientation": this.orientation
103
- }, () => this.$slots.default?.());
104
- }
105
- });
106
-
107
- const tabsContentProps = {
108
- ...primitiveProps,
109
- /**
110
- * A unique value that associates the content with a trigger.
111
- */
112
- value: {
113
- type: String,
114
- required: true
115
- },
116
- /**
117
- * Used to force mounting when more control is needed. Useful when
118
- * controlling animation with Vue animation libraries.
119
- */
120
- forceMount: {
121
- type: Boolean,
122
- required: false
123
- }
124
- };
125
- const TabsContent = defineComponent({
126
- name: "DestylerTabsContent",
127
- props: tabsContentProps,
128
- setup(props) {
129
- const { forwardRef } = useForwardExpose();
130
- const rootContext = injectTabsRootContext();
131
- const triggerId = computed(
132
- () => makeTriggerId(rootContext.baseId, props.value)
133
- );
134
- const contentId = computed(
135
- () => makeContentId(rootContext.baseId, props.value)
136
- );
137
- const isSelected = computed(
138
- () => props.value === rootContext.modelValue.value
139
- );
140
- const isMountAnimationPreventedRef = ref(isSelected.value);
141
- onMounted(() => {
142
- requestAnimationFrame(() => {
143
- isMountAnimationPreventedRef.value = false;
144
- });
145
- });
146
- return {
147
- forwardRef,
148
- rootContext,
149
- triggerId,
150
- contentId,
151
- isSelected,
152
- isMountAnimationPreventedRef
153
- };
154
- },
155
- render() {
156
- return h(
157
- Presence,
158
- {
159
- present: this.isSelected,
160
- forceMount: false
161
- },
162
- {
163
- default: ({ present }) => [
164
- withDirectives(
165
- h(
166
- Primitive,
167
- {
168
- "ref": (el) => this.forwardRef(el),
169
- "as": this.$props.as,
170
- "asChild": this.$props.asChild,
171
- "role": "tabpanel",
172
- "data-state": this.isSelected ? "active" : "inactive",
173
- "data-orientation": this.rootContext.orientation.value,
174
- "aria-labelledby": this.triggerId,
175
- "hidden": !present.value,
176
- "tabindex": "0",
177
- "style": {
178
- animationDuration: this.isMountAnimationPreventedRef ? "0s" : void 0
179
- }
180
- },
181
- () => [
182
- this.$props.forceMount || this.isSelected ? this.$slots.default?.() : null
183
- ]
184
- ),
185
- [[BindOnceDirective, { id: this.contentId }]]
186
- )
187
- ]
188
- }
189
- );
190
- }
191
- });
192
-
193
- const tabsIndicatorProps = {
194
- ...primitiveProps,
195
- /**
196
- * @default button
197
- */
198
- as: {
199
- ...primitiveProps.as,
200
- default: "button"
201
- }
202
- };
203
- const TabsIndicator = defineComponent({
204
- name: "DestylerTabsIndicator",
205
- props: tabsIndicatorProps,
206
- setup() {
207
- const context = injectTabsRootContext();
208
- useForwardExpose();
209
- const indicatorStyle = ref({
210
- size: null,
211
- position: null
212
- });
213
- watch(() => context.modelValue.value, async () => {
214
- await nextTick();
215
- updateIndicatorStyle();
216
- }, { immediate: true });
217
- useResizeObserver(context.tabsList, updateIndicatorStyle);
218
- function updateIndicatorStyle() {
219
- const activeTab = context.tabsList.value?.querySelector('[role="tab"][data-state="active"]');
220
- if (!activeTab)
221
- return;
222
- if (context.orientation.value === "horizontal") {
223
- indicatorStyle.value = {
224
- size: activeTab.offsetWidth,
225
- position: activeTab.offsetLeft
226
- };
227
- } else {
228
- indicatorStyle.value = {
229
- size: activeTab.offsetHeight,
230
- position: activeTab.offsetTop
231
- };
232
- }
233
- }
234
- return {
235
- indicatorStyle
236
- };
237
- },
238
- render() {
239
- if (typeof this.indicatorStyle.size === "number") {
240
- return h(Primitive, mergeProps(this.$props, this.$attrs, {
241
- style: {
242
- "--destyler-tabs-indicator-size": `${this.indicatorStyle.size}px`,
243
- "--destyler-tabs-indicator-position": `${this.indicatorStyle.position}px`
244
- }
245
- }), () => this.$slots.default?.());
246
- }
247
- }
248
- });
249
-
250
- const tabsListProps = {
251
- ...primitiveProps,
252
- /**
253
- * When `true`, keyboard navigation will loop from last tab to first, and vice versa.
254
- */
255
- loop: {
256
- type: Boolean,
257
- required: false,
258
- default: true
259
- }
260
- };
261
- const TabsList = defineComponent({
262
- name: "DestylerTabsList",
263
- props: tabsListProps,
264
- setup(props) {
265
- const { loop } = toRefs(props);
266
- const { forwardRef, currentElement } = useForwardExpose();
267
- const context = injectTabsRootContext();
268
- context.tabsList = currentElement;
269
- return {
270
- forwardRef,
271
- loop,
272
- context
273
- };
274
- },
275
- render() {
276
- return h(RovingFocusGroup, {
277
- asChild: true,
278
- loop: this.loop,
279
- dir: this.context.dir.value,
280
- orientation: this.context.orientation.value
281
- }, () => h(Primitive, {
282
- "ref": (el) => this.forwardRef(el),
283
- "role": "tablist",
284
- "asChild": this.$props.asChild,
285
- "as": this.$props.as,
286
- "aria-orientation": this.context.orientation.value
287
- }, {
288
- default: () => this.$slots.default?.()
289
- }));
290
- }
291
- });
292
-
293
- const tabsTriggerProps = {
294
- ...primitiveProps,
295
- /**
296
- * @default button
297
- */
298
- as: {
299
- ...primitiveProps.as,
300
- default: "button"
301
- },
302
- /**
303
- * A unique value that associates the trigger with a content.
304
- */
305
- value: {
306
- type: String,
307
- required: true
308
- },
309
- /**
310
- * When `true`, prevents the user from interacting with the tab.
311
- */
312
- disabled: {
313
- type: Boolean,
314
- required: false
315
- }
316
- };
317
- const TabsTrigger = defineComponent({
318
- name: "DestylerTabsTrigger",
319
- props: tabsTriggerProps,
320
- setup(props) {
321
- const { forwardRef } = useForwardExpose();
322
- const rootContext = injectTabsRootContext();
323
- const triggerId = computed(() => makeTriggerId(rootContext.baseId, props.value));
324
- const contentId = computed(() => makeContentId(rootContext.baseId, props.value));
325
- const isSelected = computed(() => props.value === rootContext.modelValue.value);
326
- return {
327
- forwardRef,
328
- rootContext,
329
- triggerId,
330
- contentId,
331
- isSelected
332
- };
333
- },
334
- render() {
335
- return h(RovingFocusItem, {
336
- asChild: true,
337
- focusable: !this.$props.disabled,
338
- active: this.isSelected
339
- }, () => withDirectives(h(Primitive, {
340
- "ref": (el) => this.forwardRef(el),
341
- "role": "tab",
342
- "type": this.$props.as === "button" ? "button" : void 0,
343
- "as": this.$props.as,
344
- "asChild": this.$props.asChild,
345
- "aria-selected": this.isSelected ? "true" : "false",
346
- "aria-controls": this.contentId,
347
- "data-state": this.isSelected ? "active" : "inactive",
348
- "disabled": this.$props.disabled,
349
- "data-disabled": this.$props.disabled ? "" : void 0,
350
- "data-orientation": this.rootContext.orientation.value,
351
- "onMousedown": withModifiers((event) => {
352
- if (!this.$props.disabled && event.ctrlKey === false)
353
- this.rootContext.changeModelValue(this.$props.value);
354
- else
355
- event.preventDefault();
356
- }, ["left"]),
357
- "onKeydown": withModifiers(() => {
358
- this.rootContext.changeModelValue(this.$props.value);
359
- }, ["enter", "space"]),
360
- "onFocus": () => {
361
- const isAutomaticActivation = this.rootContext.activationMode !== "manual";
362
- if (!this.isSelected && !this.$props.disabled && isAutomaticActivation)
363
- this.rootContext.changeModelValue(this.$props.value);
364
- }
365
- }, () => this.$slots.default?.()), [
366
- [BindOnceDirective, { id: this.triggerId }]
367
- ]));
368
- }
369
- });
370
-
371
- export { TabsContent, TabsIndicator, TabsList, TabsRoot, TabsTrigger, tabsContentProps, tabsIndicatorProps, tabsListProps, tabsRootEmits, tabsRootProps, tabsTriggerProps };
package/dist/resolver.cjs DELETED
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- const name = "@destyler/tabs";
4
-
5
- const packageName = name;
6
- const tabsComponentName = [
7
- "TabsContent",
8
- "TabsIndicator",
9
- "TabsList",
10
- "TabsRoot",
11
- "TabsTrigger"
12
- ];
13
- function TabsResolver() {
14
- return {
15
- type: "component",
16
- resolve: (name2) => {
17
- if (tabsComponentName.includes(name2))
18
- return { name: name2, from: packageName };
19
- }
20
- };
21
- }
22
-
23
- exports.TabsResolver = TabsResolver;
24
- exports.tabsComponentName = tabsComponentName;
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const tabsComponentName: string[];
4
- declare function TabsResolver(): ComponentResolver;
5
-
6
- export { TabsResolver, tabsComponentName };
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const tabsComponentName: string[];
4
- declare function TabsResolver(): ComponentResolver;
5
-
6
- export { TabsResolver, tabsComponentName };
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const tabsComponentName: string[];
4
- declare function TabsResolver(): ComponentResolver;
5
-
6
- export { TabsResolver, tabsComponentName };
package/dist/resolver.mjs DELETED
@@ -1,21 +0,0 @@
1
- const name = "@destyler/tabs";
2
-
3
- const packageName = name;
4
- const tabsComponentName = [
5
- "TabsContent",
6
- "TabsIndicator",
7
- "TabsList",
8
- "TabsRoot",
9
- "TabsTrigger"
10
- ];
11
- function TabsResolver() {
12
- return {
13
- type: "component",
14
- resolve: (name2) => {
15
- if (tabsComponentName.includes(name2))
16
- return { name: name2, from: packageName };
17
- }
18
- };
19
- }
20
-
21
- export { TabsResolver, tabsComponentName };