react-native-input-select 0.2.0 → 0.6.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.
- package/README.md +32 -19
- package/lib/commonjs/Dropdown.js +10 -22
- package/lib/commonjs/Dropdown.js.map +1 -1
- package/lib/commonjs/DropdownList.js +15 -10
- package/lib/commonjs/DropdownList.js.map +1 -1
- package/lib/commonjs/DropdownListItem.js +5 -4
- package/lib/commonjs/DropdownListItem.js.map +1 -1
- package/lib/commonjs/Input.js +50 -0
- package/lib/commonjs/Input.js.map +1 -0
- package/lib/commonjs/constants/index.js +11 -0
- package/lib/commonjs/constants/index.js.map +1 -0
- package/lib/commonjs/index.js +37 -9
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/styles/colors.js +1 -0
- package/lib/commonjs/styles/colors.js.map +1 -1
- package/lib/commonjs/styles/input.js +33 -0
- package/lib/commonjs/styles/input.js.map +1 -0
- package/lib/module/Dropdown.js +9 -22
- package/lib/module/Dropdown.js.map +1 -1
- package/lib/module/DropdownList.js +16 -11
- package/lib/module/DropdownList.js.map +1 -1
- package/lib/module/DropdownListItem.js +5 -4
- package/lib/module/DropdownListItem.js.map +1 -1
- package/lib/module/Input.js +33 -0
- package/lib/module/Input.js.map +1 -0
- package/lib/module/constants/index.js +3 -0
- package/lib/module/constants/index.js.map +1 -0
- package/lib/module/index.js +35 -9
- package/lib/module/index.js.map +1 -1
- package/lib/module/styles/colors.js +1 -0
- package/lib/module/styles/colors.js.map +1 -1
- package/lib/module/styles/input.js +22 -0
- package/lib/module/styles/input.js.map +1 -0
- package/lib/typescript/Dropdown.d.ts +1 -1
- package/lib/typescript/DropdownList.d.ts +1 -1
- package/lib/typescript/DropdownListItem.d.ts +1 -1
- package/lib/typescript/Input.d.ts +1 -0
- package/lib/typescript/constants/index.d.ts +2 -0
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/styles/input.d.ts +1 -0
- package/package.json +8 -3
- package/src/Dropdown.tsx +11 -22
- package/src/DropdownList.tsx +10 -7
- package/src/DropdownListItem.tsx +4 -3
- package/src/Input.tsx +37 -0
- package/src/constants/index.ts +2 -0
- package/src/index.tsx +49 -5
- package/src/styles/colors.ts +1 -0
- 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 &&
|
|
38
|
-
|
|
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={[
|
|
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.
|
|
96
|
+
borderColor: colors.red,
|
|
108
97
|
},
|
|
109
98
|
iconStyle: { position: 'absolute', right: 25, top: 25 },
|
|
110
|
-
error: { color: colors.
|
|
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' },
|
package/src/DropdownList.tsx
CHANGED
|
@@ -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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
package/src/DropdownListItem.tsx
CHANGED
|
@@ -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
|
+
});
|
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,18 +16,27 @@ 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(
|
|
27
|
-
Array.isArray(selectedValue)
|
|
33
|
+
Array.isArray(selectedValue)
|
|
34
|
+
? selectedValue
|
|
35
|
+
: selectedValue === '' || selectedValue === undefined
|
|
36
|
+
? []
|
|
37
|
+
: [selectedValue]
|
|
28
38
|
); //for multiple selection
|
|
39
|
+
const [searchValue, setSearchValue] = useState('');
|
|
29
40
|
|
|
30
41
|
/*===========================================
|
|
31
42
|
* Selection handlers
|
|
@@ -62,7 +73,8 @@ export const DropdownSelect = ({
|
|
|
62
73
|
let selectedItemLabel =
|
|
63
74
|
options &&
|
|
64
75
|
options.find(
|
|
65
|
-
(item: string) =>
|
|
76
|
+
(item: string) =>
|
|
77
|
+
item[optionValue ?? DEFAULT_OPTION_VALUE] === element
|
|
66
78
|
)?.[optionLabel];
|
|
67
79
|
selectedLabels.push(selectedItemLabel);
|
|
68
80
|
});
|
|
@@ -72,9 +84,32 @@ export const DropdownSelect = ({
|
|
|
72
84
|
let selectedItemLabel =
|
|
73
85
|
options &&
|
|
74
86
|
options.find(
|
|
75
|
-
(item: string) =>
|
|
87
|
+
(item: string) =>
|
|
88
|
+
item[optionValue ?? DEFAULT_OPTION_VALUE] === selectedItem
|
|
76
89
|
);
|
|
77
|
-
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);
|
|
78
113
|
};
|
|
79
114
|
|
|
80
115
|
return (
|
|
@@ -94,6 +129,7 @@ export const DropdownSelect = ({
|
|
|
94
129
|
dropdownContainerStyle={dropdownContainerStyle}
|
|
95
130
|
selectedItemStyle={selectedItemStyle}
|
|
96
131
|
isMultiple={isMultiple}
|
|
132
|
+
primaryColor={primaryColor}
|
|
97
133
|
/>
|
|
98
134
|
<CustomModal
|
|
99
135
|
open={open}
|
|
@@ -102,8 +138,15 @@ export const DropdownSelect = ({
|
|
|
102
138
|
modalOptionsContainer={modalOptionsContainer}
|
|
103
139
|
onRequestClose={() => {}}
|
|
104
140
|
>
|
|
141
|
+
{isSearchable && (
|
|
142
|
+
<Input
|
|
143
|
+
value={searchValue}
|
|
144
|
+
onChangeText={(text: string) => onSearch(text)}
|
|
145
|
+
style={searchInputStyle}
|
|
146
|
+
/>
|
|
147
|
+
)}
|
|
105
148
|
<DropdownList
|
|
106
|
-
options={
|
|
149
|
+
options={newOptions}
|
|
107
150
|
optionLabel={optionLabel}
|
|
108
151
|
optionValue={optionValue}
|
|
109
152
|
isMultiple={isMultiple}
|
|
@@ -111,6 +154,7 @@ export const DropdownSelect = ({
|
|
|
111
154
|
selectedItem={selectedItem}
|
|
112
155
|
handleMultipleSelections={handleMultipleSelections}
|
|
113
156
|
handleSingleSelection={handleSingleSelection}
|
|
157
|
+
primaryColor={primaryColor}
|
|
114
158
|
/>
|
|
115
159
|
</CustomModal>
|
|
116
160
|
</>
|
package/src/styles/colors.ts
CHANGED
|
@@ -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
|
+
});
|