@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.cjs CHANGED
@@ -1,353 +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
- }, () => this.$slots.default?.());
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 = vue.defineComponent({
113
- name: "DestylerTabsContent",
114
- props: destylerTabsContentProps,
115
- setup(props) {
116
- const { forwardRef } = composition.useForwardExpose();
117
- const rootContext = injectTabsRootContext();
118
- const triggerId = vue.computed(() => makeTriggerId(rootContext.baseId, props.value));
119
- const contentId = vue.computed(() => makeContentId(rootContext.baseId, props.value));
120
- const isSelected = vue.computed(() => props.value === rootContext.modelValue.value);
121
- const isMountAnimationPreventedRef = vue.ref(isSelected.value);
122
- vue.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 vue.h(presence.DestylerPresence, {
138
- present: this.isSelected,
139
- forceMount: false
140
- }, {
141
- default: ({ present }) => {
142
- return [
143
- vue.withDirectives(vue.h(primitive.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
- this.$props.forceMount || this.isSelected ? this.$slots.default?.() : null
158
- ]), [
159
- [directives.BindOnceDirective, { id: this.contentId }]
160
- ])
161
- ];
162
- }
163
- });
164
- }
165
- });
166
-
167
- const destylerTabsIndicatorProps = {
168
- as: {
169
- type: [String, Object],
170
- required: false,
171
- default: "button"
172
- },
173
- asChild: {
174
- type: Boolean,
175
- required: false,
176
- default: false
177
- }
178
- };
179
- const DestylerTabsIndicator = vue.defineComponent({
180
- name: "DestylerTabsIndicator",
181
- props: destylerTabsIndicatorProps,
182
- setup() {
183
- const context = injectTabsRootContext();
184
- composition.useForwardExpose();
185
- const indicatorStyle = vue.ref({
186
- size: null,
187
- position: null
188
- });
189
- vue.watch(() => context.modelValue.value, async () => {
190
- await vue.nextTick();
191
- updateIndicatorStyle();
192
- }, { immediate: true });
193
- composition.useResizeObserver(context.tabsList, updateIndicatorStyle);
194
- function updateIndicatorStyle() {
195
- const activeTab = context.tabsList.value?.querySelector('[role="tab"][data-state="active"]');
196
- if (!activeTab)
197
- return;
198
- if (context.orientation.value === "horizontal") {
199
- indicatorStyle.value = {
200
- size: activeTab.offsetWidth,
201
- position: activeTab.offsetLeft
202
- };
203
- } else {
204
- indicatorStyle.value = {
205
- size: activeTab.offsetHeight,
206
- position: activeTab.offsetTop
207
- };
208
- }
209
- }
210
- return {
211
- indicatorStyle
212
- };
213
- },
214
- render() {
215
- return [
216
- typeof this.indicatorStyle.size === "number" ? vue.h(primitive.DestylerPrimitive, vue.mergeProps(this.$props, {
217
- style: {
218
- "--destyler_tabs_indicator_size": `${this.indicatorStyle.size}px`,
219
- "--destyler_tabs_indicator_position": `${this.indicatorStyle.position}px`
220
- }
221
- }), () => this.$slots.default?.()) : null
222
- ];
223
- }
224
- });
225
-
226
- const destylerTabsListProps = {
227
- as: {
228
- type: [String, Object],
229
- required: false,
230
- default: "div"
231
- },
232
- asChild: {
233
- type: Boolean,
234
- required: false,
235
- default: false
236
- },
237
- loop: {
238
- type: Boolean,
239
- required: false,
240
- default: true
241
- }
242
- };
243
- const DestylerTabsList = vue.defineComponent({
244
- name: "DestylerTabsList",
245
- props: destylerTabsListProps,
246
- setup(props) {
247
- const { loop } = vue.toRefs(props);
248
- const { forwardRef, currentElement } = composition.useForwardExpose();
249
- const context = injectTabsRootContext();
250
- context.tabsList = currentElement;
251
- return {
252
- forwardRef,
253
- loop,
254
- context
255
- };
256
- },
257
- render() {
258
- return vue.h(rovingFocus.DestylerRovingFocusGroup, {
259
- asChild: true,
260
- loop: this.loop,
261
- dir: this.context.dir.value,
262
- orientation: this.context.orientation.value
263
- }, () => vue.h(primitive.DestylerPrimitive, {
264
- "ref": (el) => this.forwardRef(el),
265
- "role": "tablist",
266
- "asChild": this.$props.asChild,
267
- "as": this.$props.as,
268
- "aria-orientation": this.context.orientation.value
269
- }, {
270
- default: () => this.$slots.default?.()
271
- }));
272
- }
273
- });
274
-
275
- const destylerTabsTriggerProps = {
276
- as: {
277
- type: [String, Object],
278
- required: false,
279
- default: "button"
280
- },
281
- asChild: {
282
- type: Boolean,
283
- required: false,
284
- default: false
285
- },
286
- value: {
287
- type: String,
288
- required: true
289
- },
290
- disabled: {
291
- type: Boolean,
292
- required: false
293
- }
294
- };
295
- const DestylerTabsTrigger = vue.defineComponent({
296
- name: "DestylerTabsTrigger",
297
- props: destylerTabsTriggerProps,
298
- setup(props) {
299
- const { forwardRef } = composition.useForwardExpose();
300
- const rootContext = injectTabsRootContext();
301
- const triggerId = vue.computed(() => makeTriggerId(rootContext.baseId, props.value));
302
- const contentId = vue.computed(() => makeContentId(rootContext.baseId, props.value));
303
- const isSelected = vue.computed(() => props.value === rootContext.modelValue.value);
304
- return {
305
- forwardRef,
306
- rootContext,
307
- triggerId,
308
- contentId,
309
- isSelected
310
- };
311
- },
312
- render() {
313
- return vue.h(rovingFocus.DestylerRovingFocusItem, {
314
- asChild: true,
315
- focusable: !this.$props.disabled,
316
- active: this.isSelected
317
- }, () => vue.withDirectives(vue.h(primitive.DestylerPrimitive, {
318
- "ref": (el) => this.forwardRef(el),
319
- "role": "tab",
320
- "type": this.$props.as === "button" ? "button" : void 0,
321
- "as": this.$props.as,
322
- "asChild": this.$props.asChild,
323
- "aria-selected": this.isSelected ? "true" : "false",
324
- "aria-controls": this.contentId,
325
- "data-state": this.isSelected ? "active" : "inactive",
326
- "disabled": this.$props.disabled,
327
- "data-disabled": this.$props.disabled ? "" : void 0,
328
- "data-orientation": this.rootContext.orientation.value,
329
- "onMousedown": vue.withModifiers((event) => {
330
- if (!this.$props.disabled && event.ctrlKey === false)
331
- this.rootContext.changeModelValue(this.$props.value);
332
- else
333
- event.preventDefault();
334
- }, ["left"]),
335
- "onKeydown": vue.withModifiers(() => {
336
- this.rootContext.changeModelValue(this.$props.value);
337
- }, ["enter", "space"]),
338
- "onFocus": () => {
339
- const isAutomaticActivation = this.rootContext.activationMode !== "manual";
340
- if (!this.isSelected && !this.$props.disabled && isAutomaticActivation)
341
- this.rootContext.changeModelValue(this.$props.value);
342
- }
343
- }, () => this.$slots.default?.()), [
344
- [directives.BindOnceDirective, { id: this.triggerId }]
345
- ]));
346
- }
347
- });
348
-
349
- exports.DestylerTabsContent = DestylerTabsContent;
350
- exports.DestylerTabsIndicator = DestylerTabsIndicator;
351
- exports.DestylerTabsList = DestylerTabsList;
352
- exports.DestylerTabsRoot = DestylerTabsRoot;
353
- 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;