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.
- package/dist/forms/Input.d.ts +4 -0
- package/dist/index.esm.js +18 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +17 -3
- 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.13 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
@@ -538,14 +538,27 @@ var Input = function Input(_a) {
|
|
538
538
|
var name = _a.name,
|
539
539
|
label = _a.label,
|
540
540
|
inputType = _a.inputType,
|
541
|
+
firstValue = _a.firstValue,
|
541
542
|
style = _a.style,
|
542
|
-
rest = __rest(_a, ["name", "label", "inputType", "style"]);
|
543
|
+
rest = __rest(_a, ["name", "label", "inputType", "firstValue", "style"]);
|
543
544
|
var _b = useFormContext(),
|
544
545
|
formValues = _b.formValues,
|
545
546
|
setFormValue = _b.setFormValue,
|
546
547
|
formErrors = _b.errors;
|
547
548
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
548
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]]);
|
549
562
|
/**
|
550
563
|
* Handles text changes in the input field, applying formatting based on the inputType.
|
551
564
|
*
|
@@ -575,6 +588,7 @@ var Input = function Input(_a) {
|
|
575
588
|
formattedText = text.replace(/\D/g, "");
|
576
589
|
break;
|
577
590
|
}
|
591
|
+
setInternalValue(formattedText);
|
578
592
|
setFormValue(name, formattedText);
|
579
593
|
};
|
580
594
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
@@ -589,7 +603,7 @@ var Input = function Input(_a) {
|
|
589
603
|
borderColor: formErrors[name] ? colors.error.hex : "#CCC",
|
590
604
|
color: colors.text.hex
|
591
605
|
}, style],
|
592
|
-
value:
|
606
|
+
value: internalValue,
|
593
607
|
onChangeText: handleChange,
|
594
608
|
placeholder: label,
|
595
609
|
placeholderTextColor: colors.placeHolder.hex
|