aport-tools 4.4.4 → 4.4.6

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.4.4 | ISC */
1
+ /*! aport-tools v4.4.6 | 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
- _onPress = _a.onPress,
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,37 @@ 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 _f = React.useState(false),
213
+ errorBack = _f[0],
214
+ seterrorBack = _f[1];
215
+ var handleStepPress = function handleStepPress(stepIndex) {
216
+ return __awaiter(void 0, void 0, void 0, function () {
217
+ var errors;
218
+ return __generator(this, function (_a) {
219
+ switch (_a.label) {
220
+ case 0:
221
+ if (!presseable || stepIndex === currentStep) return [2 /*return*/];
222
+ if (!(stepIndex > currentStep)) return [3 /*break*/, 2];
223
+ return [4 /*yield*/, handleFormSubmit(formValues)];
224
+ case 1:
225
+ errors = _a.sent();
226
+ if (Object.keys(errors).length > 0) {
227
+ console.log("Validation failed. Cannot proceed to step", stepIndex);
228
+ seterrorBack(true);
229
+ return [2 /*return*/]; // Prevent step change
230
+ }
231
+ _a.label = 2;
232
+ case 2:
233
+ // Proceed to change step
234
+ onPress === null || onPress === void 0 ? void 0 : onPress(stepIndex);
235
+ return [2 /*return*/];
236
+ }
237
+ });
238
+ });
239
+ };
209
240
  React.useEffect(function () {
210
241
  reactNative.Animated.timing(progressAnim, {
211
242
  toValue: currentStep,
@@ -292,11 +323,11 @@ var Stepper = function Stepper(_a) {
292
323
  }],
293
324
  disabled: !presseable,
294
325
  onPress: function onPress() {
295
- return _onPress && _onPress(index);
326
+ return handleStepPress(index);
296
327
  }
297
328
  }, /*#__PURE__*/React.createElement(reactNative.View, {
298
329
  style: [styles$9.step, stepStyle === "square" && styles$9.squareStep, {
299
- backgroundColor: currentStep >= index ? colors.primary.hex : colors.body.hex
330
+ backgroundColor: !errorBack ? currentStep >= index ? colors.primary.hex : colors.body.hex : colors.error.hex
300
331
  }]
301
332
  }, renderStepContent(index)), steps && /*#__PURE__*/React.createElement(Text, {
302
333
  style: styles$9.stepText
@@ -409,13 +440,29 @@ var Form = function Form(_a) {
409
440
  });
410
441
  });
411
442
  };
443
+ var handleFormSubmit = function handleFormSubmit(formValues) {
444
+ return __awaiter(void 0, void 0, void 0, function () {
445
+ var validationErrors;
446
+ return __generator(this, function (_a) {
447
+ switch (_a.label) {
448
+ case 0:
449
+ return [4 /*yield*/, onSubmit(formValues)];
450
+ case 1:
451
+ validationErrors = _a.sent();
452
+ setErrors(validationErrors);
453
+ return [2 /*return*/, validationErrors];
454
+ }
455
+ });
456
+ });
457
+ };
412
458
  return /*#__PURE__*/React.createElement(FormContext.Provider, {
413
459
  value: {
414
460
  formValues: formValues,
415
461
  setFormValue: setFormValue,
416
462
  errors: errors,
417
463
  setErrors: setErrors,
418
- handleSubmit: handleSubmit
464
+ handleSubmit: handleSubmit,
465
+ handleFormSubmit: handleFormSubmit
419
466
  }
420
467
  }, stepper && (/*#__PURE__*/React.createElement(Stepper, {
421
468
  steps: stepper.steps,
@@ -424,7 +471,8 @@ var Form = function Form(_a) {
424
471
  onPress: stepper.onPress,
425
472
  totalSteps: stepper.totalSteps,
426
473
  stepType: stepper.stepType,
427
- icon: stepper.icon
474
+ icon: stepper.icon,
475
+ stepStyle: stepper.stepStyle
428
476
  })), children);
429
477
  };
430
478