aport-tools 4.4.11 → 4.4.13

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.11 | ISC */
1
+ /*! aport-tools v4.4.13 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -214,37 +214,26 @@ var Stepper = function Stepper(_a) {
214
214
  seterrorBack = _f[1];
215
215
  var handleStepPress = function handleStepPress(stepIndex) {
216
216
  return __awaiter(void 0, void 0, void 0, function () {
217
- var current, target, errors;
217
+ var targetStep, errors;
218
218
  return __generator(this, function (_a) {
219
219
  switch (_a.label) {
220
220
  case 0:
221
221
  if (!presseable || stepIndex === currentStep) return [2 /*return*/];
222
- current = currentStep;
223
- target = stepIndex;
224
- _a.label = 1;
225
- case 1:
226
- if (!(current !== target)) return [3 /*break*/, 5];
227
- if (!(target > current)) return [3 /*break*/, 3];
222
+ targetStep = stepIndex > currentStep ? currentStep + 1 : currentStep - 1;
223
+ if (!(targetStep > currentStep)) return [3 /*break*/, 2];
228
224
  return [4 /*yield*/, handleFormSubmit(formValues)];
229
- case 2:
225
+ case 1:
230
226
  errors = _a.sent();
231
227
  if (Object.keys(errors).length > 0) {
232
- console.log("Validation failed at step ".concat(current + 1, ". Cannot proceed to step ").concat(current + 2, "."));
228
+ console.log("Validation failed at step ".concat(currentStep, ". Cannot proceed to step ").concat(targetStep, "."));
233
229
  seterrorBack(true);
234
- return [2 /*return*/]; // Stop if the current step has errors
230
+ return [2 /*return*/]; // Stop if current step has errors
235
231
  }
232
+ _a.label = 2;
233
+ case 2:
234
+ // Update step
236
235
  seterrorBack(false);
237
- current += 1; // Move to the next step
238
- return [3 /*break*/, 4];
239
- case 3:
240
- // Moving backward: No validation required
241
- current -= 1;
242
- _a.label = 4;
243
- case 4:
244
- // Update the current step visually for each intermediate step
245
- onPress === null || onPress === void 0 ? void 0 : onPress(current);
246
- return [3 /*break*/, 1];
247
- case 5:
236
+ onPress === null || onPress === void 0 ? void 0 : onPress(targetStep);
248
237
  return [2 /*return*/];
249
238
  }
250
239
  });
@@ -549,14 +538,27 @@ var Input = function Input(_a) {
549
538
  var name = _a.name,
550
539
  label = _a.label,
551
540
  inputType = _a.inputType,
541
+ firstValue = _a.firstValue,
552
542
  style = _a.style,
553
- rest = __rest(_a, ["name", "label", "inputType", "style"]);
543
+ rest = __rest(_a, ["name", "label", "inputType", "firstValue", "style"]);
554
544
  var _b = useFormContext(),
555
545
  formValues = _b.formValues,
556
546
  setFormValue = _b.setFormValue,
557
547
  formErrors = _b.errors;
558
548
  var theme = React.useContext(aportThemes.ThemeContext).theme;
559
549
  var colors = theme.colors;
550
+ var _c = React.useState(""),
551
+ internalValue = _c[0],
552
+ setInternalValue = _c[1];
553
+ // Initialize the internal value based on `firstValue` or `formValues`
554
+ React.useEffect(function () {
555
+ if (firstValue) {
556
+ setInternalValue(firstValue);
557
+ setFormValue(name, firstValue);
558
+ } else {
559
+ setInternalValue(formValues[name] || "");
560
+ }
561
+ }, [firstValue, formValues[name]]);
560
562
  /**
561
563
  * Handles text changes in the input field, applying formatting based on the inputType.
562
564
  *
@@ -586,6 +588,7 @@ var Input = function Input(_a) {
586
588
  formattedText = text.replace(/\D/g, "");
587
589
  break;
588
590
  }
591
+ setInternalValue(formattedText);
589
592
  setFormValue(name, formattedText);
590
593
  };
591
594
  return /*#__PURE__*/React.createElement(reactNative.View, {
@@ -600,7 +603,7 @@ var Input = function Input(_a) {
600
603
  borderColor: formErrors[name] ? colors.error.hex : "#CCC",
601
604
  color: colors.text.hex
602
605
  }, style],
603
- value: formValues[name] || "",
606
+ value: internalValue,
604
607
  onChangeText: handleChange,
605
608
  placeholder: label,
606
609
  placeholderTextColor: colors.placeHolder.hex