@snack-uikit/stepper 0.5.9 → 0.5.10-preview-8e2ed733.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/README.md +1 -1
- package/dist/StepperContext/StepperContext.js +1 -1
- package/dist/components/Stepper/Stepper.d.ts +1 -1
- package/dist/components/Stepper/Stepper.js +9 -5
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
- package/src/StepperContext/StepperContext.ts +1 -1
- package/src/components/Stepper/Stepper.tsx +13 -6
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ return (
|
|
|
48
48
|
### Props
|
|
49
49
|
| name | type | default value | description |
|
|
50
50
|
|------|------|---------------|-------------|
|
|
51
|
-
| children* | `({stepper, ...api}) => ReactElement` | - | Render function. Принимает аргументы: `stepper` - JSX-элемент степпера, `goNext` - перейти на след. шаг, `goPrev` - перейти на пред. шаг, `
|
|
51
|
+
| children* | `({stepper, ...api}) => ReactElement` | - | Render function. Принимает аргументы: `stepper` - JSX-элемент степпера, `goNext` - перейти на след. шаг, `goPrev` - перейти на пред. шаг, `setValidation` - установить состояние валидации для текущего шага, `isCompleted` - окончен ли процесс, `currentStepIndex` - индекс текущего шага, `stepCount` - кол-во шагов. |
|
|
52
52
|
| steps* | `StepData[]` | - | Массив шагов |
|
|
53
53
|
| defaultCurrentStepIndex | `number` | - | Индекс текущего шага по-дефолту |
|
|
54
54
|
| className | `string` | - | CSS-класс |
|
|
@@ -13,7 +13,7 @@ export type StepperProps = WithSupportProps<{
|
|
|
13
13
|
className?: string;
|
|
14
14
|
/**
|
|
15
15
|
* Render function. Принимает аргументы: `stepper` - JSX-элемент степпера,
|
|
16
|
-
* `goNext` - перейти на след. шаг, `goPrev` - перейти на пред. шаг, `
|
|
16
|
+
* `goNext` - перейти на след. шаг, `goPrev` - перейти на пред. шаг, `setValidation` - установить состояние валидации для текущего шага, `isCompleted` - окончен ли процесс, `currentStepIndex` - индекс текущего шага, `stepCount` - кол-во шагов.
|
|
17
17
|
* @type ({stepper, ...api}) => ReactElement
|
|
18
18
|
*/
|
|
19
19
|
children: (params: StepperState) => ReactElement;
|
|
@@ -91,12 +91,16 @@ export function Stepper(_a) {
|
|
|
91
91
|
}
|
|
92
92
|
return Object.assign(Object.assign({}, step), { number, state: STEP_STATE.Waiting });
|
|
93
93
|
}), [steps, currentStepIndex, goPrev, currentStepState, isCompleted, goNext]);
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
const setValidation = useCallback((isValid) => {
|
|
95
|
+
const setValidationValue = (isValid) => setCurrentStepState(isValid ? STEP_STATE.Current : STEP_STATE.Rejected);
|
|
96
|
+
if (isValid instanceof Promise) {
|
|
97
|
+
setCurrentStepState(STEP_STATE.Loading);
|
|
98
|
+
isValid.then(setValidationValue).catch(() => setValidationValue(false));
|
|
99
|
+
return;
|
|
97
100
|
}
|
|
98
|
-
|
|
101
|
+
setValidationValue(isValid);
|
|
102
|
+
}, []);
|
|
99
103
|
const stepper = (_jsx("div", Object.assign({ className: cn(styles.stepper, className) }, extractSupportProps(props), { children: stepsView.map((step, index) => (_jsx(Step, { step: step, "data-test-id": props['data-test-id'], hideTailLine: index === steps.length - 1 }, step.title + index))) })));
|
|
100
|
-
const stepperApi = { goNext, goPrev, currentStepIndex, isCompleted,
|
|
104
|
+
const stepperApi = { goNext, goPrev, currentStepIndex, isCompleted, setValidation, stepCount: steps.length };
|
|
101
105
|
return _jsx(StepperContext.Provider, { value: stepperApi, children: children(Object.assign({ stepper }, stepperApi)) });
|
|
102
106
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type StepViewData = StepData & {
|
|
|
15
15
|
export type StepperApi = {
|
|
16
16
|
goNext(): void;
|
|
17
17
|
goPrev(): void;
|
|
18
|
-
|
|
18
|
+
setValidation(isValid: boolean | Promise<boolean>): void;
|
|
19
19
|
isCompleted: boolean;
|
|
20
20
|
currentStepIndex: number;
|
|
21
21
|
stepCount: number;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Stepper",
|
|
7
|
-
"version": "0.5.
|
|
7
|
+
"version": "0.5.10-preview-8e2ed733.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": "98c8bfc998da448c39972953e87601d5174e1e23"
|
|
43
43
|
}
|
|
@@ -22,7 +22,7 @@ export type StepperProps = WithSupportProps<{
|
|
|
22
22
|
className?: string;
|
|
23
23
|
/**
|
|
24
24
|
* Render function. Принимает аргументы: `stepper` - JSX-элемент степпера,
|
|
25
|
-
* `goNext` - перейти на след. шаг, `goPrev` - перейти на пред. шаг, `
|
|
25
|
+
* `goNext` - перейти на след. шаг, `goPrev` - перейти на пред. шаг, `setValidation` - установить состояние валидации для текущего шага, `isCompleted` - окончен ли процесс, `currentStepIndex` - индекс текущего шага, `stepCount` - кол-во шагов.
|
|
26
26
|
* @type ({stepper, ...api}) => ReactElement
|
|
27
27
|
*/
|
|
28
28
|
children: (params: StepperState) => ReactElement;
|
|
@@ -140,11 +140,18 @@ export function Stepper({
|
|
|
140
140
|
[steps, currentStepIndex, goPrev, currentStepState, isCompleted, goNext],
|
|
141
141
|
);
|
|
142
142
|
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
setCurrentStepState(STEP_STATE.Current);
|
|
143
|
+
const setValidation = useCallback((isValid: boolean | Promise<boolean>) => {
|
|
144
|
+
const setValidationValue = (isValid: boolean) =>
|
|
145
|
+
setCurrentStepState(isValid ? STEP_STATE.Current : STEP_STATE.Rejected);
|
|
146
|
+
|
|
147
|
+
if (isValid instanceof Promise) {
|
|
148
|
+
setCurrentStepState(STEP_STATE.Loading);
|
|
149
|
+
isValid.then(setValidationValue).catch(() => setValidationValue(false));
|
|
150
|
+
return;
|
|
146
151
|
}
|
|
147
|
-
|
|
152
|
+
|
|
153
|
+
setValidationValue(isValid);
|
|
154
|
+
}, []);
|
|
148
155
|
|
|
149
156
|
const stepper = (
|
|
150
157
|
<div className={cn(styles.stepper, className)} {...extractSupportProps(props)}>
|
|
@@ -159,7 +166,7 @@ export function Stepper({
|
|
|
159
166
|
</div>
|
|
160
167
|
);
|
|
161
168
|
|
|
162
|
-
const stepperApi = { goNext, goPrev, currentStepIndex, isCompleted,
|
|
169
|
+
const stepperApi = { goNext, goPrev, currentStepIndex, isCompleted, setValidation, stepCount: steps.length };
|
|
163
170
|
|
|
164
171
|
return <StepperContext.Provider value={stepperApi}>{children({ stepper, ...stepperApi })}</StepperContext.Provider>;
|
|
165
172
|
}
|
package/src/types.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type StepViewData = StepData & {
|
|
|
21
21
|
export type StepperApi = {
|
|
22
22
|
goNext(): void;
|
|
23
23
|
goPrev(): void;
|
|
24
|
-
|
|
24
|
+
setValidation(isValid: boolean | Promise<boolean>): void;
|
|
25
25
|
isCompleted: boolean;
|
|
26
26
|
currentStepIndex: number;
|
|
27
27
|
stepCount: number;
|