aport-tools 4.4.14 → 4.4.16
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/InputList.d.ts +1 -1
- package/dist/index.esm.js +49 -53
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +48 -52
- 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.16 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
@@ -751,29 +751,34 @@ var InputList = function InputList(_a) {
|
|
751
751
|
closeOnSelect = _h === void 0 ? true : _h,
|
752
752
|
maxSelection = _a.maxSelection,
|
753
753
|
onChange = _a.onChange;
|
754
|
-
var _j = useFormContext()
|
755
|
-
_j.formValues
|
756
|
-
|
754
|
+
var _j = useFormContext(),
|
755
|
+
formValues = _j.formValues,
|
756
|
+
setFormValue = _j.setFormValue,
|
757
757
|
formErrors = _j.errors;
|
758
758
|
var _k = React.useState(false),
|
759
759
|
isDropdownVisible = _k[0],
|
760
760
|
setIsDropdownVisible = _k[1];
|
761
|
-
var
|
762
|
-
|
763
|
-
|
761
|
+
var selectedOptions = formValues[name] || (multi ? [] : null);
|
762
|
+
var sortedOptions = React.useMemo(function () {
|
763
|
+
return sortBy ? __spreadArray([], options, true).sort(function (a, b) {
|
764
|
+
return a[sortBy] > b[sortBy] ? 1 : -1;
|
765
|
+
}) : options;
|
766
|
+
}, [options, sortBy]);
|
764
767
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
765
768
|
var colors = theme.colors;
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
var _l = React.useState(multi ? initialSelections : initialSelections[0] || null),
|
771
|
-
selectedOptions = _l[0];
|
772
|
-
_l[1];
|
773
|
-
// Update form value on mount if firstValue is provided
|
769
|
+
var _l = React.useState([]);
|
770
|
+
_l[0];
|
771
|
+
var setInternalValue = _l[1];
|
772
|
+
// Initialize the internal value based on `firstValue` or `formValues`
|
774
773
|
React.useEffect(function () {
|
775
|
-
|
776
|
-
|
774
|
+
var selectedValue = formValues[name];
|
775
|
+
if (firstValue) {
|
776
|
+
setInternalValue(firstValue);
|
777
|
+
setFormValue(name, firstValue);
|
778
|
+
} else {
|
779
|
+
setInternalValue(selectedValue || "");
|
780
|
+
}
|
781
|
+
}, [firstValue, formValues[name]]);
|
777
782
|
/**
|
778
783
|
* Handles selection of an option. Adds or removes the option from selectedOptions based on
|
779
784
|
* multi-selection and maxSelection criteria.
|
@@ -782,49 +787,35 @@ var InputList = function InputList(_a) {
|
|
782
787
|
var handleSelectOption = function handleSelectOption(option) {
|
783
788
|
var updatedSelections;
|
784
789
|
if (multi) {
|
785
|
-
|
786
|
-
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
787
|
-
var alreadySelected = selectedArray.some(function (opt) {
|
790
|
+
var alreadySelected = (selectedOptions || []).some(function (opt) {
|
788
791
|
return opt.id === option.id;
|
789
792
|
});
|
790
|
-
updatedSelections = alreadySelected ?
|
793
|
+
updatedSelections = alreadySelected ? (selectedOptions || []).filter(function (opt) {
|
791
794
|
return opt.id !== option.id;
|
792
|
-
}) : __spreadArray(__spreadArray([],
|
795
|
+
}) : __spreadArray(__spreadArray([], selectedOptions || [], true), [option], false);
|
793
796
|
if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
|
794
797
|
setIsDropdownVisible(false);
|
795
798
|
}
|
799
|
+
setInternalValue(updatedSelections);
|
796
800
|
setFormValue(name, updatedSelections);
|
797
801
|
} else {
|
798
|
-
// Handle single-selection case
|
799
802
|
updatedSelections = option;
|
803
|
+
setInternalValue(option);
|
800
804
|
setFormValue(name, option);
|
801
805
|
if (closeOnSelect) setIsDropdownVisible(false);
|
802
806
|
}
|
803
|
-
// Trigger onChange callback with the updated selection
|
804
807
|
if (onChange) {
|
805
808
|
onChange(updatedSelections);
|
806
809
|
}
|
807
810
|
};
|
808
|
-
var isItemDisabled = function isItemDisabled(option) {
|
809
|
-
if (!multi) return false; // Disable check only applies for multi-select
|
810
|
-
// Ensure selectedOptions is treated as an array
|
811
|
-
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
812
|
-
return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
|
813
|
-
return opt.id === option.id;
|
814
|
-
});
|
815
|
-
};
|
816
811
|
/**
|
817
|
-
|
818
|
-
|
819
|
-
|
812
|
+
* Renders selected options as a comma-separated string or the placeholder if none selected.
|
813
|
+
* @returns {string} - The display text for selected options or placeholder.
|
814
|
+
*/
|
820
815
|
var renderSelectedText = function renderSelectedText() {
|
821
|
-
if (multi) {
|
822
|
-
|
823
|
-
|
824
|
-
return selectedArray.map(function (opt) {
|
825
|
-
return opt.label;
|
826
|
-
}).join(', ') || placeholder;
|
827
|
-
}
|
816
|
+
if (multi) return (selectedOptions || []).map(function (opt) {
|
817
|
+
return opt.label;
|
818
|
+
}).join(", ") || placeholder;
|
828
819
|
return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
|
829
820
|
};
|
830
821
|
/**
|
@@ -843,6 +834,11 @@ var InputList = function InputList(_a) {
|
|
843
834
|
if (isDropdownVisible) setIsDropdownVisible(false);
|
844
835
|
}, [isDropdownVisible]);
|
845
836
|
// Conditionally render item as disabled if max selection reached and item is unselected
|
837
|
+
var isItemDisabled = function isItemDisabled(option) {
|
838
|
+
return multi && maxSelection && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
|
839
|
+
return opt.id === option.id;
|
840
|
+
});
|
841
|
+
};
|
846
842
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
847
843
|
style: [styles$4.container, style]
|
848
844
|
}, /*#__PURE__*/React.createElement(reactNative.Text, {
|
@@ -880,9 +876,9 @@ var InputList = function InputList(_a) {
|
|
880
876
|
},
|
881
877
|
renderItem: function renderItem(_a) {
|
882
878
|
var item = _a.item;
|
883
|
-
var isSelected = multi ?
|
879
|
+
var isSelected = multi ? selectedOptions.some(function (opt) {
|
884
880
|
return opt.id === item.id;
|
885
|
-
}) : selectedOptions
|
881
|
+
}) : (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.id) === item.id;
|
886
882
|
var isDisabled = isItemDisabled(item);
|
887
883
|
return /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
|
888
884
|
onPress: function onPress() {
|
@@ -920,12 +916,12 @@ var styles$4 = reactNative.StyleSheet.create({
|
|
920
916
|
borderRadius: 5
|
921
917
|
},
|
922
918
|
dropdownContainer: {
|
923
|
-
position:
|
924
|
-
top:
|
919
|
+
position: "absolute",
|
920
|
+
top: "30%",
|
925
921
|
// Center the dropdown vertically
|
926
|
-
alignSelf:
|
927
|
-
width:
|
928
|
-
backgroundColor:
|
922
|
+
alignSelf: "center",
|
923
|
+
width: "90%",
|
924
|
+
backgroundColor: "#fff",
|
929
925
|
borderRadius: 8,
|
930
926
|
elevation: 5,
|
931
927
|
paddingVertical: 10
|
@@ -934,16 +930,16 @@ var styles$4 = reactNative.StyleSheet.create({
|
|
934
930
|
padding: 12
|
935
931
|
},
|
936
932
|
disabledText: {
|
937
|
-
color:
|
933
|
+
color: "#999"
|
938
934
|
},
|
939
935
|
separator: {
|
940
936
|
height: 1,
|
941
|
-
backgroundColor:
|
937
|
+
backgroundColor: "#ddd",
|
942
938
|
marginHorizontal: 8
|
943
939
|
},
|
944
940
|
overlay: {
|
945
941
|
flex: 1,
|
946
|
-
backgroundColor:
|
942
|
+
backgroundColor: "rgba(0,0,0,0.3)"
|
947
943
|
}
|
948
944
|
});
|
949
945
|
|