@zag-js/steps 1.34.1 → 1.35.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.
- package/dist/index.d.mts +8 -212
- package/dist/index.d.ts +8 -212
- package/dist/index.js +36 -347
- package/dist/index.mjs +9 -343
- package/dist/steps.anatomy.d.mts +6 -0
- package/dist/steps.anatomy.d.ts +6 -0
- package/dist/steps.anatomy.js +45 -0
- package/dist/steps.anatomy.mjs +19 -0
- package/dist/steps.connect.d.mts +7 -0
- package/dist/steps.connect.d.ts +7 -0
- package/dist/steps.connect.js +224 -0
- package/dist/steps.connect.mjs +189 -0
- package/dist/steps.dom.d.mts +8 -0
- package/dist/steps.dom.d.ts +8 -0
- package/dist/steps.dom.js +39 -0
- package/dist/steps.dom.mjs +11 -0
- package/dist/steps.machine.d.mts +7 -0
- package/dist/steps.machine.d.ts +7 -0
- package/dist/steps.machine.js +147 -0
- package/dist/steps.machine.mjs +122 -0
- package/dist/steps.props.d.mts +8 -0
- package/dist/steps.props.d.ts +8 -0
- package/dist/steps.props.js +50 -0
- package/dist/steps.props.mjs +24 -0
- package/dist/steps.types.d.mts +201 -0
- package/dist/steps.types.d.ts +201 -0
- package/dist/steps.types.js +18 -0
- package/dist/steps.types.mjs +0 -0
- package/package.json +17 -7
package/dist/index.mjs
CHANGED
|
@@ -1,344 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"list",
|
|
11
|
-
"item",
|
|
12
|
-
"trigger",
|
|
13
|
-
"indicator",
|
|
14
|
-
"separator",
|
|
15
|
-
"content",
|
|
16
|
-
"nextTrigger",
|
|
17
|
-
"prevTrigger",
|
|
18
|
-
"progress"
|
|
19
|
-
);
|
|
20
|
-
var parts = anatomy.build();
|
|
21
|
-
|
|
22
|
-
// src/steps.dom.ts
|
|
23
|
-
var getRootId = (ctx) => ctx.ids?.root ?? `steps:${ctx.id}`;
|
|
24
|
-
var getListId = (ctx) => ctx.ids?.list ?? `steps:${ctx.id}:list`;
|
|
25
|
-
var getTriggerId = (ctx, index) => ctx.ids?.triggerId?.(index) ?? `steps:${ctx.id}:trigger:${index}`;
|
|
26
|
-
var getContentId = (ctx, index) => ctx.ids?.contentId?.(index) ?? `steps:${ctx.id}:content:${index}`;
|
|
27
|
-
|
|
28
|
-
// src/steps.connect.ts
|
|
29
|
-
function connect(service, normalize) {
|
|
30
|
-
const { context, send, computed, prop, scope } = service;
|
|
31
|
-
const step = context.get("step");
|
|
32
|
-
const count = prop("count");
|
|
33
|
-
const percent = computed("percent");
|
|
34
|
-
const hasNextStep = computed("hasNextStep");
|
|
35
|
-
const hasPrevStep = computed("hasPrevStep");
|
|
36
|
-
const isStepValid = (index) => {
|
|
37
|
-
return prop("isStepValid")?.(index) ?? true;
|
|
38
|
-
};
|
|
39
|
-
const isStepSkippable = (index) => {
|
|
40
|
-
return prop("isStepSkippable")?.(index) ?? false;
|
|
41
|
-
};
|
|
42
|
-
const getItemState = (props2) => ({
|
|
43
|
-
triggerId: getTriggerId(scope, props2.index),
|
|
44
|
-
contentId: getContentId(scope, props2.index),
|
|
45
|
-
current: props2.index === step,
|
|
46
|
-
completed: props2.index < step,
|
|
47
|
-
incomplete: props2.index > step,
|
|
48
|
-
index: props2.index,
|
|
49
|
-
first: props2.index === 0,
|
|
50
|
-
last: props2.index === count - 1,
|
|
51
|
-
skippable: isStepSkippable(props2.index),
|
|
52
|
-
isValid: () => isStepValid(props2.index)
|
|
53
|
-
});
|
|
54
|
-
const goToNextStep = () => {
|
|
55
|
-
send({ type: "STEP.NEXT", src: "next.trigger.click" });
|
|
56
|
-
};
|
|
57
|
-
const goToPrevStep = () => {
|
|
58
|
-
send({ type: "STEP.PREV", src: "prev.trigger.click" });
|
|
59
|
-
};
|
|
60
|
-
const resetStep = () => {
|
|
61
|
-
send({ type: "STEP.RESET", src: "reset.trigger.click" });
|
|
62
|
-
};
|
|
63
|
-
const setStep = (value) => {
|
|
64
|
-
send({ type: "STEP.SET", value, src: "api.setValue" });
|
|
65
|
-
};
|
|
66
|
-
return {
|
|
67
|
-
value: step,
|
|
68
|
-
count,
|
|
69
|
-
percent,
|
|
70
|
-
hasNextStep,
|
|
71
|
-
hasPrevStep,
|
|
72
|
-
isCompleted: computed("completed"),
|
|
73
|
-
isStepValid,
|
|
74
|
-
isStepSkippable,
|
|
75
|
-
goToNextStep,
|
|
76
|
-
goToPrevStep,
|
|
77
|
-
resetStep,
|
|
78
|
-
getItemState,
|
|
79
|
-
setStep,
|
|
80
|
-
getRootProps() {
|
|
81
|
-
return normalize.element({
|
|
82
|
-
...parts.root.attrs,
|
|
83
|
-
id: getRootId(scope),
|
|
84
|
-
dir: prop("dir"),
|
|
85
|
-
"data-orientation": prop("orientation"),
|
|
86
|
-
style: {
|
|
87
|
-
"--percent": `${percent}%`
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
getListProps() {
|
|
92
|
-
const arr = fromLength(count);
|
|
93
|
-
const triggerIds = arr.map((_, index) => getTriggerId(scope, index));
|
|
94
|
-
return normalize.element({
|
|
95
|
-
...parts.list.attrs,
|
|
96
|
-
dir: prop("dir"),
|
|
97
|
-
id: getListId(scope),
|
|
98
|
-
role: "tablist",
|
|
99
|
-
"aria-owns": triggerIds.join(" "),
|
|
100
|
-
"aria-orientation": prop("orientation"),
|
|
101
|
-
"data-orientation": prop("orientation")
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
getItemProps(props2) {
|
|
105
|
-
const itemState = getItemState(props2);
|
|
106
|
-
return normalize.element({
|
|
107
|
-
...parts.item.attrs,
|
|
108
|
-
dir: prop("dir"),
|
|
109
|
-
"aria-current": itemState.current ? "step" : void 0,
|
|
110
|
-
"data-orientation": prop("orientation"),
|
|
111
|
-
"data-skippable": dataAttr(itemState.skippable)
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
getTriggerProps(props2) {
|
|
115
|
-
const itemState = getItemState(props2);
|
|
116
|
-
return normalize.button({
|
|
117
|
-
...parts.trigger.attrs,
|
|
118
|
-
id: itemState.triggerId,
|
|
119
|
-
role: "tab",
|
|
120
|
-
dir: prop("dir"),
|
|
121
|
-
tabIndex: !prop("linear") || itemState.current ? 0 : -1,
|
|
122
|
-
"aria-selected": itemState.current,
|
|
123
|
-
"aria-controls": itemState.contentId,
|
|
124
|
-
"data-state": itemState.current ? "open" : "closed",
|
|
125
|
-
"data-orientation": prop("orientation"),
|
|
126
|
-
"data-complete": dataAttr(itemState.completed),
|
|
127
|
-
"data-current": dataAttr(itemState.current),
|
|
128
|
-
"data-incomplete": dataAttr(itemState.incomplete),
|
|
129
|
-
onClick(event) {
|
|
130
|
-
if (event.defaultPrevented) return;
|
|
131
|
-
if (prop("linear")) return;
|
|
132
|
-
send({ type: "STEP.SET", value: props2.index, src: "trigger.click" });
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
getContentProps(props2) {
|
|
137
|
-
const itemState = getItemState(props2);
|
|
138
|
-
return normalize.element({
|
|
139
|
-
...parts.content.attrs,
|
|
140
|
-
dir: prop("dir"),
|
|
141
|
-
id: itemState.contentId,
|
|
142
|
-
role: "tabpanel",
|
|
143
|
-
tabIndex: 0,
|
|
144
|
-
hidden: !itemState.current,
|
|
145
|
-
"data-state": itemState.current ? "open" : "closed",
|
|
146
|
-
"data-orientation": prop("orientation"),
|
|
147
|
-
"aria-labelledby": itemState.triggerId
|
|
148
|
-
});
|
|
149
|
-
},
|
|
150
|
-
getIndicatorProps(props2) {
|
|
151
|
-
const itemState = getItemState(props2);
|
|
152
|
-
return normalize.element({
|
|
153
|
-
...parts.indicator.attrs,
|
|
154
|
-
dir: prop("dir"),
|
|
155
|
-
"aria-hidden": true,
|
|
156
|
-
"data-complete": dataAttr(itemState.completed),
|
|
157
|
-
"data-current": dataAttr(itemState.current),
|
|
158
|
-
"data-incomplete": dataAttr(itemState.incomplete)
|
|
159
|
-
});
|
|
160
|
-
},
|
|
161
|
-
getSeparatorProps(props2) {
|
|
162
|
-
const itemState = getItemState(props2);
|
|
163
|
-
return normalize.element({
|
|
164
|
-
...parts.separator.attrs,
|
|
165
|
-
dir: prop("dir"),
|
|
166
|
-
"data-orientation": prop("orientation"),
|
|
167
|
-
"data-complete": dataAttr(itemState.completed),
|
|
168
|
-
"data-current": dataAttr(itemState.current),
|
|
169
|
-
"data-incomplete": dataAttr(itemState.incomplete)
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
getNextTriggerProps() {
|
|
173
|
-
return normalize.button({
|
|
174
|
-
...parts.nextTrigger.attrs,
|
|
175
|
-
dir: prop("dir"),
|
|
176
|
-
type: "button",
|
|
177
|
-
disabled: !hasNextStep,
|
|
178
|
-
onClick(event) {
|
|
179
|
-
if (event.defaultPrevented) return;
|
|
180
|
-
goToNextStep();
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
},
|
|
184
|
-
getPrevTriggerProps() {
|
|
185
|
-
return normalize.button({
|
|
186
|
-
dir: prop("dir"),
|
|
187
|
-
...parts.prevTrigger.attrs,
|
|
188
|
-
type: "button",
|
|
189
|
-
disabled: !hasPrevStep,
|
|
190
|
-
onClick(event) {
|
|
191
|
-
if (event.defaultPrevented) return;
|
|
192
|
-
goToPrevStep();
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
getProgressProps() {
|
|
197
|
-
return normalize.element({
|
|
198
|
-
dir: prop("dir"),
|
|
199
|
-
...parts.progress.attrs,
|
|
200
|
-
role: "progressbar",
|
|
201
|
-
"aria-valuenow": percent,
|
|
202
|
-
"aria-valuemin": 0,
|
|
203
|
-
"aria-valuemax": 100,
|
|
204
|
-
"aria-valuetext": `${percent}% complete`,
|
|
205
|
-
"data-complete": dataAttr(percent === 100)
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
var machine = createMachine({
|
|
211
|
-
props({ props: props2 }) {
|
|
212
|
-
return {
|
|
213
|
-
defaultStep: 0,
|
|
214
|
-
count: 1,
|
|
215
|
-
linear: false,
|
|
216
|
-
orientation: "horizontal",
|
|
217
|
-
...props2
|
|
218
|
-
};
|
|
219
|
-
},
|
|
220
|
-
context({ prop, bindable }) {
|
|
221
|
-
return {
|
|
222
|
-
step: bindable(() => ({
|
|
223
|
-
defaultValue: prop("defaultStep"),
|
|
224
|
-
value: prop("step"),
|
|
225
|
-
onChange(value) {
|
|
226
|
-
prop("onStepChange")?.({ step: value });
|
|
227
|
-
const completed = value == prop("count");
|
|
228
|
-
if (completed) prop("onStepComplete")?.();
|
|
229
|
-
}
|
|
230
|
-
}))
|
|
231
|
-
};
|
|
232
|
-
},
|
|
233
|
-
computed: {
|
|
234
|
-
percent: memo(
|
|
235
|
-
({ context, prop }) => [context.get("step"), prop("count")],
|
|
236
|
-
([step, count]) => step / count * 100
|
|
237
|
-
),
|
|
238
|
-
hasNextStep: ({ context, prop }) => context.get("step") < prop("count"),
|
|
239
|
-
hasPrevStep: ({ context }) => context.get("step") > 0,
|
|
240
|
-
completed: ({ context, prop }) => context.get("step") === prop("count")
|
|
241
|
-
},
|
|
242
|
-
initialState() {
|
|
243
|
-
return "idle";
|
|
244
|
-
},
|
|
245
|
-
entry: ["validateStepIndex"],
|
|
246
|
-
states: {
|
|
247
|
-
idle: {
|
|
248
|
-
on: {
|
|
249
|
-
"STEP.SET": [
|
|
250
|
-
{
|
|
251
|
-
guard: "isValidStepNavigation",
|
|
252
|
-
actions: ["setStep"]
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
actions: ["invokeOnStepInvalid"]
|
|
256
|
-
}
|
|
257
|
-
],
|
|
258
|
-
"STEP.NEXT": [
|
|
259
|
-
{
|
|
260
|
-
guard: "isCurrentStepValid",
|
|
261
|
-
actions: ["goToNextStep"]
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
actions: ["invokeOnStepInvalid"]
|
|
265
|
-
}
|
|
266
|
-
],
|
|
267
|
-
"STEP.PREV": {
|
|
268
|
-
actions: ["goToPrevStep"]
|
|
269
|
-
},
|
|
270
|
-
"STEP.RESET": {
|
|
271
|
-
actions: ["resetStep"]
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
implementations: {
|
|
277
|
-
guards: {
|
|
278
|
-
isCurrentStepValid({ context, prop }) {
|
|
279
|
-
const current = context.get("step");
|
|
280
|
-
if (prop("isStepSkippable")?.(current)) return true;
|
|
281
|
-
const isStepValid = prop("isStepValid");
|
|
282
|
-
if (!isStepValid) return true;
|
|
283
|
-
return isStepValid(current);
|
|
284
|
-
},
|
|
285
|
-
isValidStepNavigation({ context, event, prop }) {
|
|
286
|
-
const current = context.get("step");
|
|
287
|
-
if (event.value <= current) return true;
|
|
288
|
-
if (prop("isStepSkippable")?.(current)) return true;
|
|
289
|
-
const isStepValid = prop("isStepValid");
|
|
290
|
-
if (!isStepValid) return true;
|
|
291
|
-
return isStepValid(current);
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
actions: {
|
|
295
|
-
goToNextStep({ context, prop }) {
|
|
296
|
-
const count = prop("count");
|
|
297
|
-
context.set("step", Math.min(context.get("step") + 1, count));
|
|
298
|
-
},
|
|
299
|
-
goToPrevStep({ context }) {
|
|
300
|
-
context.set("step", Math.max(context.get("step") - 1, 0));
|
|
301
|
-
},
|
|
302
|
-
resetStep({ context }) {
|
|
303
|
-
context.set("step", 0);
|
|
304
|
-
},
|
|
305
|
-
setStep({ context, event }) {
|
|
306
|
-
context.set("step", event.value);
|
|
307
|
-
},
|
|
308
|
-
validateStepIndex({ context, prop }) {
|
|
309
|
-
validateStepIndex(prop("count"), context.get("step"));
|
|
310
|
-
},
|
|
311
|
-
invokeOnStepInvalid({ context, event, prop }) {
|
|
312
|
-
prop("onStepInvalid")?.({
|
|
313
|
-
step: context.get("step"),
|
|
314
|
-
action: event.type === "STEP.NEXT" ? "next" : "set",
|
|
315
|
-
targetStep: event.value
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
var validateStepIndex = (count, step) => {
|
|
322
|
-
if (!isValueWithinRange(step, 0, count)) {
|
|
323
|
-
throw new RangeError(`[zag-js/steps] step index ${step} is out of bounds`);
|
|
324
|
-
}
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { anatomy } from "./steps.anatomy.mjs";
|
|
3
|
+
import { connect } from "./steps.connect.mjs";
|
|
4
|
+
import { machine } from "./steps.machine.mjs";
|
|
5
|
+
export * from "./steps.props.mjs";
|
|
6
|
+
export {
|
|
7
|
+
anatomy,
|
|
8
|
+
connect,
|
|
9
|
+
machine
|
|
325
10
|
};
|
|
326
|
-
var props = createProps()([
|
|
327
|
-
"count",
|
|
328
|
-
"defaultStep",
|
|
329
|
-
"dir",
|
|
330
|
-
"getRootNode",
|
|
331
|
-
"id",
|
|
332
|
-
"ids",
|
|
333
|
-
"isStepSkippable",
|
|
334
|
-
"isStepValid",
|
|
335
|
-
"linear",
|
|
336
|
-
"onStepChange",
|
|
337
|
-
"onStepComplete",
|
|
338
|
-
"onStepInvalid",
|
|
339
|
-
"orientation",
|
|
340
|
-
"step"
|
|
341
|
-
]);
|
|
342
|
-
var splitProps = createSplitProps(props);
|
|
343
|
-
|
|
344
|
-
export { anatomy, connect, machine, props, splitProps };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "list" | "item" | "trigger" | "indicator" | "separator" | "content" | "nextTrigger" | "prevTrigger" | "progress">;
|
|
4
|
+
declare const parts: Record<"root" | "list" | "item" | "trigger" | "indicator" | "separator" | "content" | "nextTrigger" | "prevTrigger" | "progress", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "list" | "item" | "trigger" | "indicator" | "separator" | "content" | "nextTrigger" | "prevTrigger" | "progress">;
|
|
4
|
+
declare const parts: Record<"root" | "list" | "item" | "trigger" | "indicator" | "separator" | "content" | "nextTrigger" | "prevTrigger" | "progress", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/steps.anatomy.ts
|
|
21
|
+
var steps_anatomy_exports = {};
|
|
22
|
+
__export(steps_anatomy_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
parts: () => parts
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(steps_anatomy_exports);
|
|
27
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
28
|
+
var anatomy = (0, import_anatomy.createAnatomy)("steps").parts(
|
|
29
|
+
"root",
|
|
30
|
+
"list",
|
|
31
|
+
"item",
|
|
32
|
+
"trigger",
|
|
33
|
+
"indicator",
|
|
34
|
+
"separator",
|
|
35
|
+
"content",
|
|
36
|
+
"nextTrigger",
|
|
37
|
+
"prevTrigger",
|
|
38
|
+
"progress"
|
|
39
|
+
);
|
|
40
|
+
var parts = anatomy.build();
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
anatomy,
|
|
44
|
+
parts
|
|
45
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/steps.anatomy.ts
|
|
2
|
+
import { createAnatomy } from "@zag-js/anatomy";
|
|
3
|
+
var anatomy = createAnatomy("steps").parts(
|
|
4
|
+
"root",
|
|
5
|
+
"list",
|
|
6
|
+
"item",
|
|
7
|
+
"trigger",
|
|
8
|
+
"indicator",
|
|
9
|
+
"separator",
|
|
10
|
+
"content",
|
|
11
|
+
"nextTrigger",
|
|
12
|
+
"prevTrigger",
|
|
13
|
+
"progress"
|
|
14
|
+
);
|
|
15
|
+
var parts = anatomy.build();
|
|
16
|
+
export {
|
|
17
|
+
anatomy,
|
|
18
|
+
parts
|
|
19
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { StepsService, StepsApi } from './steps.types.mjs';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function connect<T extends PropTypes>(service: StepsService, normalize: NormalizeProps<T>): StepsApi<T>;
|
|
6
|
+
|
|
7
|
+
export { connect };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { StepsService, StepsApi } from './steps.types.js';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function connect<T extends PropTypes>(service: StepsService, normalize: NormalizeProps<T>): StepsApi<T>;
|
|
6
|
+
|
|
7
|
+
export { connect };
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/steps.connect.ts
|
|
31
|
+
var steps_connect_exports = {};
|
|
32
|
+
__export(steps_connect_exports, {
|
|
33
|
+
connect: () => connect
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(steps_connect_exports);
|
|
36
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var import_utils = require("@zag-js/utils");
|
|
38
|
+
var import_steps = require("./steps.anatomy.cjs");
|
|
39
|
+
var dom = __toESM(require("./steps.dom.cjs"));
|
|
40
|
+
function connect(service, normalize) {
|
|
41
|
+
const { context, send, computed, prop, scope } = service;
|
|
42
|
+
const step = context.get("step");
|
|
43
|
+
const count = prop("count");
|
|
44
|
+
const percent = computed("percent");
|
|
45
|
+
const hasNextStep = computed("hasNextStep");
|
|
46
|
+
const hasPrevStep = computed("hasPrevStep");
|
|
47
|
+
const isStepValid = (index) => {
|
|
48
|
+
return prop("isStepValid")?.(index) ?? true;
|
|
49
|
+
};
|
|
50
|
+
const isStepSkippable = (index) => {
|
|
51
|
+
return prop("isStepSkippable")?.(index) ?? false;
|
|
52
|
+
};
|
|
53
|
+
const getItemState = (props) => ({
|
|
54
|
+
triggerId: dom.getTriggerId(scope, props.index),
|
|
55
|
+
contentId: dom.getContentId(scope, props.index),
|
|
56
|
+
current: props.index === step,
|
|
57
|
+
completed: props.index < step,
|
|
58
|
+
incomplete: props.index > step,
|
|
59
|
+
index: props.index,
|
|
60
|
+
first: props.index === 0,
|
|
61
|
+
last: props.index === count - 1,
|
|
62
|
+
skippable: isStepSkippable(props.index),
|
|
63
|
+
isValid: () => isStepValid(props.index)
|
|
64
|
+
});
|
|
65
|
+
const goToNextStep = () => {
|
|
66
|
+
send({ type: "STEP.NEXT", src: "next.trigger.click" });
|
|
67
|
+
};
|
|
68
|
+
const goToPrevStep = () => {
|
|
69
|
+
send({ type: "STEP.PREV", src: "prev.trigger.click" });
|
|
70
|
+
};
|
|
71
|
+
const resetStep = () => {
|
|
72
|
+
send({ type: "STEP.RESET", src: "reset.trigger.click" });
|
|
73
|
+
};
|
|
74
|
+
const setStep = (value) => {
|
|
75
|
+
send({ type: "STEP.SET", value, src: "api.setValue" });
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
value: step,
|
|
79
|
+
count,
|
|
80
|
+
percent,
|
|
81
|
+
hasNextStep,
|
|
82
|
+
hasPrevStep,
|
|
83
|
+
isCompleted: computed("completed"),
|
|
84
|
+
isStepValid,
|
|
85
|
+
isStepSkippable,
|
|
86
|
+
goToNextStep,
|
|
87
|
+
goToPrevStep,
|
|
88
|
+
resetStep,
|
|
89
|
+
getItemState,
|
|
90
|
+
setStep,
|
|
91
|
+
getRootProps() {
|
|
92
|
+
return normalize.element({
|
|
93
|
+
...import_steps.parts.root.attrs,
|
|
94
|
+
id: dom.getRootId(scope),
|
|
95
|
+
dir: prop("dir"),
|
|
96
|
+
"data-orientation": prop("orientation"),
|
|
97
|
+
style: {
|
|
98
|
+
"--percent": `${percent}%`
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
getListProps() {
|
|
103
|
+
const arr = (0, import_utils.fromLength)(count);
|
|
104
|
+
const triggerIds = arr.map((_, index) => dom.getTriggerId(scope, index));
|
|
105
|
+
return normalize.element({
|
|
106
|
+
...import_steps.parts.list.attrs,
|
|
107
|
+
dir: prop("dir"),
|
|
108
|
+
id: dom.getListId(scope),
|
|
109
|
+
role: "tablist",
|
|
110
|
+
"aria-owns": triggerIds.join(" "),
|
|
111
|
+
"aria-orientation": prop("orientation"),
|
|
112
|
+
"data-orientation": prop("orientation")
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
getItemProps(props) {
|
|
116
|
+
const itemState = getItemState(props);
|
|
117
|
+
return normalize.element({
|
|
118
|
+
...import_steps.parts.item.attrs,
|
|
119
|
+
dir: prop("dir"),
|
|
120
|
+
"aria-current": itemState.current ? "step" : void 0,
|
|
121
|
+
"data-orientation": prop("orientation"),
|
|
122
|
+
"data-skippable": (0, import_dom_query.dataAttr)(itemState.skippable)
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
getTriggerProps(props) {
|
|
126
|
+
const itemState = getItemState(props);
|
|
127
|
+
return normalize.button({
|
|
128
|
+
...import_steps.parts.trigger.attrs,
|
|
129
|
+
id: itemState.triggerId,
|
|
130
|
+
role: "tab",
|
|
131
|
+
dir: prop("dir"),
|
|
132
|
+
tabIndex: !prop("linear") || itemState.current ? 0 : -1,
|
|
133
|
+
"aria-selected": itemState.current,
|
|
134
|
+
"aria-controls": itemState.contentId,
|
|
135
|
+
"data-state": itemState.current ? "open" : "closed",
|
|
136
|
+
"data-orientation": prop("orientation"),
|
|
137
|
+
"data-complete": (0, import_dom_query.dataAttr)(itemState.completed),
|
|
138
|
+
"data-current": (0, import_dom_query.dataAttr)(itemState.current),
|
|
139
|
+
"data-incomplete": (0, import_dom_query.dataAttr)(itemState.incomplete),
|
|
140
|
+
onClick(event) {
|
|
141
|
+
if (event.defaultPrevented) return;
|
|
142
|
+
if (prop("linear")) return;
|
|
143
|
+
send({ type: "STEP.SET", value: props.index, src: "trigger.click" });
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
getContentProps(props) {
|
|
148
|
+
const itemState = getItemState(props);
|
|
149
|
+
return normalize.element({
|
|
150
|
+
...import_steps.parts.content.attrs,
|
|
151
|
+
dir: prop("dir"),
|
|
152
|
+
id: itemState.contentId,
|
|
153
|
+
role: "tabpanel",
|
|
154
|
+
tabIndex: 0,
|
|
155
|
+
hidden: !itemState.current,
|
|
156
|
+
"data-state": itemState.current ? "open" : "closed",
|
|
157
|
+
"data-orientation": prop("orientation"),
|
|
158
|
+
"aria-labelledby": itemState.triggerId
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
getIndicatorProps(props) {
|
|
162
|
+
const itemState = getItemState(props);
|
|
163
|
+
return normalize.element({
|
|
164
|
+
...import_steps.parts.indicator.attrs,
|
|
165
|
+
dir: prop("dir"),
|
|
166
|
+
"aria-hidden": true,
|
|
167
|
+
"data-complete": (0, import_dom_query.dataAttr)(itemState.completed),
|
|
168
|
+
"data-current": (0, import_dom_query.dataAttr)(itemState.current),
|
|
169
|
+
"data-incomplete": (0, import_dom_query.dataAttr)(itemState.incomplete)
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
getSeparatorProps(props) {
|
|
173
|
+
const itemState = getItemState(props);
|
|
174
|
+
return normalize.element({
|
|
175
|
+
...import_steps.parts.separator.attrs,
|
|
176
|
+
dir: prop("dir"),
|
|
177
|
+
"data-orientation": prop("orientation"),
|
|
178
|
+
"data-complete": (0, import_dom_query.dataAttr)(itemState.completed),
|
|
179
|
+
"data-current": (0, import_dom_query.dataAttr)(itemState.current),
|
|
180
|
+
"data-incomplete": (0, import_dom_query.dataAttr)(itemState.incomplete)
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
getNextTriggerProps() {
|
|
184
|
+
return normalize.button({
|
|
185
|
+
...import_steps.parts.nextTrigger.attrs,
|
|
186
|
+
dir: prop("dir"),
|
|
187
|
+
type: "button",
|
|
188
|
+
disabled: !hasNextStep,
|
|
189
|
+
onClick(event) {
|
|
190
|
+
if (event.defaultPrevented) return;
|
|
191
|
+
goToNextStep();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
getPrevTriggerProps() {
|
|
196
|
+
return normalize.button({
|
|
197
|
+
dir: prop("dir"),
|
|
198
|
+
...import_steps.parts.prevTrigger.attrs,
|
|
199
|
+
type: "button",
|
|
200
|
+
disabled: !hasPrevStep,
|
|
201
|
+
onClick(event) {
|
|
202
|
+
if (event.defaultPrevented) return;
|
|
203
|
+
goToPrevStep();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
getProgressProps() {
|
|
208
|
+
return normalize.element({
|
|
209
|
+
dir: prop("dir"),
|
|
210
|
+
...import_steps.parts.progress.attrs,
|
|
211
|
+
role: "progressbar",
|
|
212
|
+
"aria-valuenow": percent,
|
|
213
|
+
"aria-valuemin": 0,
|
|
214
|
+
"aria-valuemax": 100,
|
|
215
|
+
"aria-valuetext": `${percent}% complete`,
|
|
216
|
+
"data-complete": (0, import_dom_query.dataAttr)(percent === 100)
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
+
0 && (module.exports = {
|
|
223
|
+
connect
|
|
224
|
+
});
|