aport-tools 4.4.3 → 4.4.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/forms/FormContext.d.ts +108 -3
- package/dist/forms/Stepper.d.ts +41 -0
- package/dist/index.esm.js +56 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +56 -14
- 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,
|
@@ -269,10 +293,13 @@ var Stepper = function Stepper(_a) {
|
|
269
293
|
case "number":
|
270
294
|
default:
|
271
295
|
return /*#__PURE__*/React.createElement(Text, {
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
296
|
+
b: true,
|
297
|
+
typeFont: "primary",
|
298
|
+
style: [currentStep >= index ? {
|
299
|
+
color: colors.textButton.hex
|
300
|
+
} : {
|
301
|
+
color: colors.text.hex
|
302
|
+
}]
|
276
303
|
}, index + 1);
|
277
304
|
}
|
278
305
|
};
|
@@ -289,13 +316,11 @@ var Stepper = function Stepper(_a) {
|
|
289
316
|
}],
|
290
317
|
disabled: !presseable,
|
291
318
|
onPress: function onPress() {
|
292
|
-
return
|
319
|
+
return handleStepPress(index);
|
293
320
|
}
|
294
321
|
}, /*#__PURE__*/React.createElement(reactNative.View, {
|
295
|
-
style: [styles$9.step, stepStyle === "square" && styles$9.squareStep,
|
296
|
-
backgroundColor: colors.primary.hex
|
297
|
-
}, {
|
298
|
-
backgroundColor: colors.body.hex
|
322
|
+
style: [styles$9.step, stepStyle === "square" && styles$9.squareStep, {
|
323
|
+
backgroundColor: currentStep >= index ? colors.primary.hex : colors.body.hex
|
299
324
|
}]
|
300
325
|
}, renderStepContent(index)), steps && /*#__PURE__*/React.createElement(Text, {
|
301
326
|
style: styles$9.stepText
|
@@ -408,22 +433,39 @@ var Form = function Form(_a) {
|
|
408
433
|
});
|
409
434
|
});
|
410
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
|
+
};
|
411
451
|
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
412
452
|
value: {
|
413
453
|
formValues: formValues,
|
414
454
|
setFormValue: setFormValue,
|
415
455
|
errors: errors,
|
416
456
|
setErrors: setErrors,
|
417
|
-
handleSubmit: handleSubmit
|
457
|
+
handleSubmit: handleSubmit,
|
458
|
+
handleFormSubmit: handleFormSubmit
|
418
459
|
}
|
419
460
|
}, stepper && (/*#__PURE__*/React.createElement(Stepper, {
|
420
461
|
steps: stepper.steps,
|
421
|
-
currentStep: stepper.
|
462
|
+
currentStep: stepper.currentStep,
|
422
463
|
presseable: stepper.presseable,
|
423
464
|
onPress: stepper.onPress,
|
424
465
|
totalSteps: stepper.totalSteps,
|
425
466
|
stepType: stepper.stepType,
|
426
|
-
icon: stepper.icon
|
467
|
+
icon: stepper.icon,
|
468
|
+
stepStyle: stepper.stepStyle
|
427
469
|
})), children);
|
428
470
|
};
|
429
471
|
|