aport-tools 4.4.12 → 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.12 | 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';
@@ -517,14 +517,27 @@ var Input = function Input(_a) {
517
517
  var name = _a.name,
518
518
  label = _a.label,
519
519
  inputType = _a.inputType,
520
+ firstValue = _a.firstValue,
520
521
  style = _a.style,
521
- rest = __rest(_a, ["name", "label", "inputType", "style"]);
522
+ rest = __rest(_a, ["name", "label", "inputType", "firstValue", "style"]);
522
523
  var _b = useFormContext(),
523
524
  formValues = _b.formValues,
524
525
  setFormValue = _b.setFormValue,
525
526
  formErrors = _b.errors;
526
527
  var theme = useContext(ThemeContext).theme;
527
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]]);
528
541
  /**
529
542
  * Handles text changes in the input field, applying formatting based on the inputType.
530
543
  *
@@ -554,6 +567,7 @@ var Input = function Input(_a) {
554
567
  formattedText = text.replace(/\D/g, "");
555
568
  break;
556
569
  }
570
+ setInternalValue(formattedText);
557
571
  setFormValue(name, formattedText);
558
572
  };
559
573
  return /*#__PURE__*/React.createElement(View, {
@@ -568,7 +582,7 @@ var Input = function Input(_a) {
568
582
  borderColor: formErrors[name] ? colors.error.hex : "#CCC",
569
583
  color: colors.text.hex
570
584
  }, style],
571
- value: formValues[name] || "",
585
+ value: internalValue,
572
586
  onChangeText: handleChange,
573
587
  placeholder: label,
574
588
  placeholderTextColor: colors.placeHolder.hex