aport-tools 4.4.13 → 4.4.15
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 +4 -0
- package/dist/forms/TextArea.d.ts +4 -0
- package/dist/index.esm.js +72 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +72 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
@@ -11,6 +11,10 @@ interface InputListProps {
|
|
11
11
|
* @type {string}
|
12
12
|
* @default "Choose value/s"
|
13
13
|
*/
|
14
|
+
/**
|
15
|
+
* Optional first value if you want to set values with fetch or dont have empty inputs.
|
16
|
+
*/
|
17
|
+
firstValue?: any[];
|
14
18
|
placeholder?: string;
|
15
19
|
/**
|
16
20
|
* Custom styles for the component.
|
package/dist/forms/TextArea.d.ts
CHANGED
@@ -2,6 +2,10 @@ import React from 'react';
|
|
2
2
|
import { TextInputProps } from 'react-native';
|
3
3
|
interface TextAreaProps extends TextInputProps {
|
4
4
|
name: string;
|
5
|
+
/**
|
6
|
+
* Optional first value if you want to set values with fetch or dont have empty inputs.
|
7
|
+
*/
|
8
|
+
firstValue?: string;
|
5
9
|
label: string;
|
6
10
|
errors?: string[];
|
7
11
|
}
|
package/dist/index.esm.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
1
|
+
/*! aport-tools v4.4.15 | 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';
|
@@ -611,15 +611,29 @@ var TextArea = function TextArea(_a) {
|
|
611
611
|
var name = _a.name,
|
612
612
|
label = _a.label;
|
613
613
|
_a.errors;
|
614
|
-
var
|
615
|
-
|
614
|
+
var firstValue = _a.firstValue,
|
615
|
+
style = _a.style,
|
616
|
+
rest = __rest(_a, ["name", "label", "errors", "firstValue", "style"]);
|
616
617
|
var _b = useFormContext(),
|
617
618
|
formValues = _b.formValues,
|
618
619
|
setFormValue = _b.setFormValue,
|
619
620
|
formErrors = _b.errors;
|
620
621
|
var theme = useContext(ThemeContext).theme;
|
621
622
|
var colors = theme.colors;
|
623
|
+
var _c = useState(""),
|
624
|
+
internalValue = _c[0],
|
625
|
+
setInternalValue = _c[1];
|
626
|
+
// Initialize the internal value based on `firstValue` or `formValues`
|
627
|
+
useEffect(function () {
|
628
|
+
if (firstValue) {
|
629
|
+
setInternalValue(firstValue);
|
630
|
+
setFormValue(name, firstValue);
|
631
|
+
} else {
|
632
|
+
setInternalValue(formValues[name] || "");
|
633
|
+
}
|
634
|
+
}, [firstValue, formValues[name]]);
|
622
635
|
var handleChange = function handleChange(text) {
|
636
|
+
setInternalValue(text);
|
623
637
|
setFormValue(name, text);
|
624
638
|
};
|
625
639
|
return /*#__PURE__*/React.createElement(View, {
|
@@ -634,7 +648,7 @@ var TextArea = function TextArea(_a) {
|
|
634
648
|
color: colors.text.hex,
|
635
649
|
borderColor: formErrors[name] ? colors.error.hex : "#CCC"
|
636
650
|
}],
|
637
|
-
value:
|
651
|
+
value: internalValue,
|
638
652
|
onChangeText: handleChange,
|
639
653
|
placeholder: label,
|
640
654
|
placeholderTextColor: colors.placeHolder.hex,
|
@@ -706,27 +720,41 @@ var InputList = function InputList(_a) {
|
|
706
720
|
_d = _a.disabled,
|
707
721
|
disabled = _d === void 0 ? false : _d,
|
708
722
|
sortBy = _a.sortBy,
|
709
|
-
_e = _a.
|
710
|
-
|
711
|
-
_f = _a.
|
712
|
-
|
713
|
-
_g = _a.
|
714
|
-
|
723
|
+
_e = _a.firstValue,
|
724
|
+
firstValue = _e === void 0 ? [] : _e,
|
725
|
+
_f = _a.separator,
|
726
|
+
separator = _f === void 0 ? false : _f,
|
727
|
+
_g = _a.closeOnScroll,
|
728
|
+
closeOnScroll = _g === void 0 ? false : _g,
|
729
|
+
_h = _a.closeOnSelect,
|
730
|
+
closeOnSelect = _h === void 0 ? true : _h,
|
715
731
|
maxSelection = _a.maxSelection,
|
716
732
|
onChange = _a.onChange;
|
717
|
-
var
|
718
|
-
|
719
|
-
setFormValue =
|
720
|
-
formErrors =
|
721
|
-
var
|
722
|
-
isDropdownVisible =
|
723
|
-
setIsDropdownVisible =
|
724
|
-
var selectedOptions = formValues[name] || (multi ? [] : null);
|
733
|
+
var _j = useFormContext();
|
734
|
+
_j.formValues;
|
735
|
+
var setFormValue = _j.setFormValue,
|
736
|
+
formErrors = _j.errors;
|
737
|
+
var _k = useState(false),
|
738
|
+
isDropdownVisible = _k[0],
|
739
|
+
setIsDropdownVisible = _k[1];
|
725
740
|
var sortedOptions = sortBy ? __spreadArray([], options, true).sort(function (a, b) {
|
726
741
|
return a[sortBy] > b[sortBy] ? 1 : -1;
|
727
742
|
}) : options;
|
728
743
|
var theme = useContext(ThemeContext).theme;
|
729
744
|
var colors = theme.colors;
|
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
|
+
setSelectedOptions = _l[1];
|
752
|
+
// Update form value on mount if firstValue is provided
|
753
|
+
useEffect(function () {
|
754
|
+
if (Array.isArray(firstValue) && firstValue.length > 0) {
|
755
|
+
setSelectedOptions(firstValue);
|
756
|
+
}
|
757
|
+
}, [firstValue, setSelectedOptions]); // Dependencies are properly set.
|
730
758
|
/**
|
731
759
|
* Handles selection of an option. Adds or removes the option from selectedOptions based on
|
732
760
|
* multi-selection and maxSelection criteria.
|
@@ -735,17 +763,20 @@ var InputList = function InputList(_a) {
|
|
735
763
|
var handleSelectOption = function handleSelectOption(option) {
|
736
764
|
var updatedSelections;
|
737
765
|
if (multi) {
|
738
|
-
|
766
|
+
// Ensure selectedOptions is treated as an array
|
767
|
+
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
768
|
+
var alreadySelected = selectedArray.some(function (opt) {
|
739
769
|
return opt.id === option.id;
|
740
770
|
});
|
741
|
-
updatedSelections = alreadySelected ?
|
771
|
+
updatedSelections = alreadySelected ? selectedArray.filter(function (opt) {
|
742
772
|
return opt.id !== option.id;
|
743
|
-
}) : __spreadArray(__spreadArray([],
|
773
|
+
}) : __spreadArray(__spreadArray([], selectedArray, true), [option], false);
|
744
774
|
if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
|
745
775
|
setIsDropdownVisible(false);
|
746
776
|
}
|
747
777
|
setFormValue(name, updatedSelections);
|
748
778
|
} else {
|
779
|
+
// Handle single-selection case
|
749
780
|
updatedSelections = option;
|
750
781
|
setFormValue(name, option);
|
751
782
|
if (closeOnSelect) setIsDropdownVisible(false);
|
@@ -755,14 +786,26 @@ var InputList = function InputList(_a) {
|
|
755
786
|
onChange(updatedSelections);
|
756
787
|
}
|
757
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
|
+
};
|
758
797
|
/**
|
759
|
-
|
760
|
-
|
761
|
-
|
798
|
+
* Renders selected options as a comma-separated string or the placeholder if none selected.
|
799
|
+
* @returns {string} - The display text for selected options or placeholder.
|
800
|
+
*/
|
762
801
|
var renderSelectedText = function renderSelectedText() {
|
763
|
-
if (multi)
|
764
|
-
|
765
|
-
|
802
|
+
if (multi) {
|
803
|
+
// Ensure selectedOptions is treated as an array
|
804
|
+
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
805
|
+
return selectedArray.map(function (opt) {
|
806
|
+
return opt.label;
|
807
|
+
}).join(', ') || placeholder;
|
808
|
+
}
|
766
809
|
return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
|
767
810
|
};
|
768
811
|
/**
|
@@ -781,11 +824,6 @@ var InputList = function InputList(_a) {
|
|
781
824
|
if (isDropdownVisible) setIsDropdownVisible(false);
|
782
825
|
}, [isDropdownVisible]);
|
783
826
|
// Conditionally render item as disabled if max selection reached and item is unselected
|
784
|
-
var isItemDisabled = function isItemDisabled(option) {
|
785
|
-
return multi && maxSelection && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
|
786
|
-
return opt.id === option.id;
|
787
|
-
});
|
788
|
-
};
|
789
827
|
return /*#__PURE__*/React.createElement(View, {
|
790
828
|
style: [styles$4.container, style]
|
791
829
|
}, /*#__PURE__*/React.createElement(Text$1, {
|
@@ -823,9 +861,9 @@ var InputList = function InputList(_a) {
|
|
823
861
|
},
|
824
862
|
renderItem: function renderItem(_a) {
|
825
863
|
var item = _a.item;
|
826
|
-
var isSelected = multi ? selectedOptions.some(function (opt) {
|
864
|
+
var isSelected = multi ? Array.isArray(selectedOptions) && selectedOptions.some(function (opt) {
|
827
865
|
return opt.id === item.id;
|
828
|
-
}) :
|
866
|
+
}) : selectedOptions && 'id' in selectedOptions && selectedOptions.id === item.id;
|
829
867
|
var isDisabled = isItemDisabled(item);
|
830
868
|
return /*#__PURE__*/React.createElement(TouchableOpacity, {
|
831
869
|
onPress: function onPress() {
|