@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.
- package/dist/components/Stepper/Stepper.js +19 -27
- package/dist/constants.d.ts +0 -4
- package/dist/constants.js +0 -4
- package/dist/types.d.ts +3 -4
- package/package.json +2 -2
- package/src/components/Stepper/Stepper.tsx +19 -28
- package/src/constants.ts +0 -5
- package/src/types.ts +3 -5
|
@@ -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
|
|
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(
|
|
47
|
-
(_c = stepsValidator === null || stepsValidator === void 0 ? void 0 : stepsValidator(currentStepIndex)) !== null && _c !== void 0 ? _c : Promise.resolve(
|
|
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(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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) {
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
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
|
|
3
|
+
import { STEP_STATE } from './constants';
|
|
4
4
|
export type StepState = ValueOf<typeof STEP_STATE>;
|
|
5
|
-
export type
|
|
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<
|
|
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-
|
|
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": "
|
|
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
|
|
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(
|
|
79
|
-
stepsValidator?.(currentStepIndex) ?? Promise.resolve(
|
|
78
|
+
currentStep.validation?.() ?? Promise.resolve(true),
|
|
79
|
+
stepsValidator?.(currentStepIndex) ?? Promise.resolve(true),
|
|
80
80
|
])
|
|
81
|
-
.then(results =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
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
|
|
5
|
+
import { STEP_STATE } from './constants';
|
|
6
6
|
|
|
7
7
|
export type StepState = ValueOf<typeof STEP_STATE>;
|
|
8
8
|
|
|
9
|
-
export type
|
|
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<
|
|
14
|
+
validation?(): Promise<boolean>;
|
|
17
15
|
};
|
|
18
16
|
|
|
19
17
|
export type StepViewData = StepData & {
|