@destyler/tabs 0.0.2 → 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,365 +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
- }, {
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": (el) => this.forwardRef(el),
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": (el) => this.forwardRef(el),
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": (el) => this.forwardRef(el),
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 };
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,24 +1,22 @@
1
1
  {
2
2
  "name": "@destyler/tabs",
3
- "version": "0.0.2",
4
- "description": "unstyled tabs component for vue",
3
+ "type": "module",
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.",
5
6
  "author": "Elone Hoo <elonehoo@gmail.com>",
6
7
  "license": "MIT",
7
8
  "exports": {
8
9
  ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.cjs"
10
+ "types": "./dist/index.d.mts",
11
+ "default": "./dist/index.mjs"
12
12
  },
13
13
  "./resolver": {
14
- "types": "./dist/resolver.d.ts",
15
- "import": "./dist/resolver.mjs",
16
- "require": "./dist/resolver.cjs"
14
+ "types": "./dist/resolver.d.mts",
15
+ "default": "./dist/resolver.mjs"
17
16
  },
18
17
  "./component": {
19
- "types": "./dist/component.d.ts",
20
- "import": "./dist/component.mjs",
21
- "require": "./dist/component.cjs"
18
+ "types": "./dist/component.d.mts",
19
+ "default": "./dist/component.mjs"
22
20
  },
23
21
  "./*": "./*"
24
22
  },
@@ -30,18 +28,19 @@
30
28
  "dist"
31
29
  ],
32
30
  "peerDependencies": {
33
- "vue": ">=3.3.4"
31
+ "vue": ">=3.4.21"
34
32
  },
35
33
  "dependencies": {
36
- "@destyler/composition": "0.0.2",
37
- "@destyler/directives": "0.0.2",
38
- "@destyler/presence": "0.0.2",
39
- "@destyler/primitive": "0.0.2",
40
- "@destyler/shared": "0.0.2",
41
- "@destyler/roving-focus": "0.0.2"
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"
42
40
  },
43
41
  "scripts": {
44
42
  "clear": "rimraf ./dist",
45
- "build": "pnpm run clear && unbuild"
43
+ "build": "pnpm run clear && unbuild",
44
+ "stub": "unbuild --stub"
46
45
  }
47
46
  }