react-native-input-select 0.4.0 → 0.5.0

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 (49) hide show
  1. package/README.md +30 -22
  2. package/lib/commonjs/Dropdown.js +10 -22
  3. package/lib/commonjs/Dropdown.js.map +1 -1
  4. package/lib/commonjs/DropdownList.js +15 -10
  5. package/lib/commonjs/DropdownList.js.map +1 -1
  6. package/lib/commonjs/DropdownListItem.js +5 -4
  7. package/lib/commonjs/DropdownListItem.js.map +1 -1
  8. package/lib/commonjs/Input.js +50 -0
  9. package/lib/commonjs/Input.js.map +1 -0
  10. package/lib/commonjs/constants/index.js +11 -0
  11. package/lib/commonjs/constants/index.js.map +1 -0
  12. package/lib/commonjs/index.js +36 -8
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/styles/colors.js +1 -0
  15. package/lib/commonjs/styles/colors.js.map +1 -1
  16. package/lib/commonjs/styles/input.js +33 -0
  17. package/lib/commonjs/styles/input.js.map +1 -0
  18. package/lib/module/Dropdown.js +9 -22
  19. package/lib/module/Dropdown.js.map +1 -1
  20. package/lib/module/DropdownList.js +16 -11
  21. package/lib/module/DropdownList.js.map +1 -1
  22. package/lib/module/DropdownListItem.js +5 -4
  23. package/lib/module/DropdownListItem.js.map +1 -1
  24. package/lib/module/Input.js +33 -0
  25. package/lib/module/Input.js.map +1 -0
  26. package/lib/module/constants/index.js +3 -0
  27. package/lib/module/constants/index.js.map +1 -0
  28. package/lib/module/index.js +34 -8
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/styles/colors.js +1 -0
  31. package/lib/module/styles/colors.js.map +1 -1
  32. package/lib/module/styles/input.js +22 -0
  33. package/lib/module/styles/input.js.map +1 -0
  34. package/lib/typescript/Dropdown.d.ts +1 -1
  35. package/lib/typescript/DropdownList.d.ts +1 -1
  36. package/lib/typescript/DropdownListItem.d.ts +1 -1
  37. package/lib/typescript/Input.d.ts +1 -0
  38. package/lib/typescript/constants/index.d.ts +2 -0
  39. package/lib/typescript/index.d.ts +1 -1
  40. package/lib/typescript/styles/input.d.ts +1 -0
  41. package/package.json +8 -3
  42. package/src/Dropdown.tsx +11 -22
  43. package/src/DropdownList.tsx +10 -7
  44. package/src/DropdownListItem.tsx +4 -3
  45. package/src/Input.tsx +37 -0
  46. package/src/constants/index.ts +2 -0
  47. package/src/index.tsx +44 -4
  48. package/src/styles/colors.ts +1 -0
  49. package/src/styles/input.ts +22 -0
package/src/Dropdown.tsx CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  Image,
9
9
  } from 'react-native';
10
10
  import { colors } from './styles/colors';
11
+ import { inputStyles } from './styles/input';
11
12
  import { typography } from './styles/typography';
12
13
 
13
14
  const Dropdown = ({
@@ -25,6 +26,7 @@ const Dropdown = ({
25
26
  dropdownStyle,
26
27
  dropdownContainerStyle,
27
28
  selectedItemStyle,
29
+ primaryColor,
28
30
  }: any) => {
29
31
  return (
30
32
  <View style={[styles.dropdownInputContainer, dropdownContainerStyle]}>
@@ -34,8 +36,8 @@ const Dropdown = ({
34
36
  <Pressable
35
37
  onPress={() => setOpen(!open)}
36
38
  style={({ pressed }) => [
37
- pressed && styles.inputFocusState,
38
- styles.input,
39
+ pressed && inputStyles.inputFocusState,
40
+ inputStyles.input,
39
41
  dropdownStyle,
40
42
  ]}
41
43
  >
@@ -52,7 +54,11 @@ const Dropdown = ({
52
54
  getSelectedItemsLabel().map((item: any, i: Number) => (
53
55
  <Text
54
56
  key={`SelectedItems${i}`}
55
- style={[styles.selectedItems, selectedItemStyle]}
57
+ style={[
58
+ styles.selectedItems,
59
+ { backgroundColor: primaryColor },
60
+ selectedItemStyle,
61
+ ]}
56
62
  >
57
63
  {item}
58
64
  </Text>
@@ -84,30 +90,13 @@ const Dropdown = ({
84
90
 
85
91
  const styles = StyleSheet.create({
86
92
  label: { marginBottom: 16, color: colors.gray, ...typography.caption },
87
- input: {
88
- paddingVertical: 18,
89
- paddingHorizontal: 23,
90
- backgroundColor: colors.lightGray,
91
- borderRadius: 8,
92
- borderColor: colors.dark,
93
- borderWidth: 1,
94
- color: colors.dark,
95
- width: '100%',
96
- minHeight: 64,
97
- },
98
- inputFocusState: {
99
- borderWidth: 2,
100
- borderStyle: 'solid',
101
- borderColor: colors.primary,
102
- borderRadius: 8,
103
- },
104
93
  inputFocusErrorState: {
105
94
  borderWidth: 2,
106
95
  borderStyle: 'solid',
107
- borderColor: colors.cliqkiRed,
96
+ borderColor: colors.red,
108
97
  },
109
98
  iconStyle: { position: 'absolute', right: 25, top: 25 },
110
- error: { color: colors.cliqkiRed, marginTop: 8, ...typography.caption },
99
+ error: { color: colors.red, marginTop: 8, ...typography.caption },
111
100
  helper: { marginTop: 8, color: colors.primary, ...typography.caption },
112
101
  dropdownInputContainer: { marginBottom: 23, width: '100%' },
113
102
  selectedItemsContainer: { flexDirection: 'row', flexWrap: 'nowrap' },
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { View, FlatList, StyleSheet } from 'react-native';
2
+ import { View, FlatList, StyleSheet, Text } from 'react-native';
3
3
  import DropdownListItem from './DropdownListItem';
4
4
  import { colors } from './styles/colors';
5
5
 
@@ -12,18 +12,18 @@ const DropdownList = ({
12
12
  selectedItem,
13
13
  handleMultipleSelections,
14
14
  handleSingleSelection,
15
+ primaryColor,
15
16
  }: any) => {
16
17
  return (
17
18
  <FlatList
18
19
  data={options}
19
20
  extraData={isMultiple ? selectedItems : selectedItem}
20
21
  initialNumToRender={5}
21
- // ListEmptyComponent={
22
- // <EmptyStateComponent
23
- // style={{alignItems: 'flex-start', marginTop: 30}}
24
- // message="Be the first to reply"
25
- // />
26
- // }
22
+ ListEmptyComponent={
23
+ <View style={styles.emptyListStyle}>
24
+ <Text>No options available</Text>
25
+ </View>
26
+ }
27
27
  ItemSeparatorComponent={() => <View style={styles.itemSeparatorStyle} />}
28
28
  renderItem={(item) =>
29
29
  _renderItem(item, {
@@ -34,6 +34,7 @@ const DropdownList = ({
34
34
  onChange: isMultiple
35
35
  ? handleMultipleSelections
36
36
  : handleSingleSelection,
37
+ primaryColor,
37
38
  })
38
39
  }
39
40
  keyExtractor={(_item, index) => `Options${index}`}
@@ -50,6 +51,7 @@ const _renderItem = ({ item }: any, props: any) => {
50
51
  isMultiple={props.isMultiple}
51
52
  selectedOption={props.selectedOption}
52
53
  onChange={props.onChange}
54
+ primaryColor={props.primaryColor}
53
55
  />
54
56
  );
55
57
  };
@@ -71,6 +73,7 @@ const styles = StyleSheet.create({
71
73
  height: 1,
72
74
  opacity: 0.15,
73
75
  },
76
+ emptyListStyle: { alignItems: 'center', width: '100%', marginVertical: 20 },
74
77
  });
75
78
 
76
79
  export default DropdownList;
@@ -10,6 +10,7 @@ const DropdownListItem = ({
10
10
  isMultiple,
11
11
  selectedOption,
12
12
  onChange,
13
+ primaryColor,
13
14
  }: any) => {
14
15
  const selectedOptionValue = optionValue ?? 'value';
15
16
  return (
@@ -26,9 +27,9 @@ const DropdownListItem = ({
26
27
  }
27
28
  onChange={() => onChange(item[selectedOptionValue])}
28
29
  boxType="circle" //works on ios only
29
- tintColors={{ true: colors.primary }} //android control
30
- onCheckColor={colors.primary} //ios checkmark colour control
31
- onTintColor={colors.primary} //ios box colour control
30
+ tintColors={{ true: primaryColor || colors.primary }} //android control
31
+ onCheckColor={primaryColor || colors.primary} //ios checkmark colour control
32
+ onTintColor={primaryColor || colors.primary} //ios box colour control
32
33
  />
33
34
  </View>
34
35
  <View>
package/src/Input.tsx ADDED
@@ -0,0 +1,37 @@
1
+ import React, { useState } from 'react';
2
+ import { TextInput, StyleSheet, View } from 'react-native';
3
+ import { inputStyles } from './styles/input';
4
+
5
+ export const Input = ({
6
+ placeholder,
7
+ value,
8
+ onChangeText,
9
+ style,
10
+ ...rest
11
+ }: any) => {
12
+ const [isFocused, setFocus] = useState(false);
13
+
14
+ return (
15
+ <View style={styles.container}>
16
+ <TextInput
17
+ placeholder={placeholder}
18
+ style={[
19
+ inputStyles.input,
20
+ isFocused && inputStyles.inputFocusState,
21
+ style,
22
+ ]}
23
+ onFocus={() => {
24
+ setFocus(true);
25
+ }}
26
+ onBlur={() => setFocus(false)}
27
+ value={value}
28
+ onChangeText={onChangeText}
29
+ {...rest}
30
+ />
31
+ </View>
32
+ );
33
+ };
34
+
35
+ const styles = StyleSheet.create({
36
+ container: { margin: 23 },
37
+ });
@@ -0,0 +1,2 @@
1
+ export const DEFAULT_OPTION_LABEL = 'label';
2
+ export const DEFAULT_OPTION_VALUE = 'value';
package/src/index.tsx CHANGED
@@ -2,6 +2,8 @@ import React, { useState } from 'react';
2
2
  import Dropdown from './Dropdown';
3
3
  import CustomModal from './Modal';
4
4
  import DropdownList from './DropdownList';
5
+ import { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';
6
+ import { Input } from './Input';
5
7
 
6
8
  export const DropdownSelect = ({
7
9
  placeholder,
@@ -14,13 +16,17 @@ export const DropdownSelect = ({
14
16
  onValueChange,
15
17
  selectedValue,
16
18
  isMultiple,
19
+ isSearchable,
17
20
  labelStyle,
18
21
  dropdownStyle,
19
22
  dropdownContainerStyle,
20
23
  selectedItemStyle,
21
24
  modalBackgroundStyle,
22
25
  modalOptionsContainer,
26
+ searchInputStyle,
27
+ primaryColor,
23
28
  }: any) => {
29
+ const [newOptions, setNewOptions] = useState(options ? options : []);
24
30
  const [open, setOpen] = useState(false);
25
31
  const [selectedItem, setSelectedItem] = useState(selectedValue); //for single selection
26
32
  const [selectedItems, setSelectedItems] = useState(
@@ -30,6 +36,7 @@ export const DropdownSelect = ({
30
36
  ? []
31
37
  : [selectedValue]
32
38
  ); //for multiple selection
39
+ const [searchValue, setSearchValue] = useState('');
33
40
 
34
41
  /*===========================================
35
42
  * Selection handlers
@@ -66,7 +73,8 @@ export const DropdownSelect = ({
66
73
  let selectedItemLabel =
67
74
  options &&
68
75
  options.find(
69
- (item: string) => item[optionValue ?? 'value'] === element
76
+ (item: string) =>
77
+ item[optionValue ?? DEFAULT_OPTION_VALUE] === element
70
78
  )?.[optionLabel];
71
79
  selectedLabels.push(selectedItemLabel);
72
80
  });
@@ -76,9 +84,32 @@ export const DropdownSelect = ({
76
84
  let selectedItemLabel =
77
85
  options &&
78
86
  options.find(
79
- (item: string) => item[optionValue ?? 'value'] === selectedItem
87
+ (item: string) =>
88
+ item[optionValue ?? DEFAULT_OPTION_VALUE] === selectedItem
80
89
  );
81
- return selectedItemLabel?.[optionLabel];
90
+ return selectedItemLabel?.[optionLabel ?? DEFAULT_OPTION_LABEL];
91
+ };
92
+
93
+ /*===========================================
94
+ * Search
95
+ *==========================================*/
96
+ const onSearch = (value: string) => {
97
+ setSearchValue(value);
98
+ let searchTerm = value.toString().toLocaleLowerCase();
99
+ const searchResults = options.filter((item: any) => {
100
+ return (
101
+ item[optionLabel ?? DEFAULT_OPTION_LABEL]
102
+ .toString()
103
+ .toLowerCase()
104
+ .includes(searchTerm) ||
105
+ item[optionValue ?? DEFAULT_OPTION_VALUE]
106
+ .toString(searchTerm)
107
+ .toLowerCase()
108
+ .includes()
109
+ );
110
+ });
111
+
112
+ setNewOptions(searchResults);
82
113
  };
83
114
 
84
115
  return (
@@ -98,6 +129,7 @@ export const DropdownSelect = ({
98
129
  dropdownContainerStyle={dropdownContainerStyle}
99
130
  selectedItemStyle={selectedItemStyle}
100
131
  isMultiple={isMultiple}
132
+ primaryColor={primaryColor}
101
133
  />
102
134
  <CustomModal
103
135
  open={open}
@@ -106,8 +138,15 @@ export const DropdownSelect = ({
106
138
  modalOptionsContainer={modalOptionsContainer}
107
139
  onRequestClose={() => {}}
108
140
  >
141
+ {isSearchable && (
142
+ <Input
143
+ value={searchValue}
144
+ onChangeText={(text: string) => onSearch(text)}
145
+ style={searchInputStyle}
146
+ />
147
+ )}
109
148
  <DropdownList
110
- options={options}
149
+ options={newOptions}
111
150
  optionLabel={optionLabel}
112
151
  optionValue={optionValue}
113
152
  isMultiple={isMultiple}
@@ -115,6 +154,7 @@ export const DropdownSelect = ({
115
154
  selectedItem={selectedItem}
116
155
  handleMultipleSelections={handleMultipleSelections}
117
156
  handleSingleSelection={handleSingleSelection}
157
+ primaryColor={primaryColor}
118
158
  />
119
159
  </CustomModal>
120
160
  </>
@@ -1,5 +1,6 @@
1
1
  export const colors: any = {
2
2
  primary: '#EF8031',
3
+ red: '#FA4169',
3
4
  black: '#000000',
4
5
  white: '#FFFFFF',
5
6
  dark: '#11142D',
@@ -0,0 +1,22 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { colors } from './colors';
3
+
4
+ export const inputStyles: any = StyleSheet.create({
5
+ input: {
6
+ paddingVertical: 18,
7
+ paddingHorizontal: 23,
8
+ backgroundColor: colors.lightGray,
9
+ borderRadius: 8,
10
+ borderColor: colors.dark,
11
+ borderWidth: 1,
12
+ color: colors.dark,
13
+ width: '100%',
14
+ minHeight: 64,
15
+ },
16
+ inputFocusState: {
17
+ borderWidth: 2,
18
+ borderStyle: 'solid',
19
+ borderColor: colors.primary,
20
+ borderRadius: 8,
21
+ },
22
+ });