@zag-js/steps 0.81.0 → 0.81.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 CHANGED
@@ -50,6 +50,7 @@ type ComputedContext = Readonly<{
50
50
  percent: number;
51
51
  hasNextStep: boolean;
52
52
  hasPrevStep: boolean;
53
+ completed: boolean;
53
54
  }>;
54
55
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
55
56
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
@@ -94,6 +95,10 @@ interface MachineApi<T extends PropTypes = PropTypes> {
94
95
  * Whether the stepper has a previous step.
95
96
  */
96
97
  hasPrevStep: boolean;
98
+ /**
99
+ * Whether the stepper is completed.
100
+ */
101
+ isCompleted: boolean;
97
102
  /**
98
103
  * Function to set the value of the stepper.
99
104
  */
package/dist/index.d.ts CHANGED
@@ -50,6 +50,7 @@ type ComputedContext = Readonly<{
50
50
  percent: number;
51
51
  hasNextStep: boolean;
52
52
  hasPrevStep: boolean;
53
+ completed: boolean;
53
54
  }>;
54
55
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
55
56
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
@@ -94,6 +95,10 @@ interface MachineApi<T extends PropTypes = PropTypes> {
94
95
  * Whether the stepper has a previous step.
95
96
  */
96
97
  hasPrevStep: boolean;
98
+ /**
99
+ * Whether the stepper is completed.
100
+ */
101
+ isCompleted: boolean;
97
102
  /**
98
103
  * Function to set the value of the stepper.
99
104
  */
package/dist/index.js CHANGED
@@ -62,6 +62,7 @@ function connect(state, send, normalize) {
62
62
  percent,
63
63
  hasNextStep,
64
64
  hasPrevStep,
65
+ isCompleted: state.context.completed,
65
66
  goToNextStep,
66
67
  goToPrevStep,
67
68
  resetStep,
@@ -212,7 +213,8 @@ function machine(userContext) {
212
213
  computed: {
213
214
  percent: (ctx2) => ctx2.step / ctx2.count * 100,
214
215
  hasNextStep: (ctx2) => ctx2.step < ctx2.count,
215
- hasPrevStep: (ctx2) => ctx2.step > 0
216
+ hasPrevStep: (ctx2) => ctx2.step > 0,
217
+ completed: (ctx2) => ctx2.step === ctx2.count
216
218
  },
217
219
  states: {
218
220
  idle: {
@@ -246,21 +248,27 @@ function machine(userContext) {
246
248
  resetStep(ctx2) {
247
249
  set.value(ctx2, 0);
248
250
  },
249
- setStep(ctx2, event) {
250
- const value = event.value;
251
- const inRange = value >= 0 && value < ctx2.count;
252
- if (!inRange) throw new RangeError(`Index ${value} is out of bounds`);
253
- set.value(ctx2, value);
251
+ setStep(ctx2, evt) {
252
+ set.value(ctx2, evt.value);
254
253
  }
255
254
  }
256
255
  }
257
256
  );
258
257
  }
258
+ var validateStep = (ctx, step) => {
259
+ if (!utils.isValueWithinRange(step, 0, ctx.count)) {
260
+ throw new RangeError(`[zag-js/steps] step index ${step} is out of bounds`);
261
+ }
262
+ };
259
263
  var set = {
260
264
  value(ctx, step) {
261
265
  if (utils.isEqual(ctx.step, step)) return;
266
+ validateStep(ctx, step);
262
267
  ctx.step = step;
263
268
  ctx.onStepChange?.({ step });
269
+ if (ctx.completed) {
270
+ ctx.onStepComplete?.();
271
+ }
264
272
  }
265
273
  };
266
274
  var props = types.createProps()([
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createAnatomy } from '@zag-js/anatomy';
2
2
  import { createScope, dataAttr } from '@zag-js/dom-query';
3
- import { createSplitProps, fromLength, compact, isEqual } from '@zag-js/utils';
3
+ import { createSplitProps, fromLength, compact, isEqual, isValueWithinRange } from '@zag-js/utils';
4
4
  import { createMachine } from '@zag-js/core';
5
5
  import { createProps } from '@zag-js/types';
6
6
 
@@ -60,6 +60,7 @@ function connect(state, send, normalize) {
60
60
  percent,
61
61
  hasNextStep,
62
62
  hasPrevStep,
63
+ isCompleted: state.context.completed,
63
64
  goToNextStep,
64
65
  goToPrevStep,
65
66
  resetStep,
@@ -210,7 +211,8 @@ function machine(userContext) {
210
211
  computed: {
211
212
  percent: (ctx2) => ctx2.step / ctx2.count * 100,
212
213
  hasNextStep: (ctx2) => ctx2.step < ctx2.count,
213
- hasPrevStep: (ctx2) => ctx2.step > 0
214
+ hasPrevStep: (ctx2) => ctx2.step > 0,
215
+ completed: (ctx2) => ctx2.step === ctx2.count
214
216
  },
215
217
  states: {
216
218
  idle: {
@@ -244,21 +246,27 @@ function machine(userContext) {
244
246
  resetStep(ctx2) {
245
247
  set.value(ctx2, 0);
246
248
  },
247
- setStep(ctx2, event) {
248
- const value = event.value;
249
- const inRange = value >= 0 && value < ctx2.count;
250
- if (!inRange) throw new RangeError(`Index ${value} is out of bounds`);
251
- set.value(ctx2, value);
249
+ setStep(ctx2, evt) {
250
+ set.value(ctx2, evt.value);
252
251
  }
253
252
  }
254
253
  }
255
254
  );
256
255
  }
256
+ var validateStep = (ctx, step) => {
257
+ if (!isValueWithinRange(step, 0, ctx.count)) {
258
+ throw new RangeError(`[zag-js/steps] step index ${step} is out of bounds`);
259
+ }
260
+ };
257
261
  var set = {
258
262
  value(ctx, step) {
259
263
  if (isEqual(ctx.step, step)) return;
264
+ validateStep(ctx, step);
260
265
  ctx.step = step;
261
266
  ctx.onStepChange?.({ step });
267
+ if (ctx.completed) {
268
+ ctx.onStepComplete?.();
269
+ }
262
270
  }
263
271
  };
264
272
  var props = createProps()([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/steps",
3
- "version": "0.81.0",
3
+ "version": "0.81.1",
4
4
  "description": "Core logic for the steps widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,11 +27,11 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/anatomy": "0.81.0",
31
- "@zag-js/core": "0.81.0",
32
- "@zag-js/dom-query": "0.81.0",
33
- "@zag-js/utils": "0.81.0",
34
- "@zag-js/types": "0.81.0"
30
+ "@zag-js/anatomy": "0.81.1",
31
+ "@zag-js/core": "0.81.1",
32
+ "@zag-js/dom-query": "0.81.1",
33
+ "@zag-js/utils": "0.81.1",
34
+ "@zag-js/types": "0.81.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "clean-package": "2.2.0"