aport-tools 4.4.25 → 4.4.27
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/InputCheck.d.ts +8 -6
- package/dist/index.esm.js +43 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +43 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
@@ -1,17 +1,19 @@
|
|
1
1
|
import React from "react";
|
2
|
+
interface InputOption {
|
3
|
+
id: string;
|
4
|
+
label?: string;
|
5
|
+
icon?: string;
|
6
|
+
value: string;
|
7
|
+
}
|
2
8
|
interface InputCheckProps {
|
3
9
|
name: string;
|
4
|
-
options:
|
5
|
-
id: string;
|
6
|
-
label: string;
|
7
|
-
icon?: string;
|
8
|
-
value: string;
|
9
|
-
}[];
|
10
|
+
options: InputOption[];
|
10
11
|
multi?: boolean;
|
11
12
|
max?: number;
|
12
13
|
rowAmount?: number;
|
13
14
|
iconPosition?: "row" | "column";
|
14
15
|
disabled?: boolean;
|
16
|
+
firstValue: InputOption[];
|
15
17
|
}
|
16
18
|
declare const InputCheck: React.FC<InputCheckProps>;
|
17
19
|
export default InputCheck;
|
package/dist/index.esm.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
1
|
+
/*! aport-tools v4.4.27 | ISC */
|
2
2
|
import React, { useContext, useState, createContext, useRef, useEffect, useMemo, useCallback } 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';
|
@@ -1015,19 +1015,39 @@ var InputCheck = function InputCheck(_a) {
|
|
1015
1015
|
max = _a.max,
|
1016
1016
|
_c = _a.rowAmount,
|
1017
1017
|
rowAmount = _c === void 0 ? 3 : _c,
|
1018
|
-
_d = _a.
|
1019
|
-
|
1020
|
-
_e = _a.
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1018
|
+
_d = _a.firstValue,
|
1019
|
+
firstValue = _d === void 0 ? [] : _d,
|
1020
|
+
_e = _a.iconPosition,
|
1021
|
+
iconPosition = _e === void 0 ? "row" : _e,
|
1022
|
+
_f = _a.disabled,
|
1023
|
+
disabled = _f === void 0 ? false : _f;
|
1024
|
+
var _g = useFormContext(),
|
1025
|
+
formValues = _g.formValues,
|
1026
|
+
setFormValue = _g.setFormValue,
|
1027
|
+
formErrors = _g.errors;
|
1028
|
+
var _h = useState(formValues[name] || []),
|
1029
|
+
selectedValues = _h[0],
|
1030
|
+
setSelectedValues = _h[1];
|
1029
1031
|
var theme = useContext(ThemeContext).theme;
|
1030
1032
|
var colors = theme.colors;
|
1033
|
+
// Sync firstValue with selectedValues on mount or when firstValue changes
|
1034
|
+
useEffect(function () {
|
1035
|
+
var initialSelectedValues = options.filter(function (option) {
|
1036
|
+
return firstValue.some(function (fv) {
|
1037
|
+
return fv.value === option.value;
|
1038
|
+
});
|
1039
|
+
});
|
1040
|
+
var formattedValues = initialSelectedValues.map(function (_a) {
|
1041
|
+
var id = _a.id,
|
1042
|
+
value = _a.value;
|
1043
|
+
return {
|
1044
|
+
id: id,
|
1045
|
+
value: value
|
1046
|
+
};
|
1047
|
+
});
|
1048
|
+
setSelectedValues(formattedValues);
|
1049
|
+
setFormValue(name, formattedValues); // Update form context
|
1050
|
+
}, [firstValue, name, options, setFormValue]);
|
1031
1051
|
var handleSelect = function handleSelect(id, value) {
|
1032
1052
|
if (disabled) return;
|
1033
1053
|
var updatedSelection;
|
@@ -1075,11 +1095,11 @@ var InputCheck = function InputCheck(_a) {
|
|
1075
1095
|
uri: item.icon
|
1076
1096
|
},
|
1077
1097
|
style: [styles$2.icon, iconPosition === "column" && styles$2.iconColumn]
|
1078
|
-
})), /*#__PURE__*/React.createElement(Text, {
|
1098
|
+
})), item.label && (/*#__PURE__*/React.createElement(Text, {
|
1079
1099
|
style: [styles$2.label, {
|
1080
1100
|
color: isSelected ? colors.textButton.hex : colors.text.hex
|
1081
1101
|
}]
|
1082
|
-
}, item.label));
|
1102
|
+
}, item.label)));
|
1083
1103
|
};
|
1084
1104
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
|
1085
1105
|
style: styles$2.title
|
@@ -1147,18 +1167,19 @@ var InputAttach = function InputAttach(_a) {
|
|
1147
1167
|
var _g = useFormContext(),
|
1148
1168
|
setFormValue = _g.setFormValue,
|
1149
1169
|
formErrors = _g.errors;
|
1150
|
-
|
1151
|
-
var _h = useState(function () {
|
1152
|
-
return Array.isArray(firstValue) ? firstValue.slice(0, amount) : [];
|
1153
|
-
}),
|
1170
|
+
var _h = useState([]),
|
1154
1171
|
selectedFiles = _h[0],
|
1155
1172
|
setSelectedFiles = _h[1];
|
1156
|
-
//
|
1173
|
+
// Ref to track initialization
|
1174
|
+
var isInitialized = useRef(false);
|
1175
|
+
// Sync firstValue with selectedFiles when it changes
|
1157
1176
|
useEffect(function () {
|
1158
|
-
if (
|
1159
|
-
|
1177
|
+
if (!isInitialized.current) {
|
1178
|
+
setSelectedFiles(firstValue);
|
1179
|
+
setFormValue(name, firstValue); // Update form context
|
1180
|
+
isInitialized.current = true;
|
1160
1181
|
}
|
1161
|
-
}, [firstValue, name, setFormValue
|
1182
|
+
}, [firstValue, name, setFormValue]);
|
1162
1183
|
var theme = useContext(ThemeContext).theme;
|
1163
1184
|
var colors = theme.colors;
|
1164
1185
|
var pickImage = function pickImage() {
|