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.
@@ -8,6 +8,10 @@ interface InputProps extends TextInputProps {
8
8
  * The unique identifier for the input field, used to manage its state within the form.
9
9
  */
10
10
  name: string;
11
+ /**
12
+ * Optional first value if you want to set values with fetch or dont have empty inputs.
13
+ */
14
+ firstValue?: string;
11
15
  /**
12
16
  * The text label displayed above the input field.
13
17
  */
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- /*! aport-tools v4.4.11 | ISC */
2
- import React, { useContext, useState, createContext, useCallback, useMemo } from 'react';
1
+ /*! aport-tools v4.4.13 | ISC */
2
+ import React, { useContext, useState, createContext, useEffect, useCallback, useMemo } from 'react';
3
3
  import { StyleSheet, Text as Text$1, Animated, View, TouchableOpacity, Image, TextInput, Modal, Pressable, FlatList, Keyboard, Platform, Alert, ActivityIndicator } from 'react-native';
4
4
  import { ThemeContext } from 'aport-themes';
5
5
  import * as ImagePicker from 'expo-image-picker';
@@ -193,37 +193,26 @@ var Stepper = function Stepper(_a) {
193
193
  seterrorBack = _f[1];
194
194
  var handleStepPress = function handleStepPress(stepIndex) {
195
195
  return __awaiter(void 0, void 0, void 0, function () {
196
- var current, target, errors;
196
+ var targetStep, errors;
197
197
  return __generator(this, function (_a) {
198
198
  switch (_a.label) {
199
199
  case 0:
200
200
  if (!presseable || stepIndex === currentStep) return [2 /*return*/];
201
- current = currentStep;
202
- target = stepIndex;
203
- _a.label = 1;
204
- case 1:
205
- if (!(current !== target)) return [3 /*break*/, 5];
206
- if (!(target > current)) return [3 /*break*/, 3];
201
+ targetStep = stepIndex > currentStep ? currentStep + 1 : currentStep - 1;
202
+ if (!(targetStep > currentStep)) return [3 /*break*/, 2];
207
203
  return [4 /*yield*/, handleFormSubmit(formValues)];
208
- case 2:
204
+ case 1:
209
205
  errors = _a.sent();
210
206
  if (Object.keys(errors).length > 0) {
211
- console.log("Validation failed at step ".concat(current + 1, ". Cannot proceed to step ").concat(current + 2, "."));
207
+ console.log("Validation failed at step ".concat(currentStep, ". Cannot proceed to step ").concat(targetStep, "."));
212
208
  seterrorBack(true);
213
- return [2 /*return*/]; // Stop if the current step has errors
209
+ return [2 /*return*/]; // Stop if current step has errors
214
210
  }
211
+ _a.label = 2;
212
+ case 2:
213
+ // Update step
215
214
  seterrorBack(false);
216
- current += 1; // Move to the next step
217
- return [3 /*break*/, 4];
218
- case 3:
219
- // Moving backward: No validation required
220
- current -= 1;
221
- _a.label = 4;
222
- case 4:
223
- // Update the current step visually for each intermediate step
224
- onPress === null || onPress === void 0 ? void 0 : onPress(current);
225
- return [3 /*break*/, 1];
226
- case 5:
215
+ onPress === null || onPress === void 0 ? void 0 : onPress(targetStep);
227
216
  return [2 /*return*/];
228
217
  }
229
218
  });
@@ -528,14 +517,27 @@ var Input = function Input(_a) {
528
517
  var name = _a.name,
529
518
  label = _a.label,
530
519
  inputType = _a.inputType,
520
+ firstValue = _a.firstValue,
531
521
  style = _a.style,
532
- rest = __rest(_a, ["name", "label", "inputType", "style"]);
522
+ rest = __rest(_a, ["name", "label", "inputType", "firstValue", "style"]);
533
523
  var _b = useFormContext(),
534
524
  formValues = _b.formValues,
535
525
  setFormValue = _b.setFormValue,
536
526
  formErrors = _b.errors;
537
527
  var theme = useContext(ThemeContext).theme;
538
528
  var colors = theme.colors;
529
+ var _c = useState(""),
530
+ internalValue = _c[0],
531
+ setInternalValue = _c[1];
532
+ // Initialize the internal value based on `firstValue` or `formValues`
533
+ useEffect(function () {
534
+ if (firstValue) {
535
+ setInternalValue(firstValue);
536
+ setFormValue(name, firstValue);
537
+ } else {
538
+ setInternalValue(formValues[name] || "");
539
+ }
540
+ }, [firstValue, formValues[name]]);
539
541
  /**
540
542
  * Handles text changes in the input field, applying formatting based on the inputType.
541
543
  *
@@ -565,6 +567,7 @@ var Input = function Input(_a) {
565
567
  formattedText = text.replace(/\D/g, "");
566
568
  break;
567
569
  }
570
+ setInternalValue(formattedText);
568
571
  setFormValue(name, formattedText);
569
572
  };
570
573
  return /*#__PURE__*/React.createElement(View, {
@@ -579,7 +582,7 @@ var Input = function Input(_a) {
579
582
  borderColor: formErrors[name] ? colors.error.hex : "#CCC",
580
583
  color: colors.text.hex
581
584
  }, style],
582
- value: formValues[name] || "",
585
+ value: internalValue,
583
586
  onChangeText: handleChange,
584
587
  placeholder: label,
585
588
  placeholderTextColor: colors.placeHolder.hex