@snack-uikit/stepper 0.5.10-preview-e59b2871.0 → 0.5.10-preview-440a038d.0

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.
@@ -13,7 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import { useCallback, useEffect, useMemo, useState } from 'react';
15
15
  import { extractSupportProps } from '@snack-uikit/utils';
16
- import { STEP_STATE, STEP_VALIDATION_RESULT } from '../../constants';
16
+ import { STEP_STATE } from '../../constants';
17
17
  import { Step } from '../../helperComponents';
18
18
  import { StepperContext } from '../../StepperContext';
19
19
  import styles from './styles.module.css';
@@ -43,34 +43,26 @@ export function Stepper(_a) {
43
43
  const currentStep = steps[currentStepIndex];
44
44
  setCurrentStepState(STEP_STATE.Loading);
45
45
  Promise.all([
46
- (_b = (_a = currentStep.validation) === null || _a === void 0 ? void 0 : _a.call(currentStep)) !== null && _b !== void 0 ? _b : Promise.resolve(STEP_STATE.Completed),
47
- (_c = stepsValidator === null || stepsValidator === void 0 ? void 0 : stepsValidator(currentStepIndex)) !== null && _c !== void 0 ? _c : Promise.resolve(STEP_STATE.Completed),
46
+ (_b = (_a = currentStep.validation) === null || _a === void 0 ? void 0 : _a.call(currentStep)) !== null && _b !== void 0 ? _b : Promise.resolve(true),
47
+ (_c = stepsValidator === null || stepsValidator === void 0 ? void 0 : stepsValidator(currentStepIndex)) !== null && _c !== void 0 ? _c : Promise.resolve(true),
48
48
  ])
49
- .then(results => results.every(result => result === STEP_VALIDATION_RESULT.Completed)
50
- ? STEP_VALIDATION_RESULT.Completed
51
- : STEP_VALIDATION_RESULT.Rejected)
52
- .catch(() => STEP_VALIDATION_RESULT.Rejected)
53
- .then(validationResult => {
54
- switch (validationResult) {
55
- case STEP_VALIDATION_RESULT.Completed:
56
- if (currentStepIndex === steps.length - 1) {
57
- // завершился последний шаг
58
- setCurrentStepState(STEP_STATE.Completed);
59
- setIsCompleted(true);
60
- }
61
- else {
62
- setCurrentStepIndex(currentStepIndex + 1);
63
- setCurrentStepState(STEP_STATE.Current);
64
- }
65
- return;
66
- case STEP_VALIDATION_RESULT.Rejected:
67
- setCurrentStepState(STEP_STATE.Rejected);
68
- return;
69
- default:
70
- setCurrentStepState(STEP_STATE.Current);
49
+ .then(results => results.every(isValid => isValid))
50
+ .catch(() => false)
51
+ .then(isValid => {
52
+ if (!isValid) {
53
+ setCurrentStepState(STEP_STATE.Rejected);
54
+ return;
71
55
  }
72
- })
73
- .catch(() => setCurrentStepState(STEP_STATE.Rejected));
56
+ if (currentStepIndex === steps.length - 1) {
57
+ // завершился последний шаг
58
+ setCurrentStepState(STEP_STATE.Completed);
59
+ setIsCompleted(true);
60
+ }
61
+ else {
62
+ setCurrentStepIndex(currentStepIndex + 1);
63
+ setCurrentStepState(STEP_STATE.Current);
64
+ }
65
+ });
74
66
  }, [currentStepIndex, isCompleted, setCurrentStepIndex, steps, stepsValidator]);
75
67
  const goPrev = useCallback((index = currentStepIndex - 1) => {
76
68
  if (currentStepIndex === 0 || index < 0 || index > currentStepIndex) {
@@ -5,7 +5,3 @@ export declare const STEP_STATE: {
5
5
  readonly Waiting: "waiting";
6
6
  readonly Rejected: "rejected";
7
7
  };
8
- export declare const STEP_VALIDATION_RESULT: {
9
- readonly Completed: "completed";
10
- readonly Rejected: "rejected";
11
- };
package/dist/constants.js CHANGED
@@ -5,7 +5,3 @@ export const STEP_STATE = {
5
5
  Waiting: 'waiting',
6
6
  Rejected: 'rejected',
7
7
  };
8
- export const STEP_VALIDATION_RESULT = {
9
- Completed: 'completed',
10
- Rejected: 'rejected',
11
- };
package/dist/types.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import { JSX } from 'react';
2
2
  import { ValueOf } from '@snack-uikit/utils';
3
- import { STEP_STATE, STEP_VALIDATION_RESULT } from './constants';
3
+ import { STEP_STATE } from './constants';
4
4
  export type StepState = ValueOf<typeof STEP_STATE>;
5
- export type StepValidationResult = ValueOf<typeof STEP_VALIDATION_RESULT>;
6
- export type StepsValidator = (stepIndex: number) => Promise<StepValidationResult>;
5
+ export type StepsValidator = (stepIndex: number) => Promise<boolean>;
7
6
  export type StepData = {
8
7
  title: string;
9
8
  description?: string;
10
- validation?(): Promise<StepValidationResult>;
9
+ validation?(): Promise<boolean>;
11
10
  };
12
11
  export type StepViewData = StepData & {
13
12
  onClick?(): void;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Stepper",
7
- "version": "0.5.10-preview-e59b2871.0",
7
+ "version": "0.5.10-preview-440a038d.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -39,5 +39,5 @@
39
39
  "@snack-uikit/utils": "3.2.0",
40
40
  "classnames": "2.3.2"
41
41
  },
42
- "gitHead": "1f6f70cea8ded89a952f288fefe362231ea3404b"
42
+ "gitHead": "f59fd51aedff7f4a7e89e5b76d269a47eb44e215"
43
43
  }
@@ -3,7 +3,7 @@ import { ReactElement, useCallback, useEffect, useMemo, useState } from 'react';
3
3
 
4
4
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
5
5
 
6
- import { STEP_STATE, STEP_VALIDATION_RESULT } from '../../constants';
6
+ import { STEP_STATE } from '../../constants';
7
7
  import { Step } from '../../helperComponents';
8
8
  import { StepperContext } from '../../StepperContext';
9
9
  import { StepData, StepperApi, StepState, StepsValidator, StepViewData } from '../../types';
@@ -75,35 +75,26 @@ export function Stepper({
75
75
  setCurrentStepState(STEP_STATE.Loading);
76
76
 
77
77
  Promise.all([
78
- currentStep.validation?.() ?? Promise.resolve(STEP_STATE.Completed),
79
- stepsValidator?.(currentStepIndex) ?? Promise.resolve(STEP_STATE.Completed),
78
+ currentStep.validation?.() ?? Promise.resolve(true),
79
+ stepsValidator?.(currentStepIndex) ?? Promise.resolve(true),
80
80
  ])
81
- .then(results =>
82
- results.every(result => result === STEP_VALIDATION_RESULT.Completed)
83
- ? STEP_VALIDATION_RESULT.Completed
84
- : STEP_VALIDATION_RESULT.Rejected,
85
- )
86
- .catch(() => STEP_VALIDATION_RESULT.Rejected)
87
- .then(validationResult => {
88
- switch (validationResult) {
89
- case STEP_VALIDATION_RESULT.Completed:
90
- if (currentStepIndex === steps.length - 1) {
91
- // завершился последний шаг
92
- setCurrentStepState(STEP_STATE.Completed);
93
- setIsCompleted(true);
94
- } else {
95
- setCurrentStepIndex(currentStepIndex + 1);
96
- setCurrentStepState(STEP_STATE.Current);
97
- }
98
- return;
99
- case STEP_VALIDATION_RESULT.Rejected:
100
- setCurrentStepState(STEP_STATE.Rejected);
101
- return;
102
- default:
103
- setCurrentStepState(STEP_STATE.Current);
81
+ .then(results => results.every(isValid => isValid))
82
+ .catch(() => false)
83
+ .then(isValid => {
84
+ if (!isValid) {
85
+ setCurrentStepState(STEP_STATE.Rejected);
86
+ return;
104
87
  }
105
- })
106
- .catch(() => setCurrentStepState(STEP_STATE.Rejected));
88
+
89
+ if (currentStepIndex === steps.length - 1) {
90
+ // завершился последний шаг
91
+ setCurrentStepState(STEP_STATE.Completed);
92
+ setIsCompleted(true);
93
+ } else {
94
+ setCurrentStepIndex(currentStepIndex + 1);
95
+ setCurrentStepState(STEP_STATE.Current);
96
+ }
97
+ });
107
98
  }, [currentStepIndex, isCompleted, setCurrentStepIndex, steps, stepsValidator]);
108
99
 
109
100
  const goPrev = useCallback(
package/src/constants.ts CHANGED
@@ -5,8 +5,3 @@ export const STEP_STATE = {
5
5
  Waiting: 'waiting',
6
6
  Rejected: 'rejected',
7
7
  } as const;
8
-
9
- export const STEP_VALIDATION_RESULT = {
10
- Completed: 'completed',
11
- Rejected: 'rejected',
12
- } as const;
package/src/types.ts CHANGED
@@ -2,18 +2,16 @@ import { JSX } from 'react';
2
2
 
3
3
  import { ValueOf } from '@snack-uikit/utils';
4
4
 
5
- import { STEP_STATE, STEP_VALIDATION_RESULT } from './constants';
5
+ import { STEP_STATE } from './constants';
6
6
 
7
7
  export type StepState = ValueOf<typeof STEP_STATE>;
8
8
 
9
- export type StepValidationResult = ValueOf<typeof STEP_VALIDATION_RESULT>;
10
-
11
- export type StepsValidator = (stepIndex: number) => Promise<StepValidationResult>;
9
+ export type StepsValidator = (stepIndex: number) => Promise<boolean>;
12
10
 
13
11
  export type StepData = {
14
12
  title: string;
15
13
  description?: string;
16
- validation?(): Promise<StepValidationResult>;
14
+ validation?(): Promise<boolean>;
17
15
  };
18
16
 
19
17
  export type StepViewData = StepData & {