aport-tools 4.4.4 → 4.4.5
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/forms/FormContext.d.ts +1 -0
- package/dist/index.esm.js +46 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +46 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
1
|
+
/*! aport-tools v4.4.5 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
@@ -196,7 +196,7 @@ var Stepper = function Stepper(_a) {
|
|
196
196
|
currentStep = _a.currentStep,
|
197
197
|
_b = _a.presseable,
|
198
198
|
presseable = _b === void 0 ? false : _b,
|
199
|
-
|
199
|
+
onPress = _a.onPress,
|
200
200
|
_c = _a.stepStyle,
|
201
201
|
stepStyle = _c === void 0 ? "circular" : _c,
|
202
202
|
totalSteps = _a.totalSteps,
|
@@ -206,6 +206,30 @@ var Stepper = function Stepper(_a) {
|
|
206
206
|
var progressAnim = React.useRef(new reactNative.Animated.Value(0)).current;
|
207
207
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
208
208
|
var colors = theme.colors;
|
209
|
+
var _e = useFormContext(),
|
210
|
+
formValues = _e.formValues,
|
211
|
+
handleFormSubmit = _e.handleFormSubmit;
|
212
|
+
var handleStepPress = function handleStepPress(stepIndex) {
|
213
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
214
|
+
var errors;
|
215
|
+
return __generator(this, function (_a) {
|
216
|
+
switch (_a.label) {
|
217
|
+
case 0:
|
218
|
+
if (!presseable || stepIndex === currentStep) return [2 /*return*/];
|
219
|
+
return [4 /*yield*/, handleFormSubmit(formValues)];
|
220
|
+
case 1:
|
221
|
+
errors = _a.sent();
|
222
|
+
if (Object.keys(errors).length > 0) {
|
223
|
+
console.log("Validation failed. Cannot proceed to step", stepIndex);
|
224
|
+
return [2 /*return*/]; // Prevent step change
|
225
|
+
}
|
226
|
+
// Proceed to change step
|
227
|
+
onPress === null || onPress === void 0 ? void 0 : onPress(stepIndex);
|
228
|
+
return [2 /*return*/];
|
229
|
+
}
|
230
|
+
});
|
231
|
+
});
|
232
|
+
};
|
209
233
|
React.useEffect(function () {
|
210
234
|
reactNative.Animated.timing(progressAnim, {
|
211
235
|
toValue: currentStep,
|
@@ -292,7 +316,7 @@ var Stepper = function Stepper(_a) {
|
|
292
316
|
}],
|
293
317
|
disabled: !presseable,
|
294
318
|
onPress: function onPress() {
|
295
|
-
return
|
319
|
+
return handleStepPress(index);
|
296
320
|
}
|
297
321
|
}, /*#__PURE__*/React.createElement(reactNative.View, {
|
298
322
|
style: [styles$9.step, stepStyle === "square" && styles$9.squareStep, {
|
@@ -409,13 +433,29 @@ var Form = function Form(_a) {
|
|
409
433
|
});
|
410
434
|
});
|
411
435
|
};
|
436
|
+
var handleFormSubmit = function handleFormSubmit(formValues) {
|
437
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
438
|
+
var validationErrors;
|
439
|
+
return __generator(this, function (_a) {
|
440
|
+
switch (_a.label) {
|
441
|
+
case 0:
|
442
|
+
return [4 /*yield*/, onSubmit(formValues)];
|
443
|
+
case 1:
|
444
|
+
validationErrors = _a.sent();
|
445
|
+
setErrors(validationErrors);
|
446
|
+
return [2 /*return*/, validationErrors];
|
447
|
+
}
|
448
|
+
});
|
449
|
+
});
|
450
|
+
};
|
412
451
|
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
413
452
|
value: {
|
414
453
|
formValues: formValues,
|
415
454
|
setFormValue: setFormValue,
|
416
455
|
errors: errors,
|
417
456
|
setErrors: setErrors,
|
418
|
-
handleSubmit: handleSubmit
|
457
|
+
handleSubmit: handleSubmit,
|
458
|
+
handleFormSubmit: handleFormSubmit
|
419
459
|
}
|
420
460
|
}, stepper && (/*#__PURE__*/React.createElement(Stepper, {
|
421
461
|
steps: stepper.steps,
|
@@ -424,7 +464,8 @@ var Form = function Form(_a) {
|
|
424
464
|
onPress: stepper.onPress,
|
425
465
|
totalSteps: stepper.totalSteps,
|
426
466
|
stepType: stepper.stepType,
|
427
|
-
icon: stepper.icon
|
467
|
+
icon: stepper.icon,
|
468
|
+
stepStyle: stepper.stepStyle
|
428
469
|
})), children);
|
429
470
|
};
|
430
471
|
|