@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 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` - перейти на пред. шаг, `resetValidation` - сбросить состояние валидации для текущего шага, `isCompleted` - окончен ли процесс, `currentStepIndex` - индекс текущего шага, `stepCount` - кол-во шагов. |
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-класс |
@@ -9,7 +9,7 @@ export const StepperContext = createContext({
9
9
  goPrev() {
10
10
  /* stub */
11
11
  },
12
- resetValidation() {
12
+ setValidation() {
13
13
  /* stub */
14
14
  },
15
15
  });
@@ -13,7 +13,7 @@ export type StepperProps = WithSupportProps<{
13
13
  className?: string;
14
14
  /**
15
15
  * Render function. Принимает аргументы: `stepper` - JSX-элемент степпера,
16
- * `goNext` - перейти на след. шаг, `goPrev` - перейти на пред. шаг, `resetValidation` - сбросить состояние валидации для текущего шага, `isCompleted` - окончен ли процесс, `currentStepIndex` - индекс текущего шага, `stepCount` - кол-во шагов.
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 resetValidation = useCallback(() => {
95
- if (currentStepState === STEP_STATE.Rejected) {
96
- setCurrentStepState(STEP_STATE.Current);
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
- }, [currentStepState]);
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, resetValidation, stepCount: steps.length };
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
- resetValidation(): void;
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.9",
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": "234be77560f8bd1b3a4b567e2ec88f3a89c3631f"
42
+ "gitHead": "98c8bfc998da448c39972953e87601d5174e1e23"
43
43
  }
@@ -14,7 +14,7 @@ export const StepperContext = createContext<StepperApi>({
14
14
  goPrev() {
15
15
  /* stub */
16
16
  },
17
- resetValidation() {
17
+ setValidation() {
18
18
  /* stub */
19
19
  },
20
20
  });
@@ -22,7 +22,7 @@ export type StepperProps = WithSupportProps<{
22
22
  className?: string;
23
23
  /**
24
24
  * Render function. Принимает аргументы: `stepper` - JSX-элемент степпера,
25
- * `goNext` - перейти на след. шаг, `goPrev` - перейти на пред. шаг, `resetValidation` - сбросить состояние валидации для текущего шага, `isCompleted` - окончен ли процесс, `currentStepIndex` - индекс текущего шага, `stepCount` - кол-во шагов.
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 resetValidation = useCallback(() => {
144
- if (currentStepState === STEP_STATE.Rejected) {
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
- }, [currentStepState]);
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, resetValidation, stepCount: steps.length };
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
- resetValidation(): void;
24
+ setValidation(isValid: boolean | Promise<boolean>): void;
25
25
  isCompleted: boolean;
26
26
  currentStepIndex: number;
27
27
  stepCount: number;