aport-tools 4.4.17 → 4.4.18

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.
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
  interface Option {
3
3
  id: number | string;
4
4
  label: string;
@@ -14,7 +14,7 @@ interface InputListProps {
14
14
  /**
15
15
  * Optional first value if you want to set values with fetch or dont have empty inputs.
16
16
  */
17
- firstValue?: any[] | any;
17
+ firstValue?: any[];
18
18
  placeholder?: string;
19
19
  /**
20
20
  * Custom styles for the component.
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- /*! aport-tools v4.4.17 | ISC */
2
- import React, { useContext, useState, createContext, useEffect, useMemo, useCallback } from 'react';
1
+ /*! aport-tools v4.4.18 | ISC */
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';
5
5
  import * as ImagePicker from 'expo-image-picker';
@@ -737,25 +737,22 @@ var InputList = function InputList(_a) {
737
737
  var _k = useState(false),
738
738
  isDropdownVisible = _k[0],
739
739
  setIsDropdownVisible = _k[1];
740
- var selectedOptions = firstValue || formValues[name] || (multi ? [] : null);
741
- var sortedOptions = useMemo(function () {
742
- return sortBy ? __spreadArray([], options, true).sort(function (a, b) {
743
- return a[sortBy] > b[sortBy] ? 1 : -1;
744
- }) : options;
745
- }, [options, sortBy]);
740
+ var selectedOptions = formValues[name] || (multi ? [] : null);
741
+ var sortedOptions = sortBy ? __spreadArray([], options, true).sort(function (a, b) {
742
+ return a[sortBy] > b[sortBy] ? 1 : -1;
743
+ }) : options;
746
744
  var theme = useContext(ThemeContext).theme;
747
745
  var colors = theme.colors;
748
- var _l = useState([]);
746
+ var _l = useState();
749
747
  _l[0];
750
748
  var setInternalValue = _l[1];
751
749
  // Initialize the internal value based on `firstValue` or `formValues`
752
750
  useEffect(function () {
753
- var selectedValue = formValues[name];
754
751
  if (firstValue) {
755
752
  setInternalValue(firstValue);
756
753
  setFormValue(name, firstValue);
757
754
  } else {
758
- setInternalValue(selectedValue || (multi ? [] : null));
755
+ setInternalValue(formValues[name] || "");
759
756
  }
760
757
  }, [firstValue, formValues[name]]);
761
758
  /**
@@ -766,37 +763,51 @@ var InputList = function InputList(_a) {
766
763
  var handleSelectOption = function handleSelectOption(option) {
767
764
  var updatedSelections;
768
765
  if (multi) {
769
- var alreadySelected = (selectedOptions || []).some(function (opt) {
766
+ // Ensure selectedOptions is treated as an array
767
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
768
+ var alreadySelected = selectedArray.some(function (opt) {
770
769
  return opt.id === option.id;
771
770
  });
772
- updatedSelections = alreadySelected ? (selectedOptions || []).filter(function (opt) {
771
+ updatedSelections = alreadySelected ? selectedArray.filter(function (opt) {
773
772
  return opt.id !== option.id;
774
- }) : __spreadArray(__spreadArray([], selectedOptions || [], true), [option], false);
773
+ }) : __spreadArray(__spreadArray([], selectedArray, true), [option], false);
775
774
  if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
776
775
  setIsDropdownVisible(false);
777
776
  }
778
- setInternalValue(updatedSelections);
779
777
  setFormValue(name, updatedSelections);
780
778
  } else {
779
+ // Handle single-selection case
781
780
  updatedSelections = option;
782
- setInternalValue(option);
783
781
  setFormValue(name, option);
784
782
  if (closeOnSelect) setIsDropdownVisible(false);
785
783
  }
784
+ // Trigger onChange callback with the updated selection
786
785
  if (onChange) {
787
786
  onChange(updatedSelections);
788
787
  }
789
788
  };
789
+ var isItemDisabled = function isItemDisabled(option) {
790
+ if (!multi) return false; // Disable check only applies for multi-select
791
+ // Ensure selectedOptions is treated as an array
792
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
793
+ return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
794
+ return opt.id === option.id;
795
+ });
796
+ };
797
+ var renderSelectedText = function renderSelectedText() {
798
+ if (multi) {
799
+ // Ensure selectedOptions is treated as an array
800
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
801
+ return selectedArray.map(function (opt) {
802
+ return opt.label;
803
+ }).join(', ') || placeholder;
804
+ }
805
+ return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
806
+ };
790
807
  /**
791
808
  * Renders selected options as a comma-separated string or the placeholder if none selected.
792
809
  * @returns {string} - The display text for selected options or placeholder.
793
810
  */
794
- var renderSelectedText = function renderSelectedText() {
795
- if (multi) return (selectedOptions || []).map(function (opt) {
796
- return opt.label;
797
- }).join(", ") || placeholder;
798
- return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
799
- };
800
811
  /**
801
812
  * Toggles dropdown visibility. Disables toggle if the component is disabled.
802
813
  */
@@ -813,11 +824,6 @@ var InputList = function InputList(_a) {
813
824
  if (isDropdownVisible) setIsDropdownVisible(false);
814
825
  }, [isDropdownVisible]);
815
826
  // Conditionally render item as disabled if max selection reached and item is unselected
816
- var isItemDisabled = function isItemDisabled(option) {
817
- return multi && maxSelection && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
818
- return opt.id === option.id;
819
- });
820
- };
821
827
  return /*#__PURE__*/React.createElement(View, {
822
828
  style: [styles$4.container, style]
823
829
  }, /*#__PURE__*/React.createElement(Text$1, {
@@ -855,9 +861,9 @@ var InputList = function InputList(_a) {
855
861
  },
856
862
  renderItem: function renderItem(_a) {
857
863
  var item = _a.item;
858
- var isSelected = multi ? selectedOptions.some(function (opt) {
864
+ var isSelected = multi ? Array.isArray(selectedOptions) && selectedOptions.some(function (opt) {
859
865
  return opt.id === item.id;
860
- }) : (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.id) === item.id;
866
+ }) : selectedOptions && 'id' in selectedOptions && selectedOptions.id === item.id;
861
867
  var isDisabled = isItemDisabled(item);
862
868
  return /*#__PURE__*/React.createElement(TouchableOpacity, {
863
869
  onPress: function onPress() {
@@ -895,12 +901,12 @@ var styles$4 = StyleSheet.create({
895
901
  borderRadius: 5
896
902
  },
897
903
  dropdownContainer: {
898
- position: "absolute",
899
- top: "30%",
904
+ position: 'absolute',
905
+ top: '30%',
900
906
  // Center the dropdown vertically
901
- alignSelf: "center",
902
- width: "90%",
903
- backgroundColor: "#fff",
907
+ alignSelf: 'center',
908
+ width: '90%',
909
+ backgroundColor: '#fff',
904
910
  borderRadius: 8,
905
911
  elevation: 5,
906
912
  paddingVertical: 10
@@ -909,16 +915,16 @@ var styles$4 = StyleSheet.create({
909
915
  padding: 12
910
916
  },
911
917
  disabledText: {
912
- color: "#999"
918
+ color: '#999'
913
919
  },
914
920
  separator: {
915
921
  height: 1,
916
- backgroundColor: "#ddd",
922
+ backgroundColor: '#ddd',
917
923
  marginHorizontal: 8
918
924
  },
919
925
  overlay: {
920
926
  flex: 1,
921
- backgroundColor: "rgba(0,0,0,0.3)"
927
+ backgroundColor: 'rgba(0,0,0,0.3)'
922
928
  }
923
929
  });
924
930