aport-tools 4.4.18 → 4.4.19
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/index.esm.js +18 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +18 -31
- 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.19 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
@@ -751,36 +751,29 @@ 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
|
-
|
756
|
-
setFormValue = _j.setFormValue,
|
754
|
+
var _j = useFormContext();
|
755
|
+
_j.formValues;
|
756
|
+
var 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 selectedOptions = formValues[name] || (multi ? [] : null);
|
762
761
|
var sortedOptions = sortBy ? __spreadArray([], options, true).sort(function (a, b) {
|
763
762
|
return a[sortBy] > b[sortBy] ? 1 : -1;
|
764
763
|
}) : options;
|
765
764
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
766
765
|
var colors = theme.colors;
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
766
|
+
// Initialize selected options based on firstValue
|
767
|
+
var initialSelections = options.filter(function (opt) {
|
768
|
+
return firstValue.includes(opt.value);
|
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
|
771
774
|
React.useEffect(function () {
|
772
|
-
|
773
|
-
|
774
|
-
setFormValue(name, firstValue);
|
775
|
-
} else {
|
776
|
-
setInternalValue(formValues[name] || "");
|
777
|
-
}
|
778
|
-
}, [firstValue, formValues[name]]);
|
779
|
-
/**
|
780
|
-
* Handles selection of an option. Adds or removes the option from selectedOptions based on
|
781
|
-
* multi-selection and maxSelection criteria.
|
782
|
-
* @param {Option} option - The selected option object.
|
783
|
-
*/
|
775
|
+
setFormValue(name, multi ? initialSelections : initialSelections[0] || null);
|
776
|
+
}, [firstValue]);
|
784
777
|
var handleSelectOption = function handleSelectOption(option) {
|
785
778
|
var updatedSelections;
|
786
779
|
if (multi) {
|
@@ -825,25 +818,19 @@ var InputList = function InputList(_a) {
|
|
825
818
|
}
|
826
819
|
return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
|
827
820
|
};
|
828
|
-
/**
|
829
|
-
* Renders selected options as a comma-separated string or the placeholder if none selected.
|
830
|
-
* @returns {string} - The display text for selected options or placeholder.
|
831
|
-
*/
|
832
|
-
/**
|
833
|
-
* Toggles dropdown visibility. Disables toggle if the component is disabled.
|
834
|
-
*/
|
835
821
|
var toggleDropdown = function toggleDropdown() {
|
836
822
|
if (!disabled) {
|
837
823
|
setIsDropdownVisible(!isDropdownVisible);
|
838
824
|
if (!isDropdownVisible) reactNative.Keyboard.dismiss();
|
839
825
|
}
|
840
826
|
};
|
841
|
-
/**
|
842
|
-
* Closes the dropdown when pressing outside.
|
843
|
-
*/
|
844
827
|
var handleCloseDropdown = React.useCallback(function () {
|
845
828
|
if (isDropdownVisible) setIsDropdownVisible(false);
|
846
829
|
}, [isDropdownVisible]);
|
830
|
+
/**
|
831
|
+
* Renders selected options as a comma-separated string or the placeholder if none selected.
|
832
|
+
* @returns {string} - The display text for selected options or placeholder.
|
833
|
+
*/
|
847
834
|
// Conditionally render item as disabled if max selection reached and item is unselected
|
848
835
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
849
836
|
style: [styles$4.container, style]
|