@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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// src/steps.connect.ts
|
|
2
|
+
import { dataAttr } from "@zag-js/dom-query";
|
|
3
|
+
import { fromLength } from "@zag-js/utils";
|
|
4
|
+
import { parts } from "./steps.anatomy.mjs";
|
|
5
|
+
import * as dom from "./steps.dom.mjs";
|
|
6
|
+
function connect(service, normalize) {
|
|
7
|
+
const { context, send, computed, prop, scope } = service;
|
|
8
|
+
const step = context.get("step");
|
|
9
|
+
const count = prop("count");
|
|
10
|
+
const percent = computed("percent");
|
|
11
|
+
const hasNextStep = computed("hasNextStep");
|
|
12
|
+
const hasPrevStep = computed("hasPrevStep");
|
|
13
|
+
const isStepValid = (index) => {
|
|
14
|
+
return prop("isStepValid")?.(index) ?? true;
|
|
15
|
+
};
|
|
16
|
+
const isStepSkippable = (index) => {
|
|
17
|
+
return prop("isStepSkippable")?.(index) ?? false;
|
|
18
|
+
};
|
|
19
|
+
const getItemState = (props) => ({
|
|
20
|
+
triggerId: dom.getTriggerId(scope, props.index),
|
|
21
|
+
contentId: dom.getContentId(scope, props.index),
|
|
22
|
+
current: props.index === step,
|
|
23
|
+
completed: props.index < step,
|
|
24
|
+
incomplete: props.index > step,
|
|
25
|
+
index: props.index,
|
|
26
|
+
first: props.index === 0,
|
|
27
|
+
last: props.index === count - 1,
|
|
28
|
+
skippable: isStepSkippable(props.index),
|
|
29
|
+
isValid: () => isStepValid(props.index)
|
|
30
|
+
});
|
|
31
|
+
const goToNextStep = () => {
|
|
32
|
+
send({ type: "STEP.NEXT", src: "next.trigger.click" });
|
|
33
|
+
};
|
|
34
|
+
const goToPrevStep = () => {
|
|
35
|
+
send({ type: "STEP.PREV", src: "prev.trigger.click" });
|
|
36
|
+
};
|
|
37
|
+
const resetStep = () => {
|
|
38
|
+
send({ type: "STEP.RESET", src: "reset.trigger.click" });
|
|
39
|
+
};
|
|
40
|
+
const setStep = (value) => {
|
|
41
|
+
send({ type: "STEP.SET", value, src: "api.setValue" });
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
value: step,
|
|
45
|
+
count,
|
|
46
|
+
percent,
|
|
47
|
+
hasNextStep,
|
|
48
|
+
hasPrevStep,
|
|
49
|
+
isCompleted: computed("completed"),
|
|
50
|
+
isStepValid,
|
|
51
|
+
isStepSkippable,
|
|
52
|
+
goToNextStep,
|
|
53
|
+
goToPrevStep,
|
|
54
|
+
resetStep,
|
|
55
|
+
getItemState,
|
|
56
|
+
setStep,
|
|
57
|
+
getRootProps() {
|
|
58
|
+
return normalize.element({
|
|
59
|
+
...parts.root.attrs,
|
|
60
|
+
id: dom.getRootId(scope),
|
|
61
|
+
dir: prop("dir"),
|
|
62
|
+
"data-orientation": prop("orientation"),
|
|
63
|
+
style: {
|
|
64
|
+
"--percent": `${percent}%`
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
getListProps() {
|
|
69
|
+
const arr = fromLength(count);
|
|
70
|
+
const triggerIds = arr.map((_, index) => dom.getTriggerId(scope, index));
|
|
71
|
+
return normalize.element({
|
|
72
|
+
...parts.list.attrs,
|
|
73
|
+
dir: prop("dir"),
|
|
74
|
+
id: dom.getListId(scope),
|
|
75
|
+
role: "tablist",
|
|
76
|
+
"aria-owns": triggerIds.join(" "),
|
|
77
|
+
"aria-orientation": prop("orientation"),
|
|
78
|
+
"data-orientation": prop("orientation")
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
getItemProps(props) {
|
|
82
|
+
const itemState = getItemState(props);
|
|
83
|
+
return normalize.element({
|
|
84
|
+
...parts.item.attrs,
|
|
85
|
+
dir: prop("dir"),
|
|
86
|
+
"aria-current": itemState.current ? "step" : void 0,
|
|
87
|
+
"data-orientation": prop("orientation"),
|
|
88
|
+
"data-skippable": dataAttr(itemState.skippable)
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
getTriggerProps(props) {
|
|
92
|
+
const itemState = getItemState(props);
|
|
93
|
+
return normalize.button({
|
|
94
|
+
...parts.trigger.attrs,
|
|
95
|
+
id: itemState.triggerId,
|
|
96
|
+
role: "tab",
|
|
97
|
+
dir: prop("dir"),
|
|
98
|
+
tabIndex: !prop("linear") || itemState.current ? 0 : -1,
|
|
99
|
+
"aria-selected": itemState.current,
|
|
100
|
+
"aria-controls": itemState.contentId,
|
|
101
|
+
"data-state": itemState.current ? "open" : "closed",
|
|
102
|
+
"data-orientation": prop("orientation"),
|
|
103
|
+
"data-complete": dataAttr(itemState.completed),
|
|
104
|
+
"data-current": dataAttr(itemState.current),
|
|
105
|
+
"data-incomplete": dataAttr(itemState.incomplete),
|
|
106
|
+
onClick(event) {
|
|
107
|
+
if (event.defaultPrevented) return;
|
|
108
|
+
if (prop("linear")) return;
|
|
109
|
+
send({ type: "STEP.SET", value: props.index, src: "trigger.click" });
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
getContentProps(props) {
|
|
114
|
+
const itemState = getItemState(props);
|
|
115
|
+
return normalize.element({
|
|
116
|
+
...parts.content.attrs,
|
|
117
|
+
dir: prop("dir"),
|
|
118
|
+
id: itemState.contentId,
|
|
119
|
+
role: "tabpanel",
|
|
120
|
+
tabIndex: 0,
|
|
121
|
+
hidden: !itemState.current,
|
|
122
|
+
"data-state": itemState.current ? "open" : "closed",
|
|
123
|
+
"data-orientation": prop("orientation"),
|
|
124
|
+
"aria-labelledby": itemState.triggerId
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
getIndicatorProps(props) {
|
|
128
|
+
const itemState = getItemState(props);
|
|
129
|
+
return normalize.element({
|
|
130
|
+
...parts.indicator.attrs,
|
|
131
|
+
dir: prop("dir"),
|
|
132
|
+
"aria-hidden": true,
|
|
133
|
+
"data-complete": dataAttr(itemState.completed),
|
|
134
|
+
"data-current": dataAttr(itemState.current),
|
|
135
|
+
"data-incomplete": dataAttr(itemState.incomplete)
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
getSeparatorProps(props) {
|
|
139
|
+
const itemState = getItemState(props);
|
|
140
|
+
return normalize.element({
|
|
141
|
+
...parts.separator.attrs,
|
|
142
|
+
dir: prop("dir"),
|
|
143
|
+
"data-orientation": prop("orientation"),
|
|
144
|
+
"data-complete": dataAttr(itemState.completed),
|
|
145
|
+
"data-current": dataAttr(itemState.current),
|
|
146
|
+
"data-incomplete": dataAttr(itemState.incomplete)
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
getNextTriggerProps() {
|
|
150
|
+
return normalize.button({
|
|
151
|
+
...parts.nextTrigger.attrs,
|
|
152
|
+
dir: prop("dir"),
|
|
153
|
+
type: "button",
|
|
154
|
+
disabled: !hasNextStep,
|
|
155
|
+
onClick(event) {
|
|
156
|
+
if (event.defaultPrevented) return;
|
|
157
|
+
goToNextStep();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
getPrevTriggerProps() {
|
|
162
|
+
return normalize.button({
|
|
163
|
+
dir: prop("dir"),
|
|
164
|
+
...parts.prevTrigger.attrs,
|
|
165
|
+
type: "button",
|
|
166
|
+
disabled: !hasPrevStep,
|
|
167
|
+
onClick(event) {
|
|
168
|
+
if (event.defaultPrevented) return;
|
|
169
|
+
goToPrevStep();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
getProgressProps() {
|
|
174
|
+
return normalize.element({
|
|
175
|
+
dir: prop("dir"),
|
|
176
|
+
...parts.progress.attrs,
|
|
177
|
+
role: "progressbar",
|
|
178
|
+
"aria-valuenow": percent,
|
|
179
|
+
"aria-valuemin": 0,
|
|
180
|
+
"aria-valuemax": 100,
|
|
181
|
+
"aria-valuetext": `${percent}% complete`,
|
|
182
|
+
"data-complete": dataAttr(percent === 100)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export {
|
|
188
|
+
connect
|
|
189
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
|
|
3
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
4
|
+
declare const getListId: (ctx: Scope) => any;
|
|
5
|
+
declare const getTriggerId: (ctx: Scope, index: number) => any;
|
|
6
|
+
declare const getContentId: (ctx: Scope, index: number) => any;
|
|
7
|
+
|
|
8
|
+
export { getContentId, getListId, getRootId, getTriggerId };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
|
|
3
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
4
|
+
declare const getListId: (ctx: Scope) => any;
|
|
5
|
+
declare const getTriggerId: (ctx: Scope, index: number) => any;
|
|
6
|
+
declare const getContentId: (ctx: Scope, index: number) => any;
|
|
7
|
+
|
|
8
|
+
export { getContentId, getListId, getRootId, getTriggerId };
|
|
@@ -0,0 +1,39 @@
|
|
|
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.dom.ts
|
|
21
|
+
var steps_dom_exports = {};
|
|
22
|
+
__export(steps_dom_exports, {
|
|
23
|
+
getContentId: () => getContentId,
|
|
24
|
+
getListId: () => getListId,
|
|
25
|
+
getRootId: () => getRootId,
|
|
26
|
+
getTriggerId: () => getTriggerId
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(steps_dom_exports);
|
|
29
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `steps:${ctx.id}`;
|
|
30
|
+
var getListId = (ctx) => ctx.ids?.list ?? `steps:${ctx.id}:list`;
|
|
31
|
+
var getTriggerId = (ctx, index) => ctx.ids?.triggerId?.(index) ?? `steps:${ctx.id}:trigger:${index}`;
|
|
32
|
+
var getContentId = (ctx, index) => ctx.ids?.contentId?.(index) ?? `steps:${ctx.id}:content:${index}`;
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
getContentId,
|
|
36
|
+
getListId,
|
|
37
|
+
getRootId,
|
|
38
|
+
getTriggerId
|
|
39
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/steps.dom.ts
|
|
2
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `steps:${ctx.id}`;
|
|
3
|
+
var getListId = (ctx) => ctx.ids?.list ?? `steps:${ctx.id}:list`;
|
|
4
|
+
var getTriggerId = (ctx, index) => ctx.ids?.triggerId?.(index) ?? `steps:${ctx.id}:trigger:${index}`;
|
|
5
|
+
var getContentId = (ctx, index) => ctx.ids?.contentId?.(index) ?? `steps:${ctx.id}:content:${index}`;
|
|
6
|
+
export {
|
|
7
|
+
getContentId,
|
|
8
|
+
getListId,
|
|
9
|
+
getRootId,
|
|
10
|
+
getTriggerId
|
|
11
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
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.machine.ts
|
|
21
|
+
var steps_machine_exports = {};
|
|
22
|
+
__export(steps_machine_exports, {
|
|
23
|
+
machine: () => machine
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(steps_machine_exports);
|
|
26
|
+
var import_core = require("@zag-js/core");
|
|
27
|
+
var import_utils = require("@zag-js/utils");
|
|
28
|
+
var machine = (0, import_core.createMachine)({
|
|
29
|
+
props({ props }) {
|
|
30
|
+
return {
|
|
31
|
+
defaultStep: 0,
|
|
32
|
+
count: 1,
|
|
33
|
+
linear: false,
|
|
34
|
+
orientation: "horizontal",
|
|
35
|
+
...props
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
context({ prop, bindable }) {
|
|
39
|
+
return {
|
|
40
|
+
step: bindable(() => ({
|
|
41
|
+
defaultValue: prop("defaultStep"),
|
|
42
|
+
value: prop("step"),
|
|
43
|
+
onChange(value) {
|
|
44
|
+
prop("onStepChange")?.({ step: value });
|
|
45
|
+
const completed = value == prop("count");
|
|
46
|
+
if (completed) prop("onStepComplete")?.();
|
|
47
|
+
}
|
|
48
|
+
}))
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
computed: {
|
|
52
|
+
percent: (0, import_core.memo)(
|
|
53
|
+
({ context, prop }) => [context.get("step"), prop("count")],
|
|
54
|
+
([step, count]) => step / count * 100
|
|
55
|
+
),
|
|
56
|
+
hasNextStep: ({ context, prop }) => context.get("step") < prop("count"),
|
|
57
|
+
hasPrevStep: ({ context }) => context.get("step") > 0,
|
|
58
|
+
completed: ({ context, prop }) => context.get("step") === prop("count")
|
|
59
|
+
},
|
|
60
|
+
initialState() {
|
|
61
|
+
return "idle";
|
|
62
|
+
},
|
|
63
|
+
entry: ["validateStepIndex"],
|
|
64
|
+
states: {
|
|
65
|
+
idle: {
|
|
66
|
+
on: {
|
|
67
|
+
"STEP.SET": [
|
|
68
|
+
{
|
|
69
|
+
guard: "isValidStepNavigation",
|
|
70
|
+
actions: ["setStep"]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
actions: ["invokeOnStepInvalid"]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"STEP.NEXT": [
|
|
77
|
+
{
|
|
78
|
+
guard: "isCurrentStepValid",
|
|
79
|
+
actions: ["goToNextStep"]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
actions: ["invokeOnStepInvalid"]
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"STEP.PREV": {
|
|
86
|
+
actions: ["goToPrevStep"]
|
|
87
|
+
},
|
|
88
|
+
"STEP.RESET": {
|
|
89
|
+
actions: ["resetStep"]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
implementations: {
|
|
95
|
+
guards: {
|
|
96
|
+
isCurrentStepValid({ context, prop }) {
|
|
97
|
+
const current = context.get("step");
|
|
98
|
+
if (prop("isStepSkippable")?.(current)) return true;
|
|
99
|
+
const isStepValid = prop("isStepValid");
|
|
100
|
+
if (!isStepValid) return true;
|
|
101
|
+
return isStepValid(current);
|
|
102
|
+
},
|
|
103
|
+
isValidStepNavigation({ context, event, prop }) {
|
|
104
|
+
const current = context.get("step");
|
|
105
|
+
if (event.value <= current) return true;
|
|
106
|
+
if (prop("isStepSkippable")?.(current)) return true;
|
|
107
|
+
const isStepValid = prop("isStepValid");
|
|
108
|
+
if (!isStepValid) return true;
|
|
109
|
+
return isStepValid(current);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
actions: {
|
|
113
|
+
goToNextStep({ context, prop }) {
|
|
114
|
+
const count = prop("count");
|
|
115
|
+
context.set("step", Math.min(context.get("step") + 1, count));
|
|
116
|
+
},
|
|
117
|
+
goToPrevStep({ context }) {
|
|
118
|
+
context.set("step", Math.max(context.get("step") - 1, 0));
|
|
119
|
+
},
|
|
120
|
+
resetStep({ context }) {
|
|
121
|
+
context.set("step", 0);
|
|
122
|
+
},
|
|
123
|
+
setStep({ context, event }) {
|
|
124
|
+
context.set("step", event.value);
|
|
125
|
+
},
|
|
126
|
+
validateStepIndex({ context, prop }) {
|
|
127
|
+
validateStepIndex(prop("count"), context.get("step"));
|
|
128
|
+
},
|
|
129
|
+
invokeOnStepInvalid({ context, event, prop }) {
|
|
130
|
+
prop("onStepInvalid")?.({
|
|
131
|
+
step: context.get("step"),
|
|
132
|
+
action: event.type === "STEP.NEXT" ? "next" : "set",
|
|
133
|
+
targetStep: event.value
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
var validateStepIndex = (count, step) => {
|
|
140
|
+
if (!(0, import_utils.isValueWithinRange)(step, 0, count)) {
|
|
141
|
+
throw new RangeError(`[zag-js/steps] step index ${step} is out of bounds`);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
machine
|
|
147
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// src/steps.machine.ts
|
|
2
|
+
import { createMachine, memo } from "@zag-js/core";
|
|
3
|
+
import { isValueWithinRange } from "@zag-js/utils";
|
|
4
|
+
var machine = createMachine({
|
|
5
|
+
props({ props }) {
|
|
6
|
+
return {
|
|
7
|
+
defaultStep: 0,
|
|
8
|
+
count: 1,
|
|
9
|
+
linear: false,
|
|
10
|
+
orientation: "horizontal",
|
|
11
|
+
...props
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
context({ prop, bindable }) {
|
|
15
|
+
return {
|
|
16
|
+
step: bindable(() => ({
|
|
17
|
+
defaultValue: prop("defaultStep"),
|
|
18
|
+
value: prop("step"),
|
|
19
|
+
onChange(value) {
|
|
20
|
+
prop("onStepChange")?.({ step: value });
|
|
21
|
+
const completed = value == prop("count");
|
|
22
|
+
if (completed) prop("onStepComplete")?.();
|
|
23
|
+
}
|
|
24
|
+
}))
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
computed: {
|
|
28
|
+
percent: memo(
|
|
29
|
+
({ context, prop }) => [context.get("step"), prop("count")],
|
|
30
|
+
([step, count]) => step / count * 100
|
|
31
|
+
),
|
|
32
|
+
hasNextStep: ({ context, prop }) => context.get("step") < prop("count"),
|
|
33
|
+
hasPrevStep: ({ context }) => context.get("step") > 0,
|
|
34
|
+
completed: ({ context, prop }) => context.get("step") === prop("count")
|
|
35
|
+
},
|
|
36
|
+
initialState() {
|
|
37
|
+
return "idle";
|
|
38
|
+
},
|
|
39
|
+
entry: ["validateStepIndex"],
|
|
40
|
+
states: {
|
|
41
|
+
idle: {
|
|
42
|
+
on: {
|
|
43
|
+
"STEP.SET": [
|
|
44
|
+
{
|
|
45
|
+
guard: "isValidStepNavigation",
|
|
46
|
+
actions: ["setStep"]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
actions: ["invokeOnStepInvalid"]
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"STEP.NEXT": [
|
|
53
|
+
{
|
|
54
|
+
guard: "isCurrentStepValid",
|
|
55
|
+
actions: ["goToNextStep"]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
actions: ["invokeOnStepInvalid"]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"STEP.PREV": {
|
|
62
|
+
actions: ["goToPrevStep"]
|
|
63
|
+
},
|
|
64
|
+
"STEP.RESET": {
|
|
65
|
+
actions: ["resetStep"]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
implementations: {
|
|
71
|
+
guards: {
|
|
72
|
+
isCurrentStepValid({ context, prop }) {
|
|
73
|
+
const current = context.get("step");
|
|
74
|
+
if (prop("isStepSkippable")?.(current)) return true;
|
|
75
|
+
const isStepValid = prop("isStepValid");
|
|
76
|
+
if (!isStepValid) return true;
|
|
77
|
+
return isStepValid(current);
|
|
78
|
+
},
|
|
79
|
+
isValidStepNavigation({ context, event, prop }) {
|
|
80
|
+
const current = context.get("step");
|
|
81
|
+
if (event.value <= current) return true;
|
|
82
|
+
if (prop("isStepSkippable")?.(current)) return true;
|
|
83
|
+
const isStepValid = prop("isStepValid");
|
|
84
|
+
if (!isStepValid) return true;
|
|
85
|
+
return isStepValid(current);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
actions: {
|
|
89
|
+
goToNextStep({ context, prop }) {
|
|
90
|
+
const count = prop("count");
|
|
91
|
+
context.set("step", Math.min(context.get("step") + 1, count));
|
|
92
|
+
},
|
|
93
|
+
goToPrevStep({ context }) {
|
|
94
|
+
context.set("step", Math.max(context.get("step") - 1, 0));
|
|
95
|
+
},
|
|
96
|
+
resetStep({ context }) {
|
|
97
|
+
context.set("step", 0);
|
|
98
|
+
},
|
|
99
|
+
setStep({ context, event }) {
|
|
100
|
+
context.set("step", event.value);
|
|
101
|
+
},
|
|
102
|
+
validateStepIndex({ context, prop }) {
|
|
103
|
+
validateStepIndex(prop("count"), context.get("step"));
|
|
104
|
+
},
|
|
105
|
+
invokeOnStepInvalid({ context, event, prop }) {
|
|
106
|
+
prop("onStepInvalid")?.({
|
|
107
|
+
step: context.get("step"),
|
|
108
|
+
action: event.type === "STEP.NEXT" ? "next" : "set",
|
|
109
|
+
targetStep: event.value
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
var validateStepIndex = (count, step) => {
|
|
116
|
+
if (!isValueWithinRange(step, 0, count)) {
|
|
117
|
+
throw new RangeError(`[zag-js/steps] step index ${step} is out of bounds`);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
export {
|
|
121
|
+
machine
|
|
122
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StepsProps } from './steps.types.mjs';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const props: (keyof StepsProps)[];
|
|
6
|
+
declare const splitProps: <Props extends Partial<StepsProps>>(props: Props) => [Partial<StepsProps>, Omit<Props, keyof StepsProps>];
|
|
7
|
+
|
|
8
|
+
export { props, splitProps };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StepsProps } from './steps.types.js';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const props: (keyof StepsProps)[];
|
|
6
|
+
declare const splitProps: <Props extends Partial<StepsProps>>(props: Props) => [Partial<StepsProps>, Omit<Props, keyof StepsProps>];
|
|
7
|
+
|
|
8
|
+
export { props, splitProps };
|
|
@@ -0,0 +1,50 @@
|
|
|
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.props.ts
|
|
21
|
+
var steps_props_exports = {};
|
|
22
|
+
__export(steps_props_exports, {
|
|
23
|
+
props: () => props,
|
|
24
|
+
splitProps: () => splitProps
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(steps_props_exports);
|
|
27
|
+
var import_types = require("@zag-js/types");
|
|
28
|
+
var import_utils = require("@zag-js/utils");
|
|
29
|
+
var props = (0, import_types.createProps)()([
|
|
30
|
+
"count",
|
|
31
|
+
"defaultStep",
|
|
32
|
+
"dir",
|
|
33
|
+
"getRootNode",
|
|
34
|
+
"id",
|
|
35
|
+
"ids",
|
|
36
|
+
"isStepSkippable",
|
|
37
|
+
"isStepValid",
|
|
38
|
+
"linear",
|
|
39
|
+
"onStepChange",
|
|
40
|
+
"onStepComplete",
|
|
41
|
+
"onStepInvalid",
|
|
42
|
+
"orientation",
|
|
43
|
+
"step"
|
|
44
|
+
]);
|
|
45
|
+
var splitProps = (0, import_utils.createSplitProps)(props);
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
props,
|
|
49
|
+
splitProps
|
|
50
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/steps.props.ts
|
|
2
|
+
import { createProps } from "@zag-js/types";
|
|
3
|
+
import { createSplitProps } from "@zag-js/utils";
|
|
4
|
+
var props = createProps()([
|
|
5
|
+
"count",
|
|
6
|
+
"defaultStep",
|
|
7
|
+
"dir",
|
|
8
|
+
"getRootNode",
|
|
9
|
+
"id",
|
|
10
|
+
"ids",
|
|
11
|
+
"isStepSkippable",
|
|
12
|
+
"isStepValid",
|
|
13
|
+
"linear",
|
|
14
|
+
"onStepChange",
|
|
15
|
+
"onStepComplete",
|
|
16
|
+
"onStepInvalid",
|
|
17
|
+
"orientation",
|
|
18
|
+
"step"
|
|
19
|
+
]);
|
|
20
|
+
var splitProps = createSplitProps(props);
|
|
21
|
+
export {
|
|
22
|
+
props,
|
|
23
|
+
splitProps
|
|
24
|
+
};
|