react-native-input-select 2.0.0 → 2.1.1

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.
Files changed (75) hide show
  1. package/README.md +16 -59
  2. package/lib/commonjs/components/CheckBox/index.js +16 -12
  3. package/lib/commonjs/components/CheckBox/index.js.map +1 -1
  4. package/lib/commonjs/components/CustomModal/index.js +3 -9
  5. package/lib/commonjs/components/CustomModal/index.js.map +1 -1
  6. package/lib/commonjs/components/Dropdown/DropdownListItem.js +1 -10
  7. package/lib/commonjs/components/Dropdown/DropdownListItem.js.map +1 -1
  8. package/lib/commonjs/components/Dropdown/DropdownSelectedItemsView.js +1 -1
  9. package/lib/commonjs/components/Dropdown/DropdownSelectedItemsView.js.map +1 -1
  10. package/lib/commonjs/components/List/DropdownFlatList.js +0 -23
  11. package/lib/commonjs/components/List/DropdownFlatList.js.map +1 -1
  12. package/lib/commonjs/components/List/DropdownSectionList.js +0 -20
  13. package/lib/commonjs/components/List/DropdownSectionList.js.map +1 -1
  14. package/lib/commonjs/hooks/use-modal.js +0 -3
  15. package/lib/commonjs/hooks/use-modal.js.map +1 -1
  16. package/lib/commonjs/hooks/use-search.js +8 -3
  17. package/lib/commonjs/hooks/use-search.js.map +1 -1
  18. package/lib/commonjs/index.js +4 -38
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/utils/index.js +1 -1
  21. package/lib/commonjs/utils/index.js.map +1 -1
  22. package/lib/module/components/CheckBox/index.js +16 -12
  23. package/lib/module/components/CheckBox/index.js.map +1 -1
  24. package/lib/module/components/CustomModal/index.js +3 -9
  25. package/lib/module/components/CustomModal/index.js.map +1 -1
  26. package/lib/module/components/Dropdown/DropdownListItem.js +1 -10
  27. package/lib/module/components/Dropdown/DropdownListItem.js.map +1 -1
  28. package/lib/module/components/Dropdown/DropdownSelectedItemsView.js +1 -1
  29. package/lib/module/components/Dropdown/DropdownSelectedItemsView.js.map +1 -1
  30. package/lib/module/components/List/DropdownFlatList.js +0 -23
  31. package/lib/module/components/List/DropdownFlatList.js.map +1 -1
  32. package/lib/module/components/List/DropdownSectionList.js +0 -20
  33. package/lib/module/components/List/DropdownSectionList.js.map +1 -1
  34. package/lib/module/hooks/use-modal.js +0 -3
  35. package/lib/module/hooks/use-modal.js.map +1 -1
  36. package/lib/module/hooks/use-search.js +8 -3
  37. package/lib/module/hooks/use-search.js.map +1 -1
  38. package/lib/module/index.js +4 -38
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/utils/index.js +1 -1
  41. package/lib/module/utils/index.js.map +1 -1
  42. package/lib/typescript/src/components/CheckBox/checkbox.types.d.ts +2 -2
  43. package/lib/typescript/src/components/CheckBox/checkbox.types.d.ts.map +1 -1
  44. package/lib/typescript/src/components/CheckBox/index.d.ts +1 -1
  45. package/lib/typescript/src/components/CheckBox/index.d.ts.map +1 -1
  46. package/lib/typescript/src/components/CustomModal/index.d.ts +2 -2
  47. package/lib/typescript/src/components/CustomModal/index.d.ts.map +1 -1
  48. package/lib/typescript/src/components/Dropdown/DropdownListItem.d.ts +1 -1
  49. package/lib/typescript/src/components/Dropdown/DropdownListItem.d.ts.map +1 -1
  50. package/lib/typescript/src/components/List/DropdownFlatList.d.ts +1 -1
  51. package/lib/typescript/src/components/List/DropdownFlatList.d.ts.map +1 -1
  52. package/lib/typescript/src/components/List/DropdownSectionList.d.ts +1 -1
  53. package/lib/typescript/src/components/List/DropdownSectionList.d.ts.map +1 -1
  54. package/lib/typescript/src/hooks/use-modal.d.ts +1 -3
  55. package/lib/typescript/src/hooks/use-modal.d.ts.map +1 -1
  56. package/lib/typescript/src/hooks/use-search.d.ts.map +1 -1
  57. package/lib/typescript/src/index.d.ts +2 -2
  58. package/lib/typescript/src/index.d.ts.map +1 -1
  59. package/lib/typescript/src/types/index.types.d.ts +3 -39
  60. package/lib/typescript/src/types/index.types.d.ts.map +1 -1
  61. package/lib/typescript/src/utils/index.d.ts +1 -1
  62. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  63. package/package.json +13 -6
  64. package/src/components/CheckBox/checkbox.types.ts +2 -2
  65. package/src/components/CheckBox/index.tsx +20 -46
  66. package/src/components/CustomModal/index.tsx +4 -9
  67. package/src/components/Dropdown/DropdownListItem.tsx +0 -11
  68. package/src/components/Dropdown/DropdownSelectedItemsView.tsx +1 -1
  69. package/src/components/List/DropdownFlatList.tsx +0 -15
  70. package/src/components/List/DropdownSectionList.tsx +0 -15
  71. package/src/hooks/use-modal.ts +1 -5
  72. package/src/hooks/use-search.ts +10 -4
  73. package/src/index.tsx +3 -26
  74. package/src/types/index.types.ts +4 -46
  75. package/src/utils/index.ts +1 -1
@@ -11,7 +11,7 @@ import {
11
11
  TouchableWithoutFeedback,
12
12
  } from 'react-native';
13
13
  import { colors } from '../../styles/colors';
14
- import { TCustomModalControls, TCustomModalProps } from 'src/types/index.types';
14
+ import { TCustomModalControls } from 'src/types/index.types';
15
15
 
16
16
  // In iOS, `SafeAreaView` does not automatically account on keyboard.
17
17
  // Therefore, for iOS we need to wrap the content in `KeyboardAvoidingView`.
@@ -27,13 +27,10 @@ const ModalContentWrapper = ({ children }: PropsWithChildren): ReactElement => {
27
27
 
28
28
  const CustomModal = ({
29
29
  visible,
30
- modalBackgroundStyle, //kept for backwards compatibility
31
- modalOptionsContainerStyle, //kept for backwards compatibility
32
30
  modalControls,
33
- modalProps, //kept for backwards compatibility
34
31
  children,
35
32
  onRequestClose,
36
- }: TCustomModalProps & {
33
+ }: {
37
34
  modalControls?: TCustomModalControls;
38
35
  } & ModalProps) => {
39
36
  return (
@@ -43,7 +40,6 @@ const CustomModal = ({
43
40
  transparent={true}
44
41
  animationType="fade"
45
42
  {...modalControls?.modalProps}
46
- {...modalProps} //kept for backwards compatibility
47
43
  >
48
44
  {/*Used to fix the select with search box behavior in iOS*/}
49
45
  <ModalContentWrapper>
@@ -52,7 +48,7 @@ const CustomModal = ({
52
48
  style={[
53
49
  styles.modalContainer,
54
50
  styles.modalBackgroundStyle,
55
- modalControls?.modalBackgroundStyle || modalBackgroundStyle,
51
+ modalControls?.modalBackgroundStyle,
56
52
  ]}
57
53
  aria-label="close modal"
58
54
  >
@@ -61,8 +57,7 @@ const CustomModal = ({
61
57
  <SafeAreaView
62
58
  style={[
63
59
  styles.modalOptionsContainer,
64
- modalControls?.modalOptionsContainerStyle ||
65
- modalOptionsContainerStyle,
60
+ modalControls?.modalOptionsContainerStyle,
66
61
  ]}
67
62
  testID="react-native-input-select-modal-body"
68
63
  >
@@ -10,11 +10,6 @@ const DropdownListItem = ({
10
10
  selectedOption,
11
11
  onChange,
12
12
  primaryColor,
13
- checkboxSize,
14
- checkboxStyle,
15
- checkboxLabelStyle,
16
- checkboxComponentStyles,
17
- checkboxComponent,
18
13
  checkboxControls,
19
14
  }: any) => {
20
15
  return (
@@ -32,13 +27,7 @@ const DropdownListItem = ({
32
27
  onChange={() => onChange(item[optionValue])}
33
28
  primaryColor={primaryColor}
34
29
  checkboxControls={checkboxControls}
35
- checkboxSize={checkboxComponentStyles?.checkboxSize || checkboxSize}
36
- checkboxStyle={checkboxComponentStyles?.checkboxStyle || checkboxStyle}
37
- checkboxLabelStyle={
38
- checkboxComponentStyles?.checkboxLabelStyle || checkboxLabelStyle
39
- }
40
30
  disabled={item.disabled}
41
- checkboxComponent={checkboxComponent}
42
31
  />
43
32
  </TouchableOpacity>
44
33
  );
@@ -85,7 +85,7 @@ const DropdownSelectedItemsView = ({
85
85
  disabled={disabled}
86
86
  />
87
87
  )}
88
- {!selectedItem && selectedItems?.length === 0 && (
88
+ {selectedItem === '' && selectedItems?.length === 0 && (
89
89
  <DropdownContent
90
90
  onPress={() => openModal()}
91
91
  style={[styles.blackText, placeholderStyle]}
@@ -16,11 +16,6 @@ const DropdownFlatList = ({
16
16
  handleMultipleSelections,
17
17
  handleSingleSelection,
18
18
  primaryColor,
19
- checkboxSize, // kept for backwards compatibility to be removed in future release
20
- checkboxStyle, // kept for backwards compatibility to be removed in future release
21
- checkboxLabelStyle, // kept for backwards compatibility to be removed in future release
22
- checkboxComponentStyles,
23
- checkboxComponent,
24
19
  checkboxControls,
25
20
  listComponentStyles,
26
21
  listIndex,
@@ -80,11 +75,6 @@ const DropdownFlatList = ({
80
75
  : handleSingleSelection,
81
76
  scrollToItem,
82
77
  primaryColor,
83
- checkboxSize, // kept for backwards compatibility
84
- checkboxStyle, // kept for backwards compatibility
85
- checkboxLabelStyle, // kept for backwards compatibility
86
- checkboxComponentStyles, // kept for backwards compatibility
87
- checkboxComponent, // kept for backwards compatibility
88
78
  checkboxControls,
89
79
  })
90
80
  }
@@ -110,12 +100,7 @@ const _renderItem = ({ item }: any, props: any) => {
110
100
  selectedOption={props.selectedOption}
111
101
  onChange={props.onChange}
112
102
  primaryColor={props.primaryColor}
113
- checkboxSize={props.checkboxSize}
114
- checkboxStyle={props.checkboxStyle}
115
- checkboxLabelStyle={props.checkboxLabelStyle}
116
103
  scrollToItem={props.scrollToItem}
117
- checkboxComponentStyles={props.checkboxComponentStyles}
118
- checkboxComponent={props.checkboxComponent}
119
104
  checkboxControls={props.checkboxControls}
120
105
  />
121
106
  );
@@ -21,11 +21,6 @@ const DropdownSectionList = ({
21
21
  handleMultipleSelections,
22
22
  handleSingleSelection,
23
23
  primaryColor,
24
- checkboxSize,
25
- checkboxStyle,
26
- checkboxLabelStyle,
27
- checkboxComponentStyles,
28
- checkboxComponent,
29
24
  checkboxControls,
30
25
  listComponentStyles,
31
26
  listIndex,
@@ -115,11 +110,6 @@ const DropdownSectionList = ({
115
110
  ? handleMultipleSelections
116
111
  : handleSingleSelection,
117
112
  primaryColor,
118
- checkboxSize, // kept for backwards compatibility
119
- checkboxStyle, // kept for backwards compatibility
120
- checkboxLabelStyle, // kept for backwards compatibility
121
- checkboxComponentStyles, // kept for backwards compatibility
122
- checkboxComponent, // kept for backwards compatibility
123
113
  checkboxControls,
124
114
  expandedSections,
125
115
  })
@@ -160,11 +150,6 @@ const _renderItem = ({ section: { title }, item }: any, props: any) => {
160
150
  selectedOption={props.selectedOption}
161
151
  onChange={props.onChange}
162
152
  primaryColor={props.primaryColor}
163
- checkboxSize={props.checkboxSize}
164
- checkboxStyle={props.checkboxStyle}
165
- checkboxLabelStyle={props.checkboxLabelStyle}
166
- checkboxComponentStyles={props.checkboxComponentStyles}
167
- checkboxComponent={props.checkboxComponent}
168
153
  checkboxControls={props.checkboxControls}
169
154
  />
170
155
  );
@@ -1,18 +1,16 @@
1
1
  import { useState } from 'react';
2
- import { ModalProps, Platform } from 'react-native';
2
+ import { Platform } from 'react-native';
3
3
  import { TCustomModalControls } from '../types/index.types';
4
4
 
5
5
  interface UseModalProps {
6
6
  resetOptionsRelatedState: () => void;
7
7
  disabled?: boolean;
8
- modalProps?: ModalProps;
9
8
  modalControls?: TCustomModalControls;
10
9
  }
11
10
 
12
11
  export const useModal = ({
13
12
  resetOptionsRelatedState,
14
13
  disabled,
15
- modalProps,
16
14
  modalControls,
17
15
  }: UseModalProps) => {
18
16
  const [isVisible, setIsVisible] = useState(false);
@@ -30,8 +28,6 @@ export const useModal = ({
30
28
  // iOS supports the onDismiss prop but android does not, so we do this explicitly here
31
29
  // https://reactnative.dev/docs/modal#ondismiss-ios
32
30
  if (Platform.OS === 'android') {
33
- modalControls?.modalProps?.closeModal?.(); //kept for backwards compatibility
34
- modalProps?.onDismiss?.(); //kept for backwards compatibility
35
31
  modalControls?.modalProps?.onDismiss?.();
36
32
  }
37
33
  };
@@ -25,8 +25,12 @@ export const useSearch = ({
25
25
  TFlatList | TSectionList
26
26
  >(initialOptions);
27
27
 
28
+ const resetOptionsToDefault = (options: TFlatList | TSectionList) => {
29
+ setFilteredOptions(options);
30
+ };
31
+
28
32
  useEffect(() => {
29
- setFilteredOptions(initialOptions);
33
+ resetOptionsToDefault(initialOptions);
30
34
  return () => {};
31
35
  }, [initialOptions]);
32
36
 
@@ -34,9 +38,9 @@ export const useSearch = ({
34
38
  (flatList: TFlatList, regexFilter: RegExp) => {
35
39
  return flatList.filter((item: TFlatListItem) => {
36
40
  return (
37
- item[optionLabel].toString().toLowerCase().search(regexFilter) !==
41
+ item[optionLabel]?.toString().toLowerCase().search(regexFilter) !==
38
42
  -1 ||
39
- item[optionValue].toString().toLowerCase().search(regexFilter) !== -1
43
+ item[optionValue]?.toString().toLowerCase().search(regexFilter) !== -1
40
44
  );
41
45
  });
42
46
  },
@@ -82,8 +86,10 @@ export const useSearch = ({
82
86
  useEffect(() => {
83
87
  if (searchValue) {
84
88
  onSearch(searchValue);
89
+ } else {
90
+ resetOptionsToDefault(initialOptions);
85
91
  }
86
- }, [onSearch, searchValue]);
92
+ }, [initialOptions, onSearch, searchValue]);
87
93
 
88
94
  return {
89
95
  searchValue,
package/src/index.tsx CHANGED
@@ -53,21 +53,12 @@ export const DropdownSelect = forwardRef<DropdownSelectHandle, DropdownProps>(
53
53
  dropdownHelperTextStyle,
54
54
  selectedItemStyle,
55
55
  multipleSelectedItemStyle,
56
- modalBackgroundStyle, // kept for backwards compatibility
57
- modalOptionsContainerStyle, // kept for backwards compatibility
58
- searchInputStyle, // kept for backwards compatibility
59
56
  primaryColor = colors.gray,
60
57
  disabled = false,
61
- checkboxSize, // kept for backwards compatibility
62
- checkboxStyle, // kept for backwards compatibility
63
- checkboxLabelStyle, // kept for backwards compatibility
64
- checkboxComponentStyles, // kept for backwards compatibility
65
- checkboxComponent, // kept for backwards compatibility
66
58
  listHeaderComponent,
67
59
  listFooterComponent,
68
60
  listComponentStyles,
69
61
  listEmptyComponent,
70
- modalProps, // kept for backwards compatibility
71
62
  listControls,
72
63
  searchControls,
73
64
  modalControls,
@@ -131,7 +122,6 @@ export const DropdownSelect = forwardRef<DropdownSelectHandle, DropdownProps>(
131
122
  const { isVisible, openModal, closeModal } = useModal({
132
123
  resetOptionsRelatedState,
133
124
  disabled,
134
- modalProps,
135
125
  modalControls,
136
126
  });
137
127
 
@@ -156,8 +146,8 @@ export const DropdownSelect = forwardRef<DropdownSelectHandle, DropdownProps>(
156
146
 
157
147
  useEffect(() => {
158
148
  isMultiple
159
- ? setSelectedItems(Array.isArray(selectedValue) ? selectedValue : [])
160
- : setSelectedItem((selectedValue as TSelectedItem) || '');
149
+ ? setSelectedItems(selectedValue as TSelectedItem[])
150
+ : setSelectedItem(selectedValue as TSelectedItem);
161
151
 
162
152
  return () => {};
163
153
  }, [
@@ -240,10 +230,7 @@ export const DropdownSelect = forwardRef<DropdownSelectHandle, DropdownProps>(
240
230
  <CustomModal
241
231
  visible={isVisible}
242
232
  onRequestClose={() => closeModal()}
243
- modalBackgroundStyle={modalBackgroundStyle} // kept for backwards compatibility
244
- modalOptionsContainerStyle={modalOptionsContainerStyle} // kept for backwards compatibility
245
233
  modalControls={modalControls}
246
- modalProps={modalProps} // kept for backwards compatibility
247
234
  >
248
235
  <ListTypeComponent
249
236
  ListHeaderComponent={
@@ -252,7 +239,7 @@ export const DropdownSelect = forwardRef<DropdownSelectHandle, DropdownProps>(
252
239
  <Input
253
240
  value={searchValue}
254
241
  onChangeText={(text: string) => setSearchValue(text)}
255
- style={searchControls?.textInputStyle || searchInputStyle}
242
+ style={searchControls?.textInputStyle}
256
243
  primaryColor={primaryColor}
257
244
  textInputContainerStyle={
258
245
  searchControls?.textInputContainerStyle
@@ -282,11 +269,6 @@ export const DropdownSelect = forwardRef<DropdownSelectHandle, DropdownProps>(
282
269
  onChange={() => handleSelectAll()}
283
270
  primaryColor={primaryColor}
284
271
  checkboxControls={checkboxControls}
285
- checkboxSize={checkboxSize}
286
- checkboxStyle={checkboxStyle}
287
- checkboxLabelStyle={checkboxLabelStyle}
288
- checkboxComponentStyles={checkboxComponentStyles}
289
- checkboxComponent={checkboxComponent}
290
272
  />
291
273
  </TouchableOpacity>
292
274
  </View>
@@ -305,11 +287,6 @@ export const DropdownSelect = forwardRef<DropdownSelectHandle, DropdownProps>(
305
287
  handleMultipleSelections={handleMultipleSelections}
306
288
  handleSingleSelection={handleSingleSelection}
307
289
  primaryColor={primaryColor}
308
- checkboxSize={checkboxSize}
309
- checkboxStyle={checkboxStyle}
310
- checkboxLabelStyle={checkboxLabelStyle}
311
- checkboxComponentStyles={checkboxComponentStyles}
312
- checkboxComponent={checkboxComponent}
313
290
  checkboxControls={checkboxControls}
314
291
  listIndex={listIndex}
315
292
  listEmptyComponent={listEmptyComponent}
@@ -9,11 +9,8 @@ import type {
9
9
 
10
10
  export type DropdownProps = CommonDropdownProps &
11
11
  TDropdownInputProps &
12
- TSearchProps &
13
- TCheckboxProps &
14
- TCustomModalProps &
15
- TListProps &
16
- TControls;
12
+ TControls &
13
+ TListProps;
17
14
 
18
15
  export type CommonDropdownProps = {
19
16
  testID?: string;
@@ -46,8 +43,6 @@ export type TDropdownInputProps = {
46
43
  primaryColor?: ColorValue;
47
44
  disabled?: boolean;
48
45
  placeholderStyle?: TextStyle;
49
- /** @deprecated Use useRef to access the open and close props.*/
50
- hideModal?: boolean;
51
46
  };
52
47
 
53
48
  type TControls = {
@@ -57,11 +52,6 @@ type TControls = {
57
52
  listControls?: TListControls;
58
53
  };
59
54
 
60
- export type TSearchProps = {
61
- /** @deprecated Use `searchControls = {{textInputStyle: ViewStyle | TextStyle }}` instead.*/
62
- searchInputStyle?: ViewStyle;
63
- };
64
-
65
55
  type TSearchControls = {
66
56
  textInputStyle?: ViewStyle | TextStyle;
67
57
  textInputContainerStyle?: ViewStyle;
@@ -69,23 +59,6 @@ type TSearchControls = {
69
59
  searchCallback?: (value: string) => void;
70
60
  };
71
61
 
72
- export type TCheckboxProps = {
73
- /** @deprecated Use `checkboxControls = {{checkboxSize: number }}` instead.*/
74
- checkboxSize?: number;
75
- /** @deprecated Use `checkboxControls = {{checkboxStyle: ViewStyle }}` instead.*/
76
- checkboxStyle?: ViewStyle;
77
- /** @deprecated Use `checkboxControls = {{checkboxLabelStyle: TextStyle }}` instead.*/
78
- checkboxLabelStyle?: TextStyle;
79
- /** @deprecated Use `checkboxControls` instead.*/
80
- checkboxComponentStyles?: {
81
- checkboxSize?: number;
82
- checkboxStyle?: ViewStyle;
83
- checkboxLabelStyle?: TextStyle;
84
- };
85
- /** @deprecated Use `checkboxControls = {{checkboxComponent: <View></View> }}` instead.*/
86
- checkboxComponent?: React.ReactNode;
87
- };
88
-
89
62
  export type TCheckboxControls = {
90
63
  checkboxSize?: number;
91
64
  checkboxStyle?: ViewStyle;
@@ -95,25 +68,10 @@ export type TCheckboxControls = {
95
68
  checkboxUnselectedColor?: ColorValue;
96
69
  };
97
70
 
98
- export type TCustomModalProps = {
99
- /** @deprecated Use `modalControls = {{modalBackgroundStyle: ViewStyle}} instead.*/
100
- modalBackgroundStyle?: ViewStyle;
101
- /** @deprecated Use `modalControls = {{ modalOptionsContainerStyle: ViewStyle}} instead.*/
102
- modalOptionsContainerStyle?: ViewStyle;
103
- /** @deprecated Use `modalControls = {{modalProps: ModalProps }}` instead.*/
104
- modalProps?: ModalProps & {
105
- /** @deprecated Use `onDismiss` instead.*/
106
- closeModal?: () => void;
107
- };
108
- };
109
-
110
71
  export type TCustomModalControls = {
111
72
  modalBackgroundStyle?: ViewStyle;
112
73
  modalOptionsContainerStyle?: ViewStyle;
113
- modalProps?: ModalProps & {
114
- /** @deprecated Use `onDismiss` instead.*/
115
- closeModal?: () => void;
116
- };
74
+ modalProps?: ModalProps;
117
75
  };
118
76
 
119
77
  export type TListProps = {
@@ -136,7 +94,7 @@ type TListControls = {
136
94
  emptyListMessage?: string;
137
95
  };
138
96
 
139
- export type TSelectedItem = string | number | boolean;
97
+ export type TSelectedItem = string | number | boolean | undefined;
140
98
  export type TSelectedItemWithReactComponent =
141
99
  | TSelectedItem
142
100
  | React.ReactElement;
@@ -55,7 +55,7 @@ export const getLabelsOfSelectedItems = ({
55
55
  (item: TFlatListItem) => item[optionValue] === element
56
56
  )?.[optionLabel];
57
57
 
58
- if (selectedItemLabel) {
58
+ if (selectedItemLabel !== '') {
59
59
  selectedLabels.push(selectedItemLabel);
60
60
  }
61
61
  });