@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.
@@ -0,0 +1,201 @@
1
+ import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { PropTypes, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types';
3
+
4
+ interface StepChangeDetails {
5
+ step: number;
6
+ }
7
+ interface StepInvalidDetails {
8
+ step: number;
9
+ action: "next" | "set";
10
+ targetStep?: number;
11
+ }
12
+ interface ElementIds {
13
+ root?: string | undefined;
14
+ list?: string | undefined;
15
+ triggerId?: ((index: number) => string) | undefined;
16
+ contentId?: ((index: number) => string) | undefined;
17
+ }
18
+ interface StepsProps extends DirectionProperty, CommonProperties {
19
+ /**
20
+ * The custom ids for the stepper elements
21
+ */
22
+ ids?: ElementIds | undefined;
23
+ /**
24
+ * The controlled value of the stepper
25
+ */
26
+ step?: number | undefined;
27
+ /**
28
+ * The initial value of the stepper when rendered.
29
+ * Use when you don't need to control the value of the stepper.
30
+ */
31
+ defaultStep?: number | undefined;
32
+ /**
33
+ * Callback to be called when the value changes
34
+ */
35
+ onStepChange?: ((details: StepChangeDetails) => void) | undefined;
36
+ /**
37
+ * Callback to be called when a step is completed
38
+ */
39
+ onStepComplete?: VoidFunction | undefined;
40
+ /**
41
+ * If `true`, the stepper requires the user to complete the steps in order
42
+ */
43
+ linear?: boolean | undefined;
44
+ /**
45
+ * The orientation of the stepper
46
+ * @default "horizontal"
47
+ */
48
+ orientation?: "horizontal" | "vertical" | undefined;
49
+ /**
50
+ * The total number of steps
51
+ */
52
+ count?: number | undefined;
53
+ /**
54
+ * Whether a step is valid. Invalid steps block forward navigation in linear mode.
55
+ * @default () => true
56
+ */
57
+ isStepValid?: ((index: number) => boolean) | undefined;
58
+ /**
59
+ * Whether a step can be skipped during navigation.
60
+ * Skippable steps are bypassed when using next/prev.
61
+ * @default () => false
62
+ */
63
+ isStepSkippable?: ((index: number) => boolean) | undefined;
64
+ /**
65
+ * Called when navigation is blocked due to an invalid step.
66
+ */
67
+ onStepInvalid?: ((details: StepInvalidDetails) => void) | undefined;
68
+ }
69
+ type PropsWithDefault = "orientation" | "linear" | "count";
70
+ interface PrivateContext {
71
+ step: number;
72
+ }
73
+ type ComputedContext = Readonly<{
74
+ percent: number;
75
+ hasNextStep: boolean;
76
+ hasPrevStep: boolean;
77
+ completed: boolean;
78
+ }>;
79
+ interface StepsSchema {
80
+ props: RequiredBy<StepsProps, PropsWithDefault>;
81
+ context: PrivateContext;
82
+ computed: ComputedContext;
83
+ state: "idle";
84
+ event: EventObject;
85
+ action: string;
86
+ effect: string;
87
+ guard: string;
88
+ }
89
+ type StepsService = Service<StepsSchema>;
90
+ type StepsMachine = Machine<StepsSchema>;
91
+ interface ItemProps {
92
+ index: number;
93
+ }
94
+ interface ItemState {
95
+ /**
96
+ * The index of the step
97
+ */
98
+ index: number;
99
+ /**
100
+ * The id of the trigger element
101
+ */
102
+ triggerId: string;
103
+ /**
104
+ * The id of the content element
105
+ */
106
+ contentId: string;
107
+ /**
108
+ * Whether the step is the current step
109
+ */
110
+ current: boolean;
111
+ /**
112
+ * Whether the step is completed (index < current step)
113
+ */
114
+ completed: boolean;
115
+ /**
116
+ * Whether the step is incomplete (index > current step)
117
+ */
118
+ incomplete: boolean;
119
+ /**
120
+ * Whether the step is the last step
121
+ */
122
+ last: boolean;
123
+ /**
124
+ * Whether the step is the first step
125
+ */
126
+ first: boolean;
127
+ /**
128
+ * Whether the step can be skipped (based on `isStepSkippable` callback)
129
+ */
130
+ skippable: boolean;
131
+ /**
132
+ * Lazy validation check - only evaluated when called
133
+ */
134
+ isValid: () => boolean;
135
+ }
136
+ interface StepsApi<T extends PropTypes = PropTypes> {
137
+ /**
138
+ * The value of the stepper.
139
+ */
140
+ value: number;
141
+ /**
142
+ * The percentage of the stepper.
143
+ */
144
+ percent: number;
145
+ /**
146
+ * The total number of steps.
147
+ */
148
+ count: number;
149
+ /**
150
+ * Whether the stepper has a next step.
151
+ */
152
+ hasNextStep: boolean;
153
+ /**
154
+ * Whether the stepper has a previous step.
155
+ */
156
+ hasPrevStep: boolean;
157
+ /**
158
+ * Whether the stepper is completed.
159
+ */
160
+ isCompleted: boolean;
161
+ /**
162
+ * Check if a specific step is valid (lazy evaluation)
163
+ */
164
+ isStepValid: (index: number) => boolean;
165
+ /**
166
+ * Check if a specific step can be skipped
167
+ */
168
+ isStepSkippable: (index: number) => boolean;
169
+ /**
170
+ * Function to set the value of the stepper.
171
+ */
172
+ setStep: (step: number) => void;
173
+ /**
174
+ * Function to go to the next step.
175
+ */
176
+ goToNextStep: VoidFunction;
177
+ /**
178
+ * Function to go to the previous step.
179
+ */
180
+ goToPrevStep: VoidFunction;
181
+ /**
182
+ * Function to go to reset the stepper.
183
+ */
184
+ resetStep: VoidFunction;
185
+ /**
186
+ * Returns the state of the item at the given index.
187
+ */
188
+ getItemState: (props: ItemProps) => ItemState;
189
+ getRootProps: () => T["element"];
190
+ getListProps: () => T["element"];
191
+ getItemProps: (props: ItemProps) => T["element"];
192
+ getTriggerProps: (props: ItemProps) => T["element"];
193
+ getContentProps: (props: ItemProps) => T["element"];
194
+ getNextTriggerProps: () => T["button"];
195
+ getPrevTriggerProps: () => T["button"];
196
+ getProgressProps: () => T["element"];
197
+ getIndicatorProps: (props: ItemProps) => T["element"];
198
+ getSeparatorProps: (props: ItemProps) => T["element"];
199
+ }
200
+
201
+ export type { ElementIds, ItemProps, ItemState, StepChangeDetails, StepInvalidDetails, StepsApi, StepsMachine, StepsProps, StepsSchema, StepsService };
@@ -0,0 +1,201 @@
1
+ import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { PropTypes, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types';
3
+
4
+ interface StepChangeDetails {
5
+ step: number;
6
+ }
7
+ interface StepInvalidDetails {
8
+ step: number;
9
+ action: "next" | "set";
10
+ targetStep?: number;
11
+ }
12
+ interface ElementIds {
13
+ root?: string | undefined;
14
+ list?: string | undefined;
15
+ triggerId?: ((index: number) => string) | undefined;
16
+ contentId?: ((index: number) => string) | undefined;
17
+ }
18
+ interface StepsProps extends DirectionProperty, CommonProperties {
19
+ /**
20
+ * The custom ids for the stepper elements
21
+ */
22
+ ids?: ElementIds | undefined;
23
+ /**
24
+ * The controlled value of the stepper
25
+ */
26
+ step?: number | undefined;
27
+ /**
28
+ * The initial value of the stepper when rendered.
29
+ * Use when you don't need to control the value of the stepper.
30
+ */
31
+ defaultStep?: number | undefined;
32
+ /**
33
+ * Callback to be called when the value changes
34
+ */
35
+ onStepChange?: ((details: StepChangeDetails) => void) | undefined;
36
+ /**
37
+ * Callback to be called when a step is completed
38
+ */
39
+ onStepComplete?: VoidFunction | undefined;
40
+ /**
41
+ * If `true`, the stepper requires the user to complete the steps in order
42
+ */
43
+ linear?: boolean | undefined;
44
+ /**
45
+ * The orientation of the stepper
46
+ * @default "horizontal"
47
+ */
48
+ orientation?: "horizontal" | "vertical" | undefined;
49
+ /**
50
+ * The total number of steps
51
+ */
52
+ count?: number | undefined;
53
+ /**
54
+ * Whether a step is valid. Invalid steps block forward navigation in linear mode.
55
+ * @default () => true
56
+ */
57
+ isStepValid?: ((index: number) => boolean) | undefined;
58
+ /**
59
+ * Whether a step can be skipped during navigation.
60
+ * Skippable steps are bypassed when using next/prev.
61
+ * @default () => false
62
+ */
63
+ isStepSkippable?: ((index: number) => boolean) | undefined;
64
+ /**
65
+ * Called when navigation is blocked due to an invalid step.
66
+ */
67
+ onStepInvalid?: ((details: StepInvalidDetails) => void) | undefined;
68
+ }
69
+ type PropsWithDefault = "orientation" | "linear" | "count";
70
+ interface PrivateContext {
71
+ step: number;
72
+ }
73
+ type ComputedContext = Readonly<{
74
+ percent: number;
75
+ hasNextStep: boolean;
76
+ hasPrevStep: boolean;
77
+ completed: boolean;
78
+ }>;
79
+ interface StepsSchema {
80
+ props: RequiredBy<StepsProps, PropsWithDefault>;
81
+ context: PrivateContext;
82
+ computed: ComputedContext;
83
+ state: "idle";
84
+ event: EventObject;
85
+ action: string;
86
+ effect: string;
87
+ guard: string;
88
+ }
89
+ type StepsService = Service<StepsSchema>;
90
+ type StepsMachine = Machine<StepsSchema>;
91
+ interface ItemProps {
92
+ index: number;
93
+ }
94
+ interface ItemState {
95
+ /**
96
+ * The index of the step
97
+ */
98
+ index: number;
99
+ /**
100
+ * The id of the trigger element
101
+ */
102
+ triggerId: string;
103
+ /**
104
+ * The id of the content element
105
+ */
106
+ contentId: string;
107
+ /**
108
+ * Whether the step is the current step
109
+ */
110
+ current: boolean;
111
+ /**
112
+ * Whether the step is completed (index < current step)
113
+ */
114
+ completed: boolean;
115
+ /**
116
+ * Whether the step is incomplete (index > current step)
117
+ */
118
+ incomplete: boolean;
119
+ /**
120
+ * Whether the step is the last step
121
+ */
122
+ last: boolean;
123
+ /**
124
+ * Whether the step is the first step
125
+ */
126
+ first: boolean;
127
+ /**
128
+ * Whether the step can be skipped (based on `isStepSkippable` callback)
129
+ */
130
+ skippable: boolean;
131
+ /**
132
+ * Lazy validation check - only evaluated when called
133
+ */
134
+ isValid: () => boolean;
135
+ }
136
+ interface StepsApi<T extends PropTypes = PropTypes> {
137
+ /**
138
+ * The value of the stepper.
139
+ */
140
+ value: number;
141
+ /**
142
+ * The percentage of the stepper.
143
+ */
144
+ percent: number;
145
+ /**
146
+ * The total number of steps.
147
+ */
148
+ count: number;
149
+ /**
150
+ * Whether the stepper has a next step.
151
+ */
152
+ hasNextStep: boolean;
153
+ /**
154
+ * Whether the stepper has a previous step.
155
+ */
156
+ hasPrevStep: boolean;
157
+ /**
158
+ * Whether the stepper is completed.
159
+ */
160
+ isCompleted: boolean;
161
+ /**
162
+ * Check if a specific step is valid (lazy evaluation)
163
+ */
164
+ isStepValid: (index: number) => boolean;
165
+ /**
166
+ * Check if a specific step can be skipped
167
+ */
168
+ isStepSkippable: (index: number) => boolean;
169
+ /**
170
+ * Function to set the value of the stepper.
171
+ */
172
+ setStep: (step: number) => void;
173
+ /**
174
+ * Function to go to the next step.
175
+ */
176
+ goToNextStep: VoidFunction;
177
+ /**
178
+ * Function to go to the previous step.
179
+ */
180
+ goToPrevStep: VoidFunction;
181
+ /**
182
+ * Function to go to reset the stepper.
183
+ */
184
+ resetStep: VoidFunction;
185
+ /**
186
+ * Returns the state of the item at the given index.
187
+ */
188
+ getItemState: (props: ItemProps) => ItemState;
189
+ getRootProps: () => T["element"];
190
+ getListProps: () => T["element"];
191
+ getItemProps: (props: ItemProps) => T["element"];
192
+ getTriggerProps: (props: ItemProps) => T["element"];
193
+ getContentProps: (props: ItemProps) => T["element"];
194
+ getNextTriggerProps: () => T["button"];
195
+ getPrevTriggerProps: () => T["button"];
196
+ getProgressProps: () => T["element"];
197
+ getIndicatorProps: (props: ItemProps) => T["element"];
198
+ getSeparatorProps: (props: ItemProps) => T["element"];
199
+ }
200
+
201
+ export type { ElementIds, ItemProps, ItemState, StepChangeDetails, StepInvalidDetails, StepsApi, StepsMachine, StepsProps, StepsSchema, StepsService };
@@ -0,0 +1,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/steps.types.ts
17
+ var steps_types_exports = {};
18
+ module.exports = __toCommonJS(steps_types_exports);
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/steps",
3
- "version": "1.34.1",
3
+ "version": "1.35.1",
4
4
  "description": "Core logic for the steps widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,16 +27,16 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/anatomy": "1.34.1",
31
- "@zag-js/core": "1.34.1",
32
- "@zag-js/dom-query": "1.34.1",
33
- "@zag-js/utils": "1.34.1",
34
- "@zag-js/types": "1.34.1"
30
+ "@zag-js/anatomy": "1.35.1",
31
+ "@zag-js/core": "1.35.1",
32
+ "@zag-js/dom-query": "1.35.1",
33
+ "@zag-js/utils": "1.35.1",
34
+ "@zag-js/types": "1.35.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "clean-package": "2.2.0"
38
38
  },
39
- "clean-package": "../../../clean-package.config.json",
39
+ "clean-package": "./clean-package.config.json",
40
40
  "module": "dist/index.mjs",
41
41
  "types": "dist/index.d.ts",
42
42
  "exports": {
@@ -50,6 +50,16 @@
50
50
  "default": "./dist/index.js"
51
51
  }
52
52
  },
53
+ "./anatomy": {
54
+ "import": {
55
+ "types": "./dist/steps.anatomy.d.mts",
56
+ "default": "./dist/steps.anatomy.mjs"
57
+ },
58
+ "require": {
59
+ "types": "./dist/steps.anatomy.d.ts",
60
+ "default": "./dist/steps.anatomy.js"
61
+ }
62
+ },
53
63
  "./package.json": "./package.json"
54
64
  },
55
65
  "scripts": {