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 CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.4.18 | ISC */
1
+ /*! aport-tools v4.4.19 | ISC */
2
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';
@@ -730,36 +730,29 @@ var InputList = function InputList(_a) {
730
730
  closeOnSelect = _h === void 0 ? true : _h,
731
731
  maxSelection = _a.maxSelection,
732
732
  onChange = _a.onChange;
733
- var _j = useFormContext(),
734
- formValues = _j.formValues,
735
- setFormValue = _j.setFormValue,
733
+ var _j = useFormContext();
734
+ _j.formValues;
735
+ var setFormValue = _j.setFormValue,
736
736
  formErrors = _j.errors;
737
737
  var _k = useState(false),
738
738
  isDropdownVisible = _k[0],
739
739
  setIsDropdownVisible = _k[1];
740
- var selectedOptions = formValues[name] || (multi ? [] : null);
741
740
  var sortedOptions = sortBy ? __spreadArray([], options, true).sort(function (a, b) {
742
741
  return a[sortBy] > b[sortBy] ? 1 : -1;
743
742
  }) : options;
744
743
  var theme = useContext(ThemeContext).theme;
745
744
  var colors = theme.colors;
746
- var _l = useState();
747
- _l[0];
748
- var setInternalValue = _l[1];
749
- // Initialize the internal value based on `firstValue` or `formValues`
745
+ // Initialize selected options based on firstValue
746
+ var initialSelections = options.filter(function (opt) {
747
+ return firstValue.includes(opt.value);
748
+ });
749
+ var _l = useState(multi ? initialSelections : initialSelections[0] || null),
750
+ selectedOptions = _l[0];
751
+ _l[1];
752
+ // Update form value on mount if firstValue is provided
750
753
  useEffect(function () {
751
- if (firstValue) {
752
- setInternalValue(firstValue);
753
- setFormValue(name, firstValue);
754
- } else {
755
- setInternalValue(formValues[name] || "");
756
- }
757
- }, [firstValue, formValues[name]]);
758
- /**
759
- * Handles selection of an option. Adds or removes the option from selectedOptions based on
760
- * multi-selection and maxSelection criteria.
761
- * @param {Option} option - The selected option object.
762
- */
754
+ setFormValue(name, multi ? initialSelections : initialSelections[0] || null);
755
+ }, [firstValue]);
763
756
  var handleSelectOption = function handleSelectOption(option) {
764
757
  var updatedSelections;
765
758
  if (multi) {
@@ -804,25 +797,19 @@ var InputList = function InputList(_a) {
804
797
  }
805
798
  return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
806
799
  };
807
- /**
808
- * Renders selected options as a comma-separated string or the placeholder if none selected.
809
- * @returns {string} - The display text for selected options or placeholder.
810
- */
811
- /**
812
- * Toggles dropdown visibility. Disables toggle if the component is disabled.
813
- */
814
800
  var toggleDropdown = function toggleDropdown() {
815
801
  if (!disabled) {
816
802
  setIsDropdownVisible(!isDropdownVisible);
817
803
  if (!isDropdownVisible) Keyboard.dismiss();
818
804
  }
819
805
  };
820
- /**
821
- * Closes the dropdown when pressing outside.
822
- */
823
806
  var handleCloseDropdown = useCallback(function () {
824
807
  if (isDropdownVisible) setIsDropdownVisible(false);
825
808
  }, [isDropdownVisible]);
809
+ /**
810
+ * Renders selected options as a comma-separated string or the placeholder if none selected.
811
+ * @returns {string} - The display text for selected options or placeholder.
812
+ */
826
813
  // Conditionally render item as disabled if max selection reached and item is unselected
827
814
  return /*#__PURE__*/React.createElement(View, {
828
815
  style: [styles$4.container, style]