react-native-input-select 1.3.13 → 1.3.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/README.md +49 -48
- package/lib/commonjs/components/CheckBox/index.js +2 -2
- package/lib/commonjs/components/CheckBox/index.js.map +1 -1
- package/lib/commonjs/components/Dropdown/Dropdown.js +4 -1
- package/lib/commonjs/components/Dropdown/Dropdown.js.map +1 -1
- package/lib/commonjs/components/Dropdown/DropdownFlatList.js +2 -1
- package/lib/commonjs/components/Dropdown/DropdownFlatList.js.map +1 -1
- package/lib/commonjs/components/Dropdown/DropdownSectionList.js +2 -1
- package/lib/commonjs/components/Dropdown/DropdownSectionList.js.map +1 -1
- package/lib/commonjs/index.js +23 -21
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/CheckBox/index.js +2 -2
- package/lib/module/components/CheckBox/index.js.map +1 -1
- package/lib/module/components/Dropdown/Dropdown.js +4 -1
- package/lib/module/components/Dropdown/Dropdown.js.map +1 -1
- package/lib/module/components/Dropdown/DropdownFlatList.js +2 -1
- package/lib/module/components/Dropdown/DropdownFlatList.js.map +1 -1
- package/lib/module/components/Dropdown/DropdownSectionList.js +2 -1
- package/lib/module/components/Dropdown/DropdownSectionList.js.map +1 -1
- package/lib/module/index.js +23 -21
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/components/Dropdown/Dropdown.d.ts +1 -1
- package/lib/typescript/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/lib/typescript/src/components/Dropdown/DropdownFlatList.d.ts +3 -1
- package/lib/typescript/src/components/Dropdown/DropdownFlatList.d.ts.map +1 -1
- package/lib/typescript/src/components/Dropdown/DropdownSectionList.d.ts +1 -1
- package/lib/typescript/src/components/Dropdown/DropdownSectionList.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/index.types.d.ts +5 -0
- package/lib/typescript/src/types/index.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/CheckBox/index.tsx +8 -8
- package/src/components/Dropdown/Dropdown.tsx +6 -1
- package/src/components/Dropdown/DropdownFlatList.tsx +11 -6
- package/src/components/Dropdown/DropdownSectionList.tsx +9 -4
- package/src/index.tsx +31 -30
- package/src/types/index.types.ts +5 -0
|
@@ -30,6 +30,7 @@ const DropdownSectionList = ({
|
|
|
30
30
|
listComponentStyles,
|
|
31
31
|
listIndex,
|
|
32
32
|
emptyListMessage,
|
|
33
|
+
listEmptyComponent,
|
|
33
34
|
...rest
|
|
34
35
|
}: any) => {
|
|
35
36
|
const [expandedSections, setExpandedSections] = useState(new Set());
|
|
@@ -84,10 +85,14 @@ const DropdownSectionList = ({
|
|
|
84
85
|
extraData={isMultiple ? selectedItems : selectedItem}
|
|
85
86
|
initialNumToRender={5}
|
|
86
87
|
ListEmptyComponent={
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
listEmptyComponent || (
|
|
89
|
+
<ListEmptyComponent
|
|
90
|
+
listEmptyComponentStyle={
|
|
91
|
+
listComponentStyles?.listEmptyComponentStyle
|
|
92
|
+
}
|
|
93
|
+
emptyListMessage={emptyListMessage}
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
91
96
|
}
|
|
92
97
|
contentContainerStyle={[
|
|
93
98
|
isSearchable ? { paddingTop: 0 } : styles.contentContainerStyle,
|
package/src/index.tsx
CHANGED
|
@@ -18,13 +18,14 @@ import type {
|
|
|
18
18
|
import { escapeRegExp, extractPropertyFromArray } from './utils';
|
|
19
19
|
|
|
20
20
|
export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
21
|
+
testID,
|
|
21
22
|
placeholder,
|
|
22
23
|
label,
|
|
23
24
|
error,
|
|
24
25
|
helperText,
|
|
25
26
|
options,
|
|
26
|
-
optionLabel,
|
|
27
|
-
optionValue,
|
|
27
|
+
optionLabel = DEFAULT_OPTION_LABEL,
|
|
28
|
+
optionValue = DEFAULT_OPTION_VALUE,
|
|
28
29
|
onValueChange,
|
|
29
30
|
selectedValue,
|
|
30
31
|
isMultiple,
|
|
@@ -43,7 +44,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
43
44
|
modalBackgroundStyle, // kept for backwards compatibility
|
|
44
45
|
modalOptionsContainerStyle, // kept for backwards compatibility
|
|
45
46
|
searchInputStyle, // kept for backwards compatibility
|
|
46
|
-
primaryColor,
|
|
47
|
+
primaryColor = colors.gray,
|
|
47
48
|
disabled,
|
|
48
49
|
checkboxSize, // kept for backwards compatibility
|
|
49
50
|
checkboxStyle, // kept for backwards compatibility
|
|
@@ -53,13 +54,14 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
53
54
|
listHeaderComponent,
|
|
54
55
|
listFooterComponent,
|
|
55
56
|
listComponentStyles,
|
|
57
|
+
listEmptyComponent,
|
|
56
58
|
modalProps, // kept for backwards compatibility
|
|
57
59
|
hideModal = false,
|
|
58
60
|
listControls,
|
|
59
61
|
searchControls,
|
|
60
62
|
modalControls,
|
|
61
63
|
checkboxControls,
|
|
62
|
-
autoCloseOnSelect=true,
|
|
64
|
+
autoCloseOnSelect = true,
|
|
63
65
|
...rest
|
|
64
66
|
}) => {
|
|
65
67
|
const [newOptions, setNewOptions] = useState<TFlatList | TSectionList>([]);
|
|
@@ -105,14 +107,11 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
105
107
|
|
|
106
108
|
/**
|
|
107
109
|
* `options` is the original array, it never changes. (Do not use except you really need the original array) .
|
|
108
|
-
* `newOptions` is a copy of options but can be mutated by `setNewOptions`, as a result, the value
|
|
110
|
+
* `newOptions` is a copy of options but can be mutated by `setNewOptions`, as a result, the value may change.
|
|
109
111
|
* `modifiedOptions` should only be used for computations. It has the same structure for both `FlatList` and `SectionList`
|
|
110
112
|
*/
|
|
111
113
|
const modifiedOptions = isSectionList ? modifiedSectionData : newOptions;
|
|
112
114
|
|
|
113
|
-
const optLabel = optionLabel || DEFAULT_OPTION_LABEL;
|
|
114
|
-
const optValue = optionValue || DEFAULT_OPTION_VALUE;
|
|
115
|
-
|
|
116
115
|
/*===========================================
|
|
117
116
|
* Selection handlers
|
|
118
117
|
*==========================================*/
|
|
@@ -124,8 +123,8 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
124
123
|
setSelectedItem(value);
|
|
125
124
|
onValueChange(value); // send value to parent
|
|
126
125
|
|
|
127
|
-
if(autoCloseOnSelect){
|
|
128
|
-
|
|
126
|
+
if (autoCloseOnSelect) {
|
|
127
|
+
setOpen(false); // close modal upon selection
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
130
|
};
|
|
@@ -161,7 +160,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
161
160
|
|
|
162
161
|
if (!prevVal) {
|
|
163
162
|
for (let i = 0; i < filteredOptions.length; i++) {
|
|
164
|
-
selectedValues.push(filteredOptions[i][
|
|
163
|
+
selectedValues.push(filteredOptions[i][optionValue]);
|
|
165
164
|
}
|
|
166
165
|
}
|
|
167
166
|
|
|
@@ -213,17 +212,17 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
213
212
|
|
|
214
213
|
selectedItems?.forEach((element: number | string) => {
|
|
215
214
|
let selectedItemLabel = modifiedOptions?.find(
|
|
216
|
-
(item: TFlatListItem) => item[
|
|
217
|
-
)?.[
|
|
215
|
+
(item: TFlatListItem) => item[optionValue] === element
|
|
216
|
+
)?.[optionLabel];
|
|
218
217
|
selectedLabels.push(selectedItemLabel);
|
|
219
218
|
});
|
|
220
219
|
return selectedLabels;
|
|
221
220
|
}
|
|
222
221
|
|
|
223
222
|
let selectedItemLabel = modifiedOptions?.find(
|
|
224
|
-
(item: TFlatListItem) => item[
|
|
223
|
+
(item: TFlatListItem) => item[optionValue] === selectedItem
|
|
225
224
|
);
|
|
226
|
-
return selectedItemLabel?.[
|
|
225
|
+
return selectedItemLabel?.[optionLabel];
|
|
227
226
|
};
|
|
228
227
|
|
|
229
228
|
/*===========================================
|
|
@@ -231,6 +230,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
231
230
|
*==========================================*/
|
|
232
231
|
const onSearch = (value: string) => {
|
|
233
232
|
setSearchValue(value);
|
|
233
|
+
searchControls?.searchCallback?.(value);
|
|
234
234
|
|
|
235
235
|
let searchText = escapeRegExp(value).toString().toLocaleLowerCase().trim();
|
|
236
236
|
|
|
@@ -247,8 +247,8 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
247
247
|
const searchFlatList = (flatList: TFlatList, regexFilter: RegExp) => {
|
|
248
248
|
const searchResults = flatList.filter((item: TFlatListItem) => {
|
|
249
249
|
if (
|
|
250
|
-
item[
|
|
251
|
-
item[
|
|
250
|
+
item[optionLabel].toString().toLowerCase().search(regexFilter) !== -1 ||
|
|
251
|
+
item[optionValue].toString().toLowerCase().search(regexFilter) !== -1
|
|
252
252
|
) {
|
|
253
253
|
return true;
|
|
254
254
|
}
|
|
@@ -264,8 +264,9 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
264
264
|
const searchResults = sectionList.map((listItem: TSectionListItem) => {
|
|
265
265
|
const filteredData = listItem.data.filter((item: TFlatListItem) => {
|
|
266
266
|
if (
|
|
267
|
-
item[
|
|
268
|
-
|
|
267
|
+
item[optionLabel].toString().toLowerCase().search(regexFilter) !==
|
|
268
|
+
-1 ||
|
|
269
|
+
item[optionValue].toString().toLowerCase().search(regexFilter) !== -1
|
|
269
270
|
) {
|
|
270
271
|
return true;
|
|
271
272
|
}
|
|
@@ -328,8 +329,6 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
328
329
|
return () => {};
|
|
329
330
|
}, [hideModal]);
|
|
330
331
|
|
|
331
|
-
let primary = primaryColor || colors.gray;
|
|
332
|
-
|
|
333
332
|
/*===========================================
|
|
334
333
|
* setIndexOfSelectedItem - For ScrollToIndex
|
|
335
334
|
*==========================================*/
|
|
@@ -338,7 +337,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
338
337
|
? (options as TSectionListItem[] | undefined)?.map(
|
|
339
338
|
(item: TSectionListItem, sectionIndex: number) => {
|
|
340
339
|
item?.data?.find((dataItem: TFlatListItem, itemIndex: number) => {
|
|
341
|
-
if (dataItem[
|
|
340
|
+
if (dataItem[optionLabel] === selectedLabel) {
|
|
342
341
|
setListIndex({ sectionIndex, itemIndex });
|
|
343
342
|
}
|
|
344
343
|
});
|
|
@@ -346,7 +345,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
346
345
|
)
|
|
347
346
|
: (options as TFlatListItem[] | undefined)?.find(
|
|
348
347
|
(item: TFlatListItem, itemIndex: number) => {
|
|
349
|
-
if (item[
|
|
348
|
+
if (item[optionLabel] === selectedLabel) {
|
|
350
349
|
setListIndex({ itemIndex });
|
|
351
350
|
}
|
|
352
351
|
}
|
|
@@ -356,6 +355,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
356
355
|
return (
|
|
357
356
|
<>
|
|
358
357
|
<Dropdown
|
|
358
|
+
testID={testID}
|
|
359
359
|
label={label}
|
|
360
360
|
placeholder={placeholder}
|
|
361
361
|
helperText={helperText}
|
|
@@ -376,7 +376,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
376
376
|
selectedItemStyle={selectedItemStyle}
|
|
377
377
|
multipleSelectedItemStyle={multipleSelectedItemStyle}
|
|
378
378
|
isMultiple={isMultiple}
|
|
379
|
-
primaryColor={
|
|
379
|
+
primaryColor={primaryColor}
|
|
380
380
|
disabled={disabled}
|
|
381
381
|
placeholderStyle={placeholderStyle}
|
|
382
382
|
setIndexOfSelectedItem={setIndexOfSelectedItem}
|
|
@@ -394,11 +394,11 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
394
394
|
ListHeaderComponent={
|
|
395
395
|
<>
|
|
396
396
|
{isSearchable && (
|
|
397
|
-
<Input
|
|
397
|
+
<Input
|
|
398
398
|
value={searchValue}
|
|
399
399
|
onChangeText={(text: string) => onSearch(text)}
|
|
400
400
|
style={searchControls?.textInputStyle || searchInputStyle}
|
|
401
|
-
primaryColor={
|
|
401
|
+
primaryColor={primaryColor}
|
|
402
402
|
textInputContainerStyle={
|
|
403
403
|
searchControls?.textInputContainerStyle
|
|
404
404
|
}
|
|
@@ -422,7 +422,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
422
422
|
: listControls?.selectAllText || 'Select all'
|
|
423
423
|
}
|
|
424
424
|
onChange={() => handleSelectAll()}
|
|
425
|
-
primaryColor={
|
|
425
|
+
primaryColor={primaryColor}
|
|
426
426
|
checkboxControls={checkboxControls}
|
|
427
427
|
checkboxSize={checkboxSize}
|
|
428
428
|
checkboxStyle={checkboxStyle}
|
|
@@ -438,15 +438,15 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
438
438
|
ListFooterComponent={listFooterComponent}
|
|
439
439
|
listComponentStyles={listComponentStyles}
|
|
440
440
|
options={newOptions}
|
|
441
|
-
optionLabel={
|
|
442
|
-
optionValue={
|
|
441
|
+
optionLabel={optionLabel}
|
|
442
|
+
optionValue={optionValue}
|
|
443
443
|
isMultiple={isMultiple}
|
|
444
444
|
isSearchable={isSearchable}
|
|
445
445
|
selectedItems={selectedItems}
|
|
446
446
|
selectedItem={selectedItem}
|
|
447
447
|
handleMultipleSelections={handleMultipleSelections}
|
|
448
448
|
handleSingleSelection={handleSingleSelection}
|
|
449
|
-
primaryColor={
|
|
449
|
+
primaryColor={primaryColor}
|
|
450
450
|
checkboxSize={checkboxSize}
|
|
451
451
|
checkboxStyle={checkboxStyle}
|
|
452
452
|
checkboxLabelStyle={checkboxLabelStyle}
|
|
@@ -454,6 +454,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
|
|
|
454
454
|
checkboxComponent={checkboxComponent}
|
|
455
455
|
checkboxControls={checkboxControls}
|
|
456
456
|
listIndex={listIndex}
|
|
457
|
+
listEmptyComponent={listEmptyComponent}
|
|
457
458
|
emptyListMessage={listControls?.emptyListMessage}
|
|
458
459
|
/>
|
|
459
460
|
</CustomModal>
|
package/src/types/index.types.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type DropdownProps = CommonDropdownProps &
|
|
|
15
15
|
TListControls;
|
|
16
16
|
|
|
17
17
|
export type CommonDropdownProps = {
|
|
18
|
+
testID?: string;
|
|
18
19
|
label?: string;
|
|
19
20
|
options: TFlatList | TSectionList;
|
|
20
21
|
optionLabel?: string;
|
|
@@ -60,6 +61,7 @@ export type TSearchControls = {
|
|
|
60
61
|
textInputStyle?: ViewStyle | TextStyle;
|
|
61
62
|
textInputContainerStyle?: ViewStyle;
|
|
62
63
|
textInputProps?: TextInputProps;
|
|
64
|
+
searchCallback?: (value: string) => void;
|
|
63
65
|
};
|
|
64
66
|
};
|
|
65
67
|
export type TCheckboxControls = {
|
|
@@ -82,6 +84,8 @@ export type TCheckboxControls = {
|
|
|
82
84
|
checkboxStyle?: ViewStyle;
|
|
83
85
|
checkboxLabelStyle?: TextStyle;
|
|
84
86
|
checkboxComponent?: React.ReactNode;
|
|
87
|
+
checkboxDisabledStyle?: ViewStyle;
|
|
88
|
+
checkboxUnselectedColor?: ColorValue;
|
|
85
89
|
};
|
|
86
90
|
};
|
|
87
91
|
|
|
@@ -109,6 +113,7 @@ export type TListControls = {
|
|
|
109
113
|
itemSeparatorStyle?: ViewStyle;
|
|
110
114
|
sectionHeaderStyle?: TextStyle;
|
|
111
115
|
};
|
|
116
|
+
listEmptyComponent?: React.ReactNode;
|
|
112
117
|
listControls?: {
|
|
113
118
|
selectAllText?: string;
|
|
114
119
|
unselectAllText?: string;
|