react-native-input-select 1.1.7 → 1.1.9
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/README.md +3 -2
- package/lib/commonjs/components/CheckBox/index.js +1 -1
- package/lib/commonjs/components/CheckBox/index.js.map +1 -1
- package/lib/commonjs/components/Dropdown/DropdownFlatList.js +4 -2
- package/lib/commonjs/components/Dropdown/DropdownFlatList.js.map +1 -1
- package/lib/commonjs/components/Dropdown/DropdownSectionList.js +6 -5
- package/lib/commonjs/components/Dropdown/DropdownSectionList.js.map +1 -1
- package/lib/commonjs/components/Input/index.js +0 -2
- package/lib/commonjs/components/Input/index.js.map +1 -1
- package/lib/commonjs/index.js +27 -25
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/index.js +1 -1
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/components/CheckBox/index.js +1 -1
- package/lib/module/components/CheckBox/index.js.map +1 -1
- package/lib/module/components/Dropdown/DropdownFlatList.js +4 -2
- package/lib/module/components/Dropdown/DropdownFlatList.js.map +1 -1
- package/lib/module/components/Dropdown/DropdownSectionList.js +6 -5
- package/lib/module/components/Dropdown/DropdownSectionList.js.map +1 -1
- package/lib/module/components/Input/index.js +0 -2
- package/lib/module/components/Input/index.js.map +1 -1
- package/lib/module/index.js +27 -25
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/components/Input/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/CheckBox/index.tsx +1 -1
- package/src/components/Dropdown/DropdownFlatList.tsx +5 -3
- package/src/components/Dropdown/DropdownSectionList.tsx +12 -12
- package/src/components/Input/index.tsx +0 -2
- package/src/index.tsx +36 -35
- package/src/utils/index.ts +1 -1
|
@@ -9,7 +9,6 @@ export const Input = ({
|
|
|
9
9
|
style,
|
|
10
10
|
primaryColor,
|
|
11
11
|
textInputContainerStyle,
|
|
12
|
-
openModal,
|
|
13
12
|
...rest
|
|
14
13
|
}: any) => {
|
|
15
14
|
const [isFocused, setFocus] = useState(false);
|
|
@@ -30,7 +29,6 @@ export const Input = ({
|
|
|
30
29
|
]}
|
|
31
30
|
onFocus={() => {
|
|
32
31
|
setFocus(true);
|
|
33
|
-
openModal();
|
|
34
32
|
}}
|
|
35
33
|
onBlur={() => setFocus(false)}
|
|
36
34
|
value={value}
|
package/src/index.tsx
CHANGED
|
@@ -68,11 +68,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
68
68
|
const [listIndex, setListIndex] = useState<{
|
|
69
69
|
sectionIndex?: number;
|
|
70
70
|
itemIndex: number;
|
|
71
|
-
}>({ itemIndex: 0 }); // for scrollToIndex in Sectionlist and Flatlist
|
|
72
|
-
|
|
73
|
-
if (!options || options.length === 0) {
|
|
74
|
-
throw new Error('Options array cannot be empty or undefined');
|
|
75
|
-
}
|
|
71
|
+
}>({ itemIndex: 0, sectionIndex: 0 }); // for scrollToIndex in Sectionlist and Flatlist
|
|
76
72
|
|
|
77
73
|
useEffect(() => {
|
|
78
74
|
setNewOptions(options);
|
|
@@ -92,7 +88,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
92
88
|
*==========================================*/
|
|
93
89
|
|
|
94
90
|
// check the structure of the new options array to determine if it is a section list or a
|
|
95
|
-
const isSectionList = newOptions
|
|
91
|
+
const isSectionList = newOptions?.some(
|
|
96
92
|
(item) => item.title && item.data && Array.isArray(item.data)
|
|
97
93
|
);
|
|
98
94
|
|
|
@@ -102,17 +98,17 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
102
98
|
const modifiedSectionData = extractPropertyFromArray(
|
|
103
99
|
newOptions,
|
|
104
100
|
'data'
|
|
105
|
-
)
|
|
101
|
+
)?.flat();
|
|
106
102
|
|
|
107
103
|
/**
|
|
108
|
-
|
|
109
|
-
*
|
|
104
|
+
* `options` is the original array, it never changes. (Do not use except you really need the original array) .
|
|
105
|
+
* `newOptions` is a copy of options but can be mutated by `setNewOptions`, as a result, the value many change.
|
|
106
|
+
* `modifiedOptions` should only be used for computations. It has the same structure for both `FlatList` and `SectionList`
|
|
110
107
|
*/
|
|
111
108
|
const modifiedOptions = isSectionList ? modifiedSectionData : newOptions;
|
|
112
109
|
|
|
113
110
|
const optLabel = optionLabel || DEFAULT_OPTION_LABEL;
|
|
114
111
|
const optValue = optionValue || DEFAULT_OPTION_VALUE;
|
|
115
|
-
const optionsCopy = JSON.parse(JSON.stringify(options)); // copy of the original options array
|
|
116
112
|
|
|
117
113
|
/*===========================================
|
|
118
114
|
* Selection handlers
|
|
@@ -143,7 +139,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
143
139
|
};
|
|
144
140
|
|
|
145
141
|
const removeDisabledItems = (items: TFlatList) => {
|
|
146
|
-
return items
|
|
142
|
+
return items?.filter((item: TFlatListItem) => !item.disabled);
|
|
147
143
|
};
|
|
148
144
|
|
|
149
145
|
const handleSelectAll = () => {
|
|
@@ -153,8 +149,8 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
153
149
|
// don't select disabled items
|
|
154
150
|
const filteredOptions = removeDisabledItems(
|
|
155
151
|
isSectionList
|
|
156
|
-
? extractPropertyFromArray(
|
|
157
|
-
:
|
|
152
|
+
? extractPropertyFromArray(options, 'data').flat()
|
|
153
|
+
: options
|
|
158
154
|
);
|
|
159
155
|
|
|
160
156
|
if (!prevVal) {
|
|
@@ -184,7 +180,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
184
180
|
(selectedValues: any[]) => {
|
|
185
181
|
//if the list contains disabled values, those values will not be selected
|
|
186
182
|
if (
|
|
187
|
-
removeDisabledItems(modifiedOptions)
|
|
183
|
+
removeDisabledItems(modifiedOptions)?.length === selectedValues?.length
|
|
188
184
|
) {
|
|
189
185
|
setSelectAll(true);
|
|
190
186
|
} else {
|
|
@@ -234,10 +230,10 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
234
230
|
|
|
235
231
|
const regexFilter = new RegExp(searchText, 'i');
|
|
236
232
|
|
|
237
|
-
// Because the options array will be mutated
|
|
233
|
+
// Because the options array will be mutated while searching, we have to search with the original array
|
|
238
234
|
const searchResults = isSectionList
|
|
239
|
-
? searchSectionList(
|
|
240
|
-
: searchFlatList(
|
|
235
|
+
? searchSectionList(options as TSectionList, regexFilter)
|
|
236
|
+
: searchFlatList(options as TFlatList, regexFilter);
|
|
241
237
|
|
|
242
238
|
setNewOptions(searchResults);
|
|
243
239
|
};
|
|
@@ -250,7 +246,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
250
246
|
) {
|
|
251
247
|
return true;
|
|
252
248
|
}
|
|
253
|
-
return;
|
|
249
|
+
return false;
|
|
254
250
|
});
|
|
255
251
|
return searchResults;
|
|
256
252
|
};
|
|
@@ -260,17 +256,17 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
260
256
|
regexFilter: RegExp
|
|
261
257
|
) => {
|
|
262
258
|
const searchResults = sectionList.map((listItem: TSectionListItem) => {
|
|
263
|
-
|
|
259
|
+
const filteredData = listItem.data.filter((item: TFlatListItem) => {
|
|
264
260
|
if (
|
|
265
261
|
item[optLabel].toString().toLowerCase().search(regexFilter) !== -1 ||
|
|
266
262
|
item[optValue].toString().toLowerCase().search(regexFilter) !== -1
|
|
267
263
|
) {
|
|
268
|
-
return
|
|
264
|
+
return true;
|
|
269
265
|
}
|
|
270
|
-
return;
|
|
266
|
+
return false;
|
|
271
267
|
});
|
|
272
268
|
|
|
273
|
-
return listItem;
|
|
269
|
+
return { ...listItem, data: filteredData };
|
|
274
270
|
});
|
|
275
271
|
|
|
276
272
|
return searchResults;
|
|
@@ -300,18 +296,22 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
300
296
|
*==========================================*/
|
|
301
297
|
const setIndexOfSelectedItem = (selectedLabel: string) => {
|
|
302
298
|
isSectionList
|
|
303
|
-
?
|
|
304
|
-
item
|
|
305
|
-
|
|
306
|
-
|
|
299
|
+
? (options as TSectionListItem[] | undefined)?.map(
|
|
300
|
+
(item: TSectionListItem, sectionIndex: number) => {
|
|
301
|
+
item?.data?.find((dataItem: TFlatListItem, itemIndex: number) => {
|
|
302
|
+
if (dataItem[optLabel] === selectedLabel) {
|
|
303
|
+
setListIndex({ sectionIndex, itemIndex });
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
)
|
|
308
|
+
: (options as TFlatListItem[] | undefined)?.find(
|
|
309
|
+
(item: TFlatListItem, itemIndex: number) => {
|
|
310
|
+
if (item[optLabel] === selectedLabel) {
|
|
311
|
+
setListIndex({ itemIndex });
|
|
307
312
|
}
|
|
308
|
-
});
|
|
309
|
-
})
|
|
310
|
-
: optionsCopy?.find((item: TFlatListItem, itemIndex: number) => {
|
|
311
|
-
if (item[optLabel] === selectedLabel) {
|
|
312
|
-
setListIndex({ itemIndex });
|
|
313
313
|
}
|
|
314
|
-
|
|
314
|
+
);
|
|
315
315
|
};
|
|
316
316
|
|
|
317
317
|
return (
|
|
@@ -350,7 +350,6 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
350
350
|
modalProps={modalProps}
|
|
351
351
|
>
|
|
352
352
|
<ListTypeComponent
|
|
353
|
-
removeClippedSubviews={false}
|
|
354
353
|
ListHeaderComponent={
|
|
355
354
|
<>
|
|
356
355
|
{isSearchable && (
|
|
@@ -362,12 +361,14 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
362
361
|
textInputContainerStyle={
|
|
363
362
|
searchControls?.textInputContainerStyle
|
|
364
363
|
}
|
|
365
|
-
|
|
364
|
+
placeholder={
|
|
365
|
+
searchControls?.textInputProps?.placeholder || 'Search'
|
|
366
|
+
}
|
|
366
367
|
{...searchControls?.textInputProps}
|
|
367
368
|
/>
|
|
368
369
|
)}
|
|
369
370
|
{listHeaderComponent}
|
|
370
|
-
{isMultiple && modifiedOptions
|
|
371
|
+
{isMultiple && modifiedOptions?.length > 1 && (
|
|
371
372
|
<View style={styles.optionsContainerStyle}>
|
|
372
373
|
<TouchableOpacity onPress={() => {}}>
|
|
373
374
|
<CheckBox
|
package/src/utils/index.ts
CHANGED