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