react-native-input-select 0.17.0 → 0.19.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 +1 -1
- package/lib/commonjs/Dropdown.js +16 -59
- package/lib/commonjs/Dropdown.js.map +1 -1
- package/lib/commonjs/SelectedItemsView.js +102 -0
- package/lib/commonjs/SelectedItemsView.js.map +1 -0
- package/lib/commonjs/index.js +6 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Dropdown.js +16 -59
- package/lib/module/Dropdown.js.map +1 -1
- package/lib/module/SelectedItemsView.js +88 -0
- package/lib/module/SelectedItemsView.js.map +1 -0
- package/lib/module/index.js +5 -3
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Dropdown.d.ts +1 -0
- package/lib/typescript/DropdownList.d.ts +1 -0
- package/lib/typescript/Input.d.ts +1 -0
- package/lib/typescript/Modal.d.ts +1 -0
- package/lib/typescript/SelectedItemsView.d.ts +3 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/types/index.types.d.ts +21 -21
- package/package.json +8 -5
- package/src/Dropdown.tsx +16 -86
- package/src/SelectedItemsView.tsx +114 -0
- package/src/index.tsx +5 -3
- package/src/types/index.types.ts +21 -21
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# react-native-input-select
|
|
2
2
|
|
|
3
|
-
A customizable dropdown selection package for react-native for android and iOS with multiple select and search capabilities.
|
|
3
|
+
A fully customizable dropdown selection package for react-native for android and iOS with multiple select and search capabilities.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
package/lib/commonjs/Dropdown.js
CHANGED
|
@@ -9,9 +9,9 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _SelectedItemsView = _interopRequireDefault(require("./SelectedItemsView"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _colors = require("./styles/colors");
|
|
15
15
|
|
|
16
16
|
var _typography = require("./styles/typography");
|
|
17
17
|
|
|
@@ -43,47 +43,21 @@ const Dropdown = _ref => {
|
|
|
43
43
|
style: [styles.dropdownInputContainer, dropdownContainerStyle]
|
|
44
44
|
}, label && label !== '' && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
45
45
|
style: [styles.label, labelStyle]
|
|
46
|
-
}, label), /*#__PURE__*/_react.default.createElement(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
disabled: disabled
|
|
60
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
|
|
61
|
-
horizontal: true,
|
|
62
|
-
alwaysBounceHorizontal: true,
|
|
63
|
-
showsHorizontalScrollIndicator: false
|
|
64
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
65
|
-
style: styles.selectedItemsContainer,
|
|
66
|
-
onStartShouldSetResponder: () => true
|
|
67
|
-
}, isMultiple ? getSelectedItemsLabel().map((item, i) => /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
|
|
68
|
-
onPress: () => handleToggleModal(),
|
|
69
|
-
key: `SelectedItems${i}`,
|
|
70
|
-
disabled: disabled
|
|
71
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
72
|
-
style: [styles.selectedItems, {
|
|
73
|
-
backgroundColor: primaryColor
|
|
74
|
-
}, multipleSelectedItemStyle]
|
|
75
|
-
}, item))) : /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
|
|
76
|
-
onPress: () => handleToggleModal(),
|
|
46
|
+
}, label), /*#__PURE__*/_react.default.createElement(_SelectedItemsView.default, {
|
|
47
|
+
placeholder: placeholder,
|
|
48
|
+
error: error,
|
|
49
|
+
getSelectedItemsLabel: getSelectedItemsLabel,
|
|
50
|
+
handleToggleModal: handleToggleModal,
|
|
51
|
+
isMultiple: isMultiple,
|
|
52
|
+
selectedItem: selectedItem,
|
|
53
|
+
selectedItems: selectedItems,
|
|
54
|
+
dropdownStyle: dropdownStyle,
|
|
55
|
+
selectedItemStyle: selectedItemStyle,
|
|
56
|
+
multipleSelectedItemStyle: multipleSelectedItemStyle,
|
|
57
|
+
dropdownErrorStyle: dropdownErrorStyle,
|
|
58
|
+
primaryColor: primaryColor,
|
|
77
59
|
disabled: disabled
|
|
78
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
79
|
-
style: [styles.blackText, selectedItemStyle]
|
|
80
|
-
}, getSelectedItemsLabel()))), !selectedItem && (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) === 0 && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
81
|
-
style: styles.blackText
|
|
82
|
-
}, placeholder !== null && placeholder !== void 0 ? placeholder : 'Select an option')), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
83
|
-
style: styles.iconStyle
|
|
84
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
|
|
85
|
-
source: require('../src/asset/arrow-down.png')
|
|
86
|
-
}))), error && error !== '' && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
60
|
+
}), error && error !== '' && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
87
61
|
style: [styles.error, dropdownErrorTextStyle]
|
|
88
62
|
}, error), helperText && helperText !== '' && !error && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
89
63
|
style: [styles.helper, dropdownHelperTextStyle]
|
|
@@ -101,11 +75,6 @@ const styles = _reactNative.StyleSheet.create({
|
|
|
101
75
|
borderStyle: 'solid',
|
|
102
76
|
borderColor: _colors.colors.red
|
|
103
77
|
},
|
|
104
|
-
iconStyle: {
|
|
105
|
-
position: 'absolute',
|
|
106
|
-
right: 25,
|
|
107
|
-
top: 25
|
|
108
|
-
},
|
|
109
78
|
error: {
|
|
110
79
|
color: _colors.colors.red,
|
|
111
80
|
marginTop: 8,
|
|
@@ -120,18 +89,6 @@ const styles = _reactNative.StyleSheet.create({
|
|
|
120
89
|
marginBottom: 23,
|
|
121
90
|
width: '100%'
|
|
122
91
|
},
|
|
123
|
-
selectedItemsContainer: {
|
|
124
|
-
flexDirection: 'row',
|
|
125
|
-
flexWrap: 'nowrap'
|
|
126
|
-
},
|
|
127
|
-
selectedItems: {
|
|
128
|
-
color: _colors.colors.white,
|
|
129
|
-
paddingHorizontal: 10,
|
|
130
|
-
paddingVertical: 5,
|
|
131
|
-
borderRadius: 10,
|
|
132
|
-
backgroundColor: _colors.colors.primary,
|
|
133
|
-
marginRight: 10
|
|
134
|
-
},
|
|
135
92
|
blackText: {
|
|
136
93
|
color: _colors.colors.black
|
|
137
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Dropdown.tsx"],"names":["Dropdown","label","placeholder","helperText","error","getSelectedItemsLabel","handleToggleModal","isMultiple","selectedItem","selectedItems","labelStyle","dropdownStyle","dropdownContainerStyle","selectedItemStyle","multipleSelectedItemStyle","dropdownErrorStyle","dropdownErrorTextStyle","dropdownHelperTextStyle","primaryColor","disabled","styles","dropdownInputContainer","
|
|
1
|
+
{"version":3,"sources":["Dropdown.tsx"],"names":["Dropdown","label","placeholder","helperText","error","getSelectedItemsLabel","handleToggleModal","isMultiple","selectedItem","selectedItems","labelStyle","dropdownStyle","dropdownContainerStyle","selectedItemStyle","multipleSelectedItemStyle","dropdownErrorStyle","dropdownErrorTextStyle","dropdownHelperTextStyle","primaryColor","disabled","styles","dropdownInputContainer","helper","StyleSheet","create","marginBottom","color","colors","gray","typography","caption","inputFocusErrorState","borderWidth","borderStyle","borderColor","red","marginTop","primary","width","blackText","black"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAEA,MAAMA,QAAQ,GAAG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D;AAAM,IAAA,KAAK,EAAE,CAACgB,MAAM,CAAChB,KAAR,EAAeY,sBAAf;AAAb,KAAsDZ,KAAtD,CArBJ,EAwBGD,UAAU,IAAIA,UAAU,KAAK,EAA7B,IAAmC,CAACC,KAApC,iBACC,6BAAC,iBAAD;AAAM,IAAA,KAAK,EAAE,CAACgB,MAAM,CAACE,MAAR,EAAgBL,uBAAhB;AAAb,KACGd,UADH,CAzBJ,CADF;AAgCD,CArDD;;AAuDA,MAAMiB,MAAM,GAAGG,wBAAWC,MAAX,CAAkB;AAC/BvB,EAAAA,KAAK,EAAE;AAAEwB,IAAAA,YAAY,EAAE,EAAhB;AAAoBC,IAAAA,KAAK,EAAEC,eAAOC,IAAlC;AAAwC,OAAGC,uBAAWC;AAAtD,GADwB;AAE/BC,EAAAA,oBAAoB,EAAE;AACpBC,IAAAA,WAAW,EAAE,CADO;AAEpBC,IAAAA,WAAW,EAAE,OAFO;AAGpBC,IAAAA,WAAW,EAAEP,eAAOQ;AAHA,GAFS;AAO/B/B,EAAAA,KAAK,EAAE;AAAEsB,IAAAA,KAAK,EAAEC,eAAOQ,GAAhB;AAAqBC,IAAAA,SAAS,EAAE,CAAhC;AAAmC,OAAGP,uBAAWC;AAAjD,GAPwB;AAQ/BR,EAAAA,MAAM,EAAE;AAAEc,IAAAA,SAAS,EAAE,CAAb;AAAgBV,IAAAA,KAAK,EAAEC,eAAOU,OAA9B;AAAuC,OAAGR,uBAAWC;AAArD,GARuB;AAS/BT,EAAAA,sBAAsB,EAAE;AAAEI,IAAAA,YAAY,EAAE,EAAhB;AAAoBa,IAAAA,KAAK,EAAE;AAA3B,GATO;AAU/BC,EAAAA,SAAS,EAAE;AAAEb,IAAAA,KAAK,EAAEC,eAAOa;AAAhB;AAVoB,CAAlB,CAAf;;eAaexC,Q","sourcesContent":["import React from 'react';\nimport { View, Text, StyleSheet } from 'react-native';\nimport SelectedItemsView from './SelectedItemsView';\nimport { colors } from './styles/colors';\nimport { typography } from './styles/typography';\n\nconst Dropdown = ({\n label,\n placeholder,\n helperText,\n error,\n getSelectedItemsLabel,\n handleToggleModal,\n isMultiple,\n selectedItem,\n selectedItems,\n labelStyle,\n dropdownStyle,\n dropdownContainerStyle,\n selectedItemStyle,\n multipleSelectedItemStyle,\n dropdownErrorStyle,\n dropdownErrorTextStyle,\n dropdownHelperTextStyle,\n primaryColor,\n disabled,\n}: any) => {\n return (\n <View style={[styles.dropdownInputContainer, dropdownContainerStyle]}>\n {label && label !== '' && (\n <Text style={[styles.label, labelStyle]}>{label}</Text>\n )}\n <SelectedItemsView\n placeholder={placeholder}\n error={error}\n getSelectedItemsLabel={getSelectedItemsLabel}\n handleToggleModal={handleToggleModal}\n isMultiple={isMultiple}\n selectedItem={selectedItem}\n selectedItems={selectedItems}\n dropdownStyle={dropdownStyle}\n selectedItemStyle={selectedItemStyle}\n multipleSelectedItemStyle={multipleSelectedItemStyle}\n dropdownErrorStyle={dropdownErrorStyle}\n primaryColor={primaryColor}\n disabled={disabled}\n />\n\n {error && error !== '' && (\n <Text style={[styles.error, dropdownErrorTextStyle]}>{error}</Text>\n )}\n\n {helperText && helperText !== '' && !error && (\n <Text style={[styles.helper, dropdownHelperTextStyle]}>\n {helperText}\n </Text>\n )}\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n label: { marginBottom: 16, color: colors.gray, ...typography.caption },\n inputFocusErrorState: {\n borderWidth: 2,\n borderStyle: 'solid',\n borderColor: colors.red,\n },\n error: { color: colors.red, marginTop: 8, ...typography.caption },\n helper: { marginTop: 8, color: colors.primary, ...typography.caption },\n dropdownInputContainer: { marginBottom: 23, width: '100%' },\n blackText: { color: colors.black },\n});\n\nexport default Dropdown;\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
var _colors = require("./styles/colors");
|
|
13
|
+
|
|
14
|
+
var _input = require("./styles/input");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
const SelectedItemsView = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
placeholder,
|
|
21
|
+
error,
|
|
22
|
+
getSelectedItemsLabel,
|
|
23
|
+
handleToggleModal,
|
|
24
|
+
isMultiple,
|
|
25
|
+
selectedItem,
|
|
26
|
+
selectedItems,
|
|
27
|
+
dropdownStyle,
|
|
28
|
+
selectedItemStyle,
|
|
29
|
+
multipleSelectedItemStyle,
|
|
30
|
+
dropdownErrorStyle,
|
|
31
|
+
primaryColor,
|
|
32
|
+
disabled
|
|
33
|
+
} = _ref;
|
|
34
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.Pressable, {
|
|
35
|
+
onPress: () => handleToggleModal(),
|
|
36
|
+
style: _ref2 => {
|
|
37
|
+
let {
|
|
38
|
+
pressed
|
|
39
|
+
} = _ref2;
|
|
40
|
+
return [pressed && { ..._input.inputStyles.inputFocusState,
|
|
41
|
+
borderColor: primaryColor
|
|
42
|
+
}, _input.inputStyles.input, dropdownStyle, error && //this must be last
|
|
43
|
+
error !== '' && !pressed && { ..._input.inputStyles.inputFocusErrorState,
|
|
44
|
+
...dropdownErrorStyle
|
|
45
|
+
}];
|
|
46
|
+
},
|
|
47
|
+
disabled: disabled
|
|
48
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
|
|
49
|
+
horizontal: true,
|
|
50
|
+
alwaysBounceHorizontal: true,
|
|
51
|
+
showsHorizontalScrollIndicator: false
|
|
52
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
53
|
+
style: styles.selectedItemsContainer,
|
|
54
|
+
onStartShouldSetResponder: () => true
|
|
55
|
+
}, isMultiple ? getSelectedItemsLabel().map((item, i) => /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
|
|
56
|
+
onPress: () => handleToggleModal(),
|
|
57
|
+
key: `react-native-input-select-${Math.random()}-${i}`,
|
|
58
|
+
disabled: disabled
|
|
59
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
60
|
+
style: [styles.selectedItems, {
|
|
61
|
+
backgroundColor: primaryColor
|
|
62
|
+
}, multipleSelectedItemStyle]
|
|
63
|
+
}, item))) : /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
|
|
64
|
+
onPress: () => handleToggleModal(),
|
|
65
|
+
disabled: disabled
|
|
66
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
67
|
+
style: [styles.blackText, selectedItemStyle]
|
|
68
|
+
}, getSelectedItemsLabel()))), !selectedItem && (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) === 0 && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
69
|
+
style: styles.blackText
|
|
70
|
+
}, placeholder !== null && placeholder !== void 0 ? placeholder : 'Select an option')), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
71
|
+
style: styles.iconStyle
|
|
72
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
|
|
73
|
+
source: require('../src/asset/arrow-down.png')
|
|
74
|
+
})));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const styles = _reactNative.StyleSheet.create({
|
|
78
|
+
iconStyle: {
|
|
79
|
+
position: 'absolute',
|
|
80
|
+
right: 25,
|
|
81
|
+
top: 25
|
|
82
|
+
},
|
|
83
|
+
selectedItemsContainer: {
|
|
84
|
+
flexDirection: 'row',
|
|
85
|
+
flexWrap: 'nowrap'
|
|
86
|
+
},
|
|
87
|
+
selectedItems: {
|
|
88
|
+
color: _colors.colors.white,
|
|
89
|
+
paddingHorizontal: 10,
|
|
90
|
+
paddingVertical: 5,
|
|
91
|
+
borderRadius: 10,
|
|
92
|
+
backgroundColor: _colors.colors.primary,
|
|
93
|
+
marginRight: 10
|
|
94
|
+
},
|
|
95
|
+
blackText: {
|
|
96
|
+
color: _colors.colors.black
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
var _default = SelectedItemsView;
|
|
101
|
+
exports.default = _default;
|
|
102
|
+
//# sourceMappingURL=SelectedItemsView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SelectedItemsView.tsx"],"names":["SelectedItemsView","placeholder","error","getSelectedItemsLabel","handleToggleModal","isMultiple","selectedItem","selectedItems","dropdownStyle","selectedItemStyle","multipleSelectedItemStyle","dropdownErrorStyle","primaryColor","disabled","pressed","inputStyles","inputFocusState","borderColor","input","inputFocusErrorState","styles","selectedItemsContainer","map","item","i","Math","random","backgroundColor","blackText","length","iconStyle","require","StyleSheet","create","position","right","top","flexDirection","flexWrap","color","colors","white","paddingHorizontal","paddingVertical","borderRadius","primary","marginRight","black"],"mappings":";;;;;;;AAAA;;AACA;;AASA;;AACA;;;;AAEA,MAAMA,iBAAiB,GAAG,QAcf;AAAA,MAdgB;AACzBC,IAAAA,WADyB;AAEzBC,IAAAA,KAFyB;AAGzBC,IAAAA,qBAHyB;AAIzBC,IAAAA,iBAJyB;AAKzBC,IAAAA,UALyB;AAMzBC,IAAAA,YANyB;AAOzBC,IAAAA,aAPyB;AAQzBC,IAAAA,aARyB;AASzBC,IAAAA,iBATyB;AAUzBC,IAAAA,yBAVyB;AAWzBC,IAAAA,kBAXyB;AAYzBC,IAAAA,YAZyB;AAazBC,IAAAA;AAbyB,GAchB;AACT,sBACE,6BAAC,sBAAD;AACE,IAAA,OAAO,EAAE,MAAMT,iBAAiB,EADlC;AAEE,IAAA,KAAK,EAAE;AAAA,UAAC;AAAEU,QAAAA;AAAF,OAAD;AAAA,aAAiB,CACtBA,OAAO,IAAI,EACT,GAAGC,mBAAYC,eADN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3C,iBACC,6BAAC,iBAAD;AAAM,IAAA,KAAK,EAAET,MAAM,CAACQ;AAApB,KACG3B,WADH,aACGA,WADH,cACGA,WADH,GACkB,kBADlB,CAxCJ,CAlBF,eA+DE,6BAAC,iBAAD;AAAM,IAAA,KAAK,EAAEmB,MAAM,CAACU;AAApB,kBACE,6BAAC,kBAAD;AAAO,IAAA,MAAM,EAAEC,OAAO,CAAC,6BAAD;AAAtB,IADF,CA/DF,CADF;AAqED,CApFD;;AAsFA,MAAMX,MAAM,GAAGY,wBAAWC,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE;AAAEI,IAAAA,QAAQ,EAAE,UAAZ;AAAwBC,IAAAA,KAAK,EAAE,EAA/B;AAAmCC,IAAAA,GAAG,EAAE;AAAxC,GADoB;AAE/Bf,EAAAA,sBAAsB,EAAE;AAAEgB,IAAAA,aAAa,EAAE,KAAjB;AAAwBC,IAAAA,QAAQ,EAAE;AAAlC,GAFO;AAG/B/B,EAAAA,aAAa,EAAE;AACbgC,IAAAA,KAAK,EAAEC,eAAOC,KADD;AAEbC,IAAAA,iBAAiB,EAAE,EAFN;AAGbC,IAAAA,eAAe,EAAE,CAHJ;AAIbC,IAAAA,YAAY,EAAE,EAJD;AAKbjB,IAAAA,eAAe,EAAEa,eAAOK,OALX;AAMbC,IAAAA,WAAW,EAAE;AANA,GAHgB;AAW/BlB,EAAAA,SAAS,EAAE;AAAEW,IAAAA,KAAK,EAAEC,eAAOO;AAAhB;AAXoB,CAAlB,CAAf;;eAce/C,iB","sourcesContent":["import React from 'react';\nimport {\n View,\n Text,\n Pressable,\n ScrollView,\n StyleSheet,\n Image,\n TouchableOpacity,\n} from 'react-native';\nimport { colors } from './styles/colors';\nimport { inputStyles } from './styles/input';\n\nconst SelectedItemsView = ({\n placeholder,\n error,\n getSelectedItemsLabel,\n handleToggleModal,\n isMultiple,\n selectedItem,\n selectedItems,\n dropdownStyle,\n selectedItemStyle,\n multipleSelectedItemStyle,\n dropdownErrorStyle,\n primaryColor,\n disabled,\n}: any) => {\n return (\n <Pressable\n onPress={() => handleToggleModal()}\n style={({ pressed }) => [\n pressed && {\n ...inputStyles.inputFocusState,\n borderColor: primaryColor,\n },\n inputStyles.input,\n dropdownStyle,\n error && //this must be last\n error !== '' &&\n !pressed && {\n ...inputStyles.inputFocusErrorState,\n ...dropdownErrorStyle,\n },\n ]}\n disabled={disabled}\n >\n <ScrollView\n horizontal\n alwaysBounceHorizontal\n showsHorizontalScrollIndicator={false}\n >\n <View\n style={styles.selectedItemsContainer}\n onStartShouldSetResponder={() => true}\n >\n {isMultiple ? (\n getSelectedItemsLabel().map((item: any, i: Number) => (\n <TouchableOpacity\n onPress={() => handleToggleModal()}\n key={`react-native-input-select-${Math.random()}-${i}`}\n disabled={disabled}\n >\n <Text\n style={[\n styles.selectedItems,\n { backgroundColor: primaryColor },\n multipleSelectedItemStyle,\n ]}\n >\n {item}\n </Text>\n </TouchableOpacity>\n ))\n ) : (\n <TouchableOpacity\n onPress={() => handleToggleModal()}\n disabled={disabled}\n >\n <Text style={[styles.blackText, selectedItemStyle]}>\n {getSelectedItemsLabel()}\n </Text>\n </TouchableOpacity>\n )}\n </View>\n\n {!selectedItem && selectedItems?.length === 0 && (\n <Text style={styles.blackText}>\n {placeholder ?? 'Select an option'}\n </Text>\n )}\n </ScrollView>\n <View style={styles.iconStyle}>\n <Image source={require('../src/asset/arrow-down.png')} />\n </View>\n </Pressable>\n );\n};\n\nconst styles = StyleSheet.create({\n iconStyle: { position: 'absolute', right: 25, top: 25 },\n selectedItemsContainer: { flexDirection: 'row', flexWrap: 'nowrap' },\n selectedItems: {\n color: colors.white,\n paddingHorizontal: 10,\n paddingVertical: 5,\n borderRadius: 10,\n backgroundColor: colors.primary,\n marginRight: 10,\n },\n blackText: { color: colors.black },\n});\n\nexport default SelectedItemsView;\n"]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -17,6 +17,8 @@ var _constants = require("./constants");
|
|
|
17
17
|
|
|
18
18
|
var _Input = require("./Input");
|
|
19
19
|
|
|
20
|
+
var _colors = require("./styles/colors");
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -132,6 +134,7 @@ const DropdownSelect = (_ref, rest) => {
|
|
|
132
134
|
setNewOptions(options);
|
|
133
135
|
};
|
|
134
136
|
|
|
137
|
+
let primary = primaryColor || _colors.colors.gray;
|
|
135
138
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Dropdown.default, _extends({
|
|
136
139
|
label: label,
|
|
137
140
|
placeholder: placeholder,
|
|
@@ -150,7 +153,7 @@ const DropdownSelect = (_ref, rest) => {
|
|
|
150
153
|
selectedItemStyle: selectedItemStyle,
|
|
151
154
|
multipleSelectedItemStyle: multipleSelectedItemStyle,
|
|
152
155
|
isMultiple: isMultiple,
|
|
153
|
-
primaryColor:
|
|
156
|
+
primaryColor: primary,
|
|
154
157
|
disabled: disabled
|
|
155
158
|
}, rest)), /*#__PURE__*/_react.default.createElement(_Modal.default, {
|
|
156
159
|
open: open,
|
|
@@ -162,7 +165,7 @@ const DropdownSelect = (_ref, rest) => {
|
|
|
162
165
|
value: searchValue,
|
|
163
166
|
onChangeText: text => onSearch(text),
|
|
164
167
|
style: searchInputStyle,
|
|
165
|
-
primaryColor:
|
|
168
|
+
primaryColor: primary
|
|
166
169
|
}), /*#__PURE__*/_react.default.createElement(_DropdownList.default, {
|
|
167
170
|
options: newOptions,
|
|
168
171
|
optionLabel: optionLabel,
|
|
@@ -172,7 +175,7 @@ const DropdownSelect = (_ref, rest) => {
|
|
|
172
175
|
selectedItem: selectedItem,
|
|
173
176
|
handleMultipleSelections: handleMultipleSelections,
|
|
174
177
|
handleSingleSelection: handleSingleSelection,
|
|
175
|
-
primaryColor:
|
|
178
|
+
primaryColor: primary
|
|
176
179
|
})));
|
|
177
180
|
};
|
|
178
181
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["DropdownSelect","rest","placeholder","label","error","helperText","options","optionLabel","optionValue","onValueChange","selectedValue","isMultiple","isSearchable","labelStyle","dropdownStyle","dropdownContainerStyle","dropdownErrorStyle","dropdownErrorTextStyle","dropdownHelperTextStyle","selectedItemStyle","multipleSelectedItemStyle","modalBackgroundStyle","modalOptionsContainer","searchInputStyle","primaryColor","disabled","newOptions","setNewOptions","open","setOpen","selectedItem","setSelectedItem","selectedItems","setSelectedItems","Array","isArray","undefined","searchValue","setSearchValue","handleSingleSelection","value","handleMultipleSelections","selectedValues","includes","filter","item","push","getSelectedItemsLabel","selectedLabels","forEach","element","selectedItemLabel","find","DEFAULT_OPTION_VALUE","DEFAULT_OPTION_LABEL","onSearch","searchText","toString","toLocaleLowerCase","trim","regexFilter","RegExp","searchResults","toLowerCase","search","handleToggleModal","text"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;AAEO,MAAMA,cAAc,GAAG,OA2B5BC,IA3B4B,KA4BzB;AAAA,MA3BH;AACEC,IAAAA,WADF;AAEEC,IAAAA,KAFF;AAGEC,IAAAA,KAHF;AAIEC,IAAAA,UAJF;AAKEC,IAAAA,OALF;AAMEC,IAAAA,WANF;AAOEC,IAAAA,WAPF;AAQEC,IAAAA,aARF;AASEC,IAAAA,aATF;AAUEC,IAAAA,UAVF;AAWEC,IAAAA,YAXF;AAYEC,IAAAA,UAZF;AAaEC,IAAAA,aAbF;AAcEC,IAAAA,sBAdF;AAeEC,IAAAA,kBAfF;AAgBEC,IAAAA,sBAhBF;AAiBEC,IAAAA,uBAjBF;AAkBEC,IAAAA,iBAlBF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IAAA,QAAQ,EAAEC;AAnBZ,KAoBMxB,IApBN,EADF,eAuBE,6BAAC,cAAD;AACE,IAAA,IAAI,EAAE2B,IADR;AAEE,IAAA,iBAAiB,EAAEqC,iBAFrB;AAGE,IAAA,oBAAoB,EAAE5C,oBAHxB;AAIE,IAAA,qBAAqB,EAAEC,qBAJzB;AAKE,IAAA,cAAc,EAAE,MAAM,CAAE;AAL1B,KAOGV,YAAY,iBACX,6BAAC,YAAD;AACE,IAAA,KAAK,EAAEyB,WADT;AAEE,IAAA,YAAY,EAAG6B,IAAD,IAAkBX,QAAQ,CAACW,IAAD,CAF1C;AAGE,IAAA,KAAK,EAAE3C,gBAHT;AAIE,IAAA,YAAY,EAAEC;AAJhB,IARJ,eAeE,6BAAC,qBAAD;AACE,IAAA,OAAO,EAAEE,UADX;AAEE,IAAA,WAAW,EAAEnB,WAFf;AAGE,IAAA,WAAW,EAAEC,WAHf;AAIE,IAAA,UAAU,EAAEG,UAJd;AAKE,IAAA,aAAa,EAAEqB,aALjB;AAME,IAAA,YAAY,EAAEF,YANhB;AAOE,IAAA,wBAAwB,EAAEW,wBAP5B;AAQE,IAAA,qBAAqB,EAAEF,qBARzB;AASE,IAAA,YAAY,EAAEf;AAThB,IAfF,CAvBF,CADF;AAqDD,CAvLM;;;eAyLQxB,c","sourcesContent":["import React, { useState } from 'react';\nimport Dropdown from './Dropdown';\nimport CustomModal from './Modal';\nimport DropdownList from './DropdownList';\nimport { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';\nimport type { DropdownProps } from './types/index.types';\nimport { Input } from './Input';\n\nexport const DropdownSelect = (\n {\n placeholder,\n label,\n error,\n helperText,\n options,\n optionLabel,\n optionValue,\n onValueChange,\n selectedValue,\n isMultiple,\n isSearchable,\n labelStyle,\n dropdownStyle,\n dropdownContainerStyle,\n dropdownErrorStyle,\n dropdownErrorTextStyle,\n dropdownHelperTextStyle,\n selectedItemStyle,\n multipleSelectedItemStyle,\n modalBackgroundStyle,\n modalOptionsContainer,\n searchInputStyle,\n primaryColor,\n disabled,\n }: DropdownProps,\n rest: any\n) => {\n const [newOptions, setNewOptions] = useState(options ? options : []);\n const [open, setOpen] = useState(false);\n const [selectedItem, setSelectedItem] = useState(selectedValue); //for single selection\n const [selectedItems, setSelectedItems] = useState(\n Array.isArray(selectedValue)\n ? selectedValue\n : selectedValue === '' || selectedValue === undefined\n ? []\n : [selectedValue]\n ); //for multiple selection\n const [searchValue, setSearchValue] = useState('');\n\n /*===========================================\n * Selection handlers\n *==========================================*/\n const handleSingleSelection = (value: any) => {\n if (selectedItem === value) {\n setSelectedItem(null);\n } else {\n setSelectedItem(value);\n onValueChange(value); //send value to parent\n setOpen(false); //close modal upon selection\n }\n };\n\n const handleMultipleSelections = (value: any) => {\n let selectedValues = [...selectedItems];\n\n if (selectedValues.includes(value)) {\n selectedValues = selectedValues.filter((item) => item !== value);\n } else {\n selectedValues.push(value);\n }\n setSelectedItems(selectedValues);\n };\n\n /*===========================================\n * Get label handler\n *==========================================*/\n const getSelectedItemsLabel = () => {\n if (isMultiple) {\n let selectedLabels: Array<string> = [];\n selectedItems &&\n selectedItems.forEach((element) => {\n let selectedItemLabel =\n options &&\n options.find(\n (item: any) =>\n item[optionValue ?? DEFAULT_OPTION_VALUE] === element\n )?.[optionLabel];\n selectedLabels.push(selectedItemLabel);\n });\n return selectedLabels;\n }\n\n let selectedItemLabel =\n options &&\n options.find(\n (item: any) =>\n item[optionValue ?? DEFAULT_OPTION_VALUE] === selectedItem\n );\n return selectedItemLabel?.[optionLabel ?? DEFAULT_OPTION_LABEL];\n };\n\n /*===========================================\n * Search\n *==========================================*/\n const onSearch = (value: string) => {\n setSearchValue(value);\n\n let searchText = value.toString().toLocaleLowerCase().trim();\n\n const regexFilter = new RegExp(searchText, 'i');\n\n const searchResults = options.filter((item: any) => {\n if (\n item[optionLabel ?? DEFAULT_OPTION_LABEL]\n .toString()\n .toLowerCase()\n .search(regexFilter) !== -1 ||\n item[optionValue ?? DEFAULT_OPTION_VALUE]\n .toString(regexFilter)\n .toLowerCase()\n .search(regexFilter) !== -1\n ) {\n return item;\n }\n });\n\n setNewOptions(searchResults);\n };\n\n /*===========================================\n * Modal\n *==========================================*/\n const handleToggleModal = () => {\n setOpen(!open);\n setSearchValue('');\n setNewOptions(options);\n };\n\n return (\n <>\n <Dropdown\n label={label}\n placeholder={placeholder}\n helperText={helperText}\n error={error}\n getSelectedItemsLabel={getSelectedItemsLabel}\n selectedItem={selectedItem}\n selectedItems={selectedItems}\n handleToggleModal={handleToggleModal}\n labelStyle={labelStyle}\n dropdownStyle={dropdownStyle}\n dropdownContainerStyle={dropdownContainerStyle}\n dropdownErrorStyle={dropdownErrorStyle}\n dropdownErrorTextStyle={dropdownErrorTextStyle}\n dropdownHelperTextStyle={dropdownHelperTextStyle}\n selectedItemStyle={selectedItemStyle}\n multipleSelectedItemStyle={multipleSelectedItemStyle}\n isMultiple={isMultiple}\n primaryColor={primaryColor}\n disabled={disabled}\n {...rest}\n />\n <CustomModal\n open={open}\n handleToggleModal={handleToggleModal}\n modalBackgroundStyle={modalBackgroundStyle}\n modalOptionsContainer={modalOptionsContainer}\n onRequestClose={() => {}}\n >\n {isSearchable && (\n <Input\n value={searchValue}\n onChangeText={(text: string) => onSearch(text)}\n style={searchInputStyle}\n primaryColor={primaryColor}\n />\n )}\n <DropdownList\n options={newOptions}\n optionLabel={optionLabel}\n optionValue={optionValue}\n isMultiple={isMultiple}\n selectedItems={selectedItems}\n selectedItem={selectedItem}\n handleMultipleSelections={handleMultipleSelections}\n handleSingleSelection={handleSingleSelection}\n primaryColor={primaryColor}\n />\n </CustomModal>\n </>\n );\n};\n\nexport default DropdownSelect;\n"]}
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["DropdownSelect","rest","placeholder","label","error","helperText","options","optionLabel","optionValue","onValueChange","selectedValue","isMultiple","isSearchable","labelStyle","dropdownStyle","dropdownContainerStyle","dropdownErrorStyle","dropdownErrorTextStyle","dropdownHelperTextStyle","selectedItemStyle","multipleSelectedItemStyle","modalBackgroundStyle","modalOptionsContainer","searchInputStyle","primaryColor","disabled","newOptions","setNewOptions","open","setOpen","selectedItem","setSelectedItem","selectedItems","setSelectedItems","Array","isArray","undefined","searchValue","setSearchValue","handleSingleSelection","value","handleMultipleSelections","selectedValues","includes","filter","item","push","getSelectedItemsLabel","selectedLabels","forEach","element","selectedItemLabel","find","DEFAULT_OPTION_VALUE","DEFAULT_OPTION_LABEL","onSearch","searchText","toString","toLocaleLowerCase","trim","regexFilter","RegExp","searchResults","toLowerCase","search","handleToggleModal","primary","colors","gray","text"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;;;AAEO,MAAMA,cAAc,GAAG,OA2B5BC,IA3B4B,KA4BzB;AAAA,MA3BH;AACEC,IAAAA,WADF;AAEEC,IAAAA,KAFF;AAGEC,IAAAA,KAHF;AAIEC,IAAAA,UAJF;AAKEC,IAAAA,OALF;AAMEC,IAAAA,WANF;AAOEC,IAAAA,WAPF;AAQEC,IAAAA,aARF;AASEC,IAAAA,aATF;AAUEC,IAAAA,UAVF;AAWEC,IAAAA,YAXF;AAYEC,IAAAA,UAZF;AAaEC,IAAAA,aAbF;AAcEC,IAAAA,sBAdF;AAeEC,IAAAA,kBAfF;AAgBEC,IAAAA,sBAhBF;AAiBEC,IAAAA,uBAjBF;AAkBEC,IAAAA,iBAlBF;AAmBEC,IAAAA,yBAnBF;AAoBEC,IAAAA,oBApBF;AAqBEC,IAAAA,qBArBF;AAsBEC,IAAAA,gBAtBF;AAuBEC,IAAAA,YAvBF;AAwBEC,IAAAA;AAxBF,GA2BG;AACH,QAAM,CAACC,UAAD,EAAaC,aAAb,IAA8B,qBAASrB,OAAO,GAAGA,OAAH,GAAa,EAA7B,CAApC;AACA,QAAM,CAACsB,IAAD,EAAOC,OAAP,IAAkB,qBAAS,KAAT,CAAxB;AACA,QAAM,CAACC,YAAD,EAAeC,eAAf,IAAkC,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ACE,IAAA,KAAK,EAAEyB,WADT;AAEE,IAAA,YAAY,EAAGgC,IAAD,IAAkBd,QAAQ,CAACc,IAAD,CAF1C;AAGE,IAAA,KAAK,EAAE9C,gBAHT;AAIE,IAAA,YAAY,EAAE2C;AAJhB,IARJ,eAeE,6BAAC,qBAAD;AACE,IAAA,OAAO,EAAExC,UADX;AAEE,IAAA,WAAW,EAAEnB,WAFf;AAGE,IAAA,WAAW,EAAEC,WAHf;AAIE,IAAA,UAAU,EAAEG,UAJd;AAKE,IAAA,aAAa,EAAEqB,aALjB;AAME,IAAA,YAAY,EAAEF,YANhB;AAOE,IAAA,wBAAwB,EAAEW,wBAP5B;AAQE,IAAA,qBAAqB,EAAEF,qBARzB;AASE,IAAA,YAAY,EAAE2B;AAThB,IAfF,CAvBF,CADF;AAqDD,CAxLM;;;eA0LQlE,c","sourcesContent":["import React, { useState } from 'react';\nimport Dropdown from './Dropdown';\nimport CustomModal from './Modal';\nimport DropdownList from './DropdownList';\nimport { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';\nimport type { DropdownProps } from './types/index.types';\nimport { Input } from './Input';\nimport { colors } from './styles/colors';\n\nexport const DropdownSelect = (\n {\n placeholder,\n label,\n error,\n helperText,\n options,\n optionLabel,\n optionValue,\n onValueChange,\n selectedValue,\n isMultiple,\n isSearchable,\n labelStyle,\n dropdownStyle,\n dropdownContainerStyle,\n dropdownErrorStyle,\n dropdownErrorTextStyle,\n dropdownHelperTextStyle,\n selectedItemStyle,\n multipleSelectedItemStyle,\n modalBackgroundStyle,\n modalOptionsContainer,\n searchInputStyle,\n primaryColor,\n disabled,\n }: DropdownProps,\n rest: any\n) => {\n const [newOptions, setNewOptions] = useState(options ? options : []);\n const [open, setOpen] = useState(false);\n const [selectedItem, setSelectedItem] = useState(selectedValue); //for single selection\n const [selectedItems, setSelectedItems] = useState(\n Array.isArray(selectedValue)\n ? selectedValue\n : selectedValue === '' || selectedValue === undefined\n ? []\n : [selectedValue]\n ); //for multiple selection\n const [searchValue, setSearchValue] = useState('');\n\n /*===========================================\n * Selection handlers\n *==========================================*/\n const handleSingleSelection = (value: any) => {\n if (selectedItem === value) {\n setSelectedItem(null);\n } else {\n setSelectedItem(value);\n onValueChange(value); //send value to parent\n setOpen(false); //close modal upon selection\n }\n };\n\n const handleMultipleSelections = (value: any) => {\n let selectedValues = [...selectedItems];\n\n if (selectedValues.includes(value)) {\n selectedValues = selectedValues.filter((item) => item !== value);\n } else {\n selectedValues.push(value);\n }\n setSelectedItems(selectedValues);\n };\n\n /*===========================================\n * Get label handler\n *==========================================*/\n const getSelectedItemsLabel = () => {\n if (isMultiple) {\n let selectedLabels: Array<string> = [];\n selectedItems &&\n selectedItems.forEach((element) => {\n let selectedItemLabel =\n options &&\n options.find(\n (item: any) =>\n item[optionValue ?? DEFAULT_OPTION_VALUE] === element\n )?.[optionLabel];\n selectedLabels.push(selectedItemLabel);\n });\n return selectedLabels;\n }\n\n let selectedItemLabel =\n options &&\n options.find(\n (item: any) =>\n item[optionValue ?? DEFAULT_OPTION_VALUE] === selectedItem\n );\n return selectedItemLabel?.[optionLabel ?? DEFAULT_OPTION_LABEL];\n };\n\n /*===========================================\n * Search\n *==========================================*/\n const onSearch = (value: string) => {\n setSearchValue(value);\n\n let searchText = value.toString().toLocaleLowerCase().trim();\n\n const regexFilter = new RegExp(searchText, 'i');\n\n const searchResults = options.filter((item: any) => {\n if (\n item[optionLabel ?? DEFAULT_OPTION_LABEL]\n .toString()\n .toLowerCase()\n .search(regexFilter) !== -1 ||\n item[optionValue ?? DEFAULT_OPTION_VALUE]\n .toString(regexFilter)\n .toLowerCase()\n .search(regexFilter) !== -1\n ) {\n return item;\n }\n });\n\n setNewOptions(searchResults);\n };\n\n /*===========================================\n * Modal\n *==========================================*/\n const handleToggleModal = () => {\n setOpen(!open);\n setSearchValue('');\n setNewOptions(options);\n };\n\n let primary = primaryColor || colors.gray;\n return (\n <>\n <Dropdown\n label={label}\n placeholder={placeholder}\n helperText={helperText}\n error={error}\n getSelectedItemsLabel={getSelectedItemsLabel}\n selectedItem={selectedItem}\n selectedItems={selectedItems}\n handleToggleModal={handleToggleModal}\n labelStyle={labelStyle}\n dropdownStyle={dropdownStyle}\n dropdownContainerStyle={dropdownContainerStyle}\n dropdownErrorStyle={dropdownErrorStyle}\n dropdownErrorTextStyle={dropdownErrorTextStyle}\n dropdownHelperTextStyle={dropdownHelperTextStyle}\n selectedItemStyle={selectedItemStyle}\n multipleSelectedItemStyle={multipleSelectedItemStyle}\n isMultiple={isMultiple}\n primaryColor={primary}\n disabled={disabled}\n {...rest}\n />\n <CustomModal\n open={open}\n handleToggleModal={handleToggleModal}\n modalBackgroundStyle={modalBackgroundStyle}\n modalOptionsContainer={modalOptionsContainer}\n onRequestClose={() => {}}\n >\n {isSearchable && (\n <Input\n value={searchValue}\n onChangeText={(text: string) => onSearch(text)}\n style={searchInputStyle}\n primaryColor={primary}\n />\n )}\n <DropdownList\n options={newOptions}\n optionLabel={optionLabel}\n optionValue={optionValue}\n isMultiple={isMultiple}\n selectedItems={selectedItems}\n selectedItem={selectedItem}\n handleMultipleSelections={handleMultipleSelections}\n handleSingleSelection={handleSingleSelection}\n primaryColor={primary}\n />\n </CustomModal>\n </>\n );\n};\n\nexport default DropdownSelect;\n"]}
|
package/lib/module/Dropdown.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { View, Text,
|
|
2
|
+
import { View, Text, StyleSheet } from 'react-native';
|
|
3
|
+
import SelectedItemsView from './SelectedItemsView';
|
|
3
4
|
import { colors } from './styles/colors';
|
|
4
|
-
import { inputStyles } from './styles/input';
|
|
5
5
|
import { typography } from './styles/typography';
|
|
6
6
|
|
|
7
7
|
const Dropdown = _ref => {
|
|
@@ -30,47 +30,21 @@ const Dropdown = _ref => {
|
|
|
30
30
|
style: [styles.dropdownInputContainer, dropdownContainerStyle]
|
|
31
31
|
}, label && label !== '' && /*#__PURE__*/React.createElement(Text, {
|
|
32
32
|
style: [styles.label, labelStyle]
|
|
33
|
-
}, label), /*#__PURE__*/React.createElement(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
}, label), /*#__PURE__*/React.createElement(SelectedItemsView, {
|
|
34
|
+
placeholder: placeholder,
|
|
35
|
+
error: error,
|
|
36
|
+
getSelectedItemsLabel: getSelectedItemsLabel,
|
|
37
|
+
handleToggleModal: handleToggleModal,
|
|
38
|
+
isMultiple: isMultiple,
|
|
39
|
+
selectedItem: selectedItem,
|
|
40
|
+
selectedItems: selectedItems,
|
|
41
|
+
dropdownStyle: dropdownStyle,
|
|
42
|
+
selectedItemStyle: selectedItemStyle,
|
|
43
|
+
multipleSelectedItemStyle: multipleSelectedItemStyle,
|
|
44
|
+
dropdownErrorStyle: dropdownErrorStyle,
|
|
45
|
+
primaryColor: primaryColor,
|
|
46
46
|
disabled: disabled
|
|
47
|
-
}, /*#__PURE__*/React.createElement(
|
|
48
|
-
horizontal: true,
|
|
49
|
-
alwaysBounceHorizontal: true,
|
|
50
|
-
showsHorizontalScrollIndicator: false
|
|
51
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
52
|
-
style: styles.selectedItemsContainer,
|
|
53
|
-
onStartShouldSetResponder: () => true
|
|
54
|
-
}, isMultiple ? getSelectedItemsLabel().map((item, i) => /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
55
|
-
onPress: () => handleToggleModal(),
|
|
56
|
-
key: `SelectedItems${i}`,
|
|
57
|
-
disabled: disabled
|
|
58
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
59
|
-
style: [styles.selectedItems, {
|
|
60
|
-
backgroundColor: primaryColor
|
|
61
|
-
}, multipleSelectedItemStyle]
|
|
62
|
-
}, item))) : /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
63
|
-
onPress: () => handleToggleModal(),
|
|
64
|
-
disabled: disabled
|
|
65
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
66
|
-
style: [styles.blackText, selectedItemStyle]
|
|
67
|
-
}, getSelectedItemsLabel()))), !selectedItem && (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) === 0 && /*#__PURE__*/React.createElement(Text, {
|
|
68
|
-
style: styles.blackText
|
|
69
|
-
}, placeholder !== null && placeholder !== void 0 ? placeholder : 'Select an option')), /*#__PURE__*/React.createElement(View, {
|
|
70
|
-
style: styles.iconStyle
|
|
71
|
-
}, /*#__PURE__*/React.createElement(Image, {
|
|
72
|
-
source: require('../src/asset/arrow-down.png')
|
|
73
|
-
}))), error && error !== '' && /*#__PURE__*/React.createElement(Text, {
|
|
47
|
+
}), error && error !== '' && /*#__PURE__*/React.createElement(Text, {
|
|
74
48
|
style: [styles.error, dropdownErrorTextStyle]
|
|
75
49
|
}, error), helperText && helperText !== '' && !error && /*#__PURE__*/React.createElement(Text, {
|
|
76
50
|
style: [styles.helper, dropdownHelperTextStyle]
|
|
@@ -88,11 +62,6 @@ const styles = StyleSheet.create({
|
|
|
88
62
|
borderStyle: 'solid',
|
|
89
63
|
borderColor: colors.red
|
|
90
64
|
},
|
|
91
|
-
iconStyle: {
|
|
92
|
-
position: 'absolute',
|
|
93
|
-
right: 25,
|
|
94
|
-
top: 25
|
|
95
|
-
},
|
|
96
65
|
error: {
|
|
97
66
|
color: colors.red,
|
|
98
67
|
marginTop: 8,
|
|
@@ -107,18 +76,6 @@ const styles = StyleSheet.create({
|
|
|
107
76
|
marginBottom: 23,
|
|
108
77
|
width: '100%'
|
|
109
78
|
},
|
|
110
|
-
selectedItemsContainer: {
|
|
111
|
-
flexDirection: 'row',
|
|
112
|
-
flexWrap: 'nowrap'
|
|
113
|
-
},
|
|
114
|
-
selectedItems: {
|
|
115
|
-
color: colors.white,
|
|
116
|
-
paddingHorizontal: 10,
|
|
117
|
-
paddingVertical: 5,
|
|
118
|
-
borderRadius: 10,
|
|
119
|
-
backgroundColor: colors.primary,
|
|
120
|
-
marginRight: 10
|
|
121
|
-
},
|
|
122
79
|
blackText: {
|
|
123
80
|
color: colors.black
|
|
124
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Dropdown.tsx"],"names":["React","View","Text","
|
|
1
|
+
{"version":3,"sources":["Dropdown.tsx"],"names":["React","View","Text","StyleSheet","SelectedItemsView","colors","typography","Dropdown","label","placeholder","helperText","error","getSelectedItemsLabel","handleToggleModal","isMultiple","selectedItem","selectedItems","labelStyle","dropdownStyle","dropdownContainerStyle","selectedItemStyle","multipleSelectedItemStyle","dropdownErrorStyle","dropdownErrorTextStyle","dropdownHelperTextStyle","primaryColor","disabled","styles","dropdownInputContainer","helper","create","marginBottom","color","gray","caption","inputFocusErrorState","borderWidth","borderStyle","borderColor","red","marginTop","primary","width","blackText","black"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,IAAT,EAAeC,IAAf,EAAqBC,UAArB,QAAuC,cAAvC;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,SAASC,MAAT,QAAuB,iBAAvB;AACA,SAASC,UAAT,QAA2B,qBAA3B;;AAEA,MAAMC,QAAQ,GAAG,QAoBN;AAAA,MApBO;AAChBC,IAAAA,KADgB;AAEhBC,IAAAA,WAFgB;AAGhBC,IAAAA,UAHgB;AAIhBC,IAAAA,KAJgB;AAKhBC,IAAAA,qBALgB;AAMhBC,IAAAA,iBANgB;AAOhBC,IAAAA,UAPgB;AAQhBC,IAAAA,YARgB;AAShBC,IAAAA,aATgB;AAUhBC,IAAAA,UAVgB;AAWhBC,IAAAA,aAXgB;AAYhBC,IAAAA,sBAZgB;AAahBC,IAAAA,iBAbgB;AAchBC,IAAAA,yBAdgB;AAehBC,IAAAA,kBAfgB;AAgBhBC,IAAAA,sBAhBgB;AAiBhBC,IAAAA,uBAjBgB;AAkBhBC,IAAAA,YA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E3B,MAAM,CAAC4B,IAAlC;AAAwC,OAAG3B,UAAU,CAAC4B;AAAtD,GADwB;AAE/BC,EAAAA,oBAAoB,EAAE;AACpBC,IAAAA,WAAW,EAAE,CADO;AAEpBC,IAAAA,WAAW,EAAE,OAFO;AAGpBC,IAAAA,WAAW,EAAEjC,MAAM,CAACkC;AAHA,GAFS;AAO/B5B,EAAAA,KAAK,EAAE;AAAEqB,IAAAA,KAAK,EAAE3B,MAAM,CAACkC,GAAhB;AAAqBC,IAAAA,SAAS,EAAE,CAAhC;AAAmC,OAAGlC,UAAU,CAAC4B;AAAjD,GAPwB;AAQ/BL,EAAAA,MAAM,EAAE;AAAEW,IAAAA,SAAS,EAAE,CAAb;AAAgBR,IAAAA,KAAK,EAAE3B,MAAM,CAACoC,OAA9B;AAAuC,OAAGnC,UAAU,CAAC4B;AAArD,GARuB;AAS/BN,EAAAA,sBAAsB,EAAE;AAAEG,IAAAA,YAAY,EAAE,EAAhB;AAAoBW,IAAAA,KAAK,EAAE;AAA3B,GATO;AAU/BC,EAAAA,SAAS,EAAE;AAAEX,IAAAA,KAAK,EAAE3B,MAAM,CAACuC;AAAhB;AAVoB,CAAlB,CAAf;AAaA,eAAerC,QAAf","sourcesContent":["import React from 'react';\nimport { View, Text, StyleSheet } from 'react-native';\nimport SelectedItemsView from './SelectedItemsView';\nimport { colors } from './styles/colors';\nimport { typography } from './styles/typography';\n\nconst Dropdown = ({\n label,\n placeholder,\n helperText,\n error,\n getSelectedItemsLabel,\n handleToggleModal,\n isMultiple,\n selectedItem,\n selectedItems,\n labelStyle,\n dropdownStyle,\n dropdownContainerStyle,\n selectedItemStyle,\n multipleSelectedItemStyle,\n dropdownErrorStyle,\n dropdownErrorTextStyle,\n dropdownHelperTextStyle,\n primaryColor,\n disabled,\n}: any) => {\n return (\n <View style={[styles.dropdownInputContainer, dropdownContainerStyle]}>\n {label && label !== '' && (\n <Text style={[styles.label, labelStyle]}>{label}</Text>\n )}\n <SelectedItemsView\n placeholder={placeholder}\n error={error}\n getSelectedItemsLabel={getSelectedItemsLabel}\n handleToggleModal={handleToggleModal}\n isMultiple={isMultiple}\n selectedItem={selectedItem}\n selectedItems={selectedItems}\n dropdownStyle={dropdownStyle}\n selectedItemStyle={selectedItemStyle}\n multipleSelectedItemStyle={multipleSelectedItemStyle}\n dropdownErrorStyle={dropdownErrorStyle}\n primaryColor={primaryColor}\n disabled={disabled}\n />\n\n {error && error !== '' && (\n <Text style={[styles.error, dropdownErrorTextStyle]}>{error}</Text>\n )}\n\n {helperText && helperText !== '' && !error && (\n <Text style={[styles.helper, dropdownHelperTextStyle]}>\n {helperText}\n </Text>\n )}\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n label: { marginBottom: 16, color: colors.gray, ...typography.caption },\n inputFocusErrorState: {\n borderWidth: 2,\n borderStyle: 'solid',\n borderColor: colors.red,\n },\n error: { color: colors.red, marginTop: 8, ...typography.caption },\n helper: { marginTop: 8, color: colors.primary, ...typography.caption },\n dropdownInputContainer: { marginBottom: 23, width: '100%' },\n blackText: { color: colors.black },\n});\n\nexport default Dropdown;\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Text, Pressable, ScrollView, StyleSheet, Image, TouchableOpacity } from 'react-native';
|
|
3
|
+
import { colors } from './styles/colors';
|
|
4
|
+
import { inputStyles } from './styles/input';
|
|
5
|
+
|
|
6
|
+
const SelectedItemsView = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
placeholder,
|
|
9
|
+
error,
|
|
10
|
+
getSelectedItemsLabel,
|
|
11
|
+
handleToggleModal,
|
|
12
|
+
isMultiple,
|
|
13
|
+
selectedItem,
|
|
14
|
+
selectedItems,
|
|
15
|
+
dropdownStyle,
|
|
16
|
+
selectedItemStyle,
|
|
17
|
+
multipleSelectedItemStyle,
|
|
18
|
+
dropdownErrorStyle,
|
|
19
|
+
primaryColor,
|
|
20
|
+
disabled
|
|
21
|
+
} = _ref;
|
|
22
|
+
return /*#__PURE__*/React.createElement(Pressable, {
|
|
23
|
+
onPress: () => handleToggleModal(),
|
|
24
|
+
style: _ref2 => {
|
|
25
|
+
let {
|
|
26
|
+
pressed
|
|
27
|
+
} = _ref2;
|
|
28
|
+
return [pressed && { ...inputStyles.inputFocusState,
|
|
29
|
+
borderColor: primaryColor
|
|
30
|
+
}, inputStyles.input, dropdownStyle, error && //this must be last
|
|
31
|
+
error !== '' && !pressed && { ...inputStyles.inputFocusErrorState,
|
|
32
|
+
...dropdownErrorStyle
|
|
33
|
+
}];
|
|
34
|
+
},
|
|
35
|
+
disabled: disabled
|
|
36
|
+
}, /*#__PURE__*/React.createElement(ScrollView, {
|
|
37
|
+
horizontal: true,
|
|
38
|
+
alwaysBounceHorizontal: true,
|
|
39
|
+
showsHorizontalScrollIndicator: false
|
|
40
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
41
|
+
style: styles.selectedItemsContainer,
|
|
42
|
+
onStartShouldSetResponder: () => true
|
|
43
|
+
}, isMultiple ? getSelectedItemsLabel().map((item, i) => /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
44
|
+
onPress: () => handleToggleModal(),
|
|
45
|
+
key: `react-native-input-select-${Math.random()}-${i}`,
|
|
46
|
+
disabled: disabled
|
|
47
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
48
|
+
style: [styles.selectedItems, {
|
|
49
|
+
backgroundColor: primaryColor
|
|
50
|
+
}, multipleSelectedItemStyle]
|
|
51
|
+
}, item))) : /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
52
|
+
onPress: () => handleToggleModal(),
|
|
53
|
+
disabled: disabled
|
|
54
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
55
|
+
style: [styles.blackText, selectedItemStyle]
|
|
56
|
+
}, getSelectedItemsLabel()))), !selectedItem && (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) === 0 && /*#__PURE__*/React.createElement(Text, {
|
|
57
|
+
style: styles.blackText
|
|
58
|
+
}, placeholder !== null && placeholder !== void 0 ? placeholder : 'Select an option')), /*#__PURE__*/React.createElement(View, {
|
|
59
|
+
style: styles.iconStyle
|
|
60
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
61
|
+
source: require('../src/asset/arrow-down.png')
|
|
62
|
+
})));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const styles = StyleSheet.create({
|
|
66
|
+
iconStyle: {
|
|
67
|
+
position: 'absolute',
|
|
68
|
+
right: 25,
|
|
69
|
+
top: 25
|
|
70
|
+
},
|
|
71
|
+
selectedItemsContainer: {
|
|
72
|
+
flexDirection: 'row',
|
|
73
|
+
flexWrap: 'nowrap'
|
|
74
|
+
},
|
|
75
|
+
selectedItems: {
|
|
76
|
+
color: colors.white,
|
|
77
|
+
paddingHorizontal: 10,
|
|
78
|
+
paddingVertical: 5,
|
|
79
|
+
borderRadius: 10,
|
|
80
|
+
backgroundColor: colors.primary,
|
|
81
|
+
marginRight: 10
|
|
82
|
+
},
|
|
83
|
+
blackText: {
|
|
84
|
+
color: colors.black
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
export default SelectedItemsView;
|
|
88
|
+
//# sourceMappingURL=SelectedItemsView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SelectedItemsView.tsx"],"names":["React","View","Text","Pressable","ScrollView","StyleSheet","Image","TouchableOpacity","colors","inputStyles","SelectedItemsView","placeholder","error","getSelectedItemsLabel","handleToggleModal","isMultiple","selectedItem","selectedItems","dropdownStyle","selectedItemStyle","multipleSelectedItemStyle","dropdownErrorStyle","primaryColor","disabled","pressed","inputFocusState","borderColor","input","inputFocusErrorState","styles","selectedItemsContainer","map","item","i","Math","random","backgroundColor","blackText","length","iconStyle","require","create","position","right","top","flexDirection","flexWrap","color","white","paddingHorizontal","paddingVertical","borderRadius","primary","marginRight","black"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SACEC,IADF,EAEEC,IAFF,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,KAAjB;AAAwBC,IAAAA,QAAQ,EAAE;AAAlC,GAFO;AAG/B7B,EAAAA,aAAa,EAAE;AACb8B,IAAAA,KAAK,EAAEvC,MAAM,CAACwC,KADD;AAEbC,IAAAA,iBAAiB,EAAE,EAFN;AAGbC,IAAAA,eAAe,EAAE,CAHJ;AAIbC,IAAAA,YAAY,EAAE,EAJD;AAKbf,IAAAA,eAAe,EAAE5B,MAAM,CAAC4C,OALX;AAMbC,IAAAA,WAAW,EAAE;AANA,GAHgB;AAW/BhB,EAAAA,SAAS,EAAE;AAAEU,IAAAA,KAAK,EAAEvC,MAAM,CAAC8C;AAAhB;AAXoB,CAAlB,CAAf;AAcA,eAAe5C,iBAAf","sourcesContent":["import React from 'react';\nimport {\n View,\n Text,\n Pressable,\n ScrollView,\n StyleSheet,\n Image,\n TouchableOpacity,\n} from 'react-native';\nimport { colors } from './styles/colors';\nimport { inputStyles } from './styles/input';\n\nconst SelectedItemsView = ({\n placeholder,\n error,\n getSelectedItemsLabel,\n handleToggleModal,\n isMultiple,\n selectedItem,\n selectedItems,\n dropdownStyle,\n selectedItemStyle,\n multipleSelectedItemStyle,\n dropdownErrorStyle,\n primaryColor,\n disabled,\n}: any) => {\n return (\n <Pressable\n onPress={() => handleToggleModal()}\n style={({ pressed }) => [\n pressed && {\n ...inputStyles.inputFocusState,\n borderColor: primaryColor,\n },\n inputStyles.input,\n dropdownStyle,\n error && //this must be last\n error !== '' &&\n !pressed && {\n ...inputStyles.inputFocusErrorState,\n ...dropdownErrorStyle,\n },\n ]}\n disabled={disabled}\n >\n <ScrollView\n horizontal\n alwaysBounceHorizontal\n showsHorizontalScrollIndicator={false}\n >\n <View\n style={styles.selectedItemsContainer}\n onStartShouldSetResponder={() => true}\n >\n {isMultiple ? (\n getSelectedItemsLabel().map((item: any, i: Number) => (\n <TouchableOpacity\n onPress={() => handleToggleModal()}\n key={`react-native-input-select-${Math.random()}-${i}`}\n disabled={disabled}\n >\n <Text\n style={[\n styles.selectedItems,\n { backgroundColor: primaryColor },\n multipleSelectedItemStyle,\n ]}\n >\n {item}\n </Text>\n </TouchableOpacity>\n ))\n ) : (\n <TouchableOpacity\n onPress={() => handleToggleModal()}\n disabled={disabled}\n >\n <Text style={[styles.blackText, selectedItemStyle]}>\n {getSelectedItemsLabel()}\n </Text>\n </TouchableOpacity>\n )}\n </View>\n\n {!selectedItem && selectedItems?.length === 0 && (\n <Text style={styles.blackText}>\n {placeholder ?? 'Select an option'}\n </Text>\n )}\n </ScrollView>\n <View style={styles.iconStyle}>\n <Image source={require('../src/asset/arrow-down.png')} />\n </View>\n </Pressable>\n );\n};\n\nconst styles = StyleSheet.create({\n iconStyle: { position: 'absolute', right: 25, top: 25 },\n selectedItemsContainer: { flexDirection: 'row', flexWrap: 'nowrap' },\n selectedItems: {\n color: colors.white,\n paddingHorizontal: 10,\n paddingVertical: 5,\n borderRadius: 10,\n backgroundColor: colors.primary,\n marginRight: 10,\n },\n blackText: { color: colors.black },\n});\n\nexport default SelectedItemsView;\n"]}
|
package/lib/module/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import CustomModal from './Modal';
|
|
|
6
6
|
import DropdownList from './DropdownList';
|
|
7
7
|
import { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';
|
|
8
8
|
import { Input } from './Input';
|
|
9
|
+
import { colors } from './styles/colors';
|
|
9
10
|
export const DropdownSelect = (_ref, rest) => {
|
|
10
11
|
let {
|
|
11
12
|
placeholder,
|
|
@@ -113,6 +114,7 @@ export const DropdownSelect = (_ref, rest) => {
|
|
|
113
114
|
setNewOptions(options);
|
|
114
115
|
};
|
|
115
116
|
|
|
117
|
+
let primary = primaryColor || colors.gray;
|
|
116
118
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropdown, _extends({
|
|
117
119
|
label: label,
|
|
118
120
|
placeholder: placeholder,
|
|
@@ -131,7 +133,7 @@ export const DropdownSelect = (_ref, rest) => {
|
|
|
131
133
|
selectedItemStyle: selectedItemStyle,
|
|
132
134
|
multipleSelectedItemStyle: multipleSelectedItemStyle,
|
|
133
135
|
isMultiple: isMultiple,
|
|
134
|
-
primaryColor:
|
|
136
|
+
primaryColor: primary,
|
|
135
137
|
disabled: disabled
|
|
136
138
|
}, rest)), /*#__PURE__*/React.createElement(CustomModal, {
|
|
137
139
|
open: open,
|
|
@@ -143,7 +145,7 @@ export const DropdownSelect = (_ref, rest) => {
|
|
|
143
145
|
value: searchValue,
|
|
144
146
|
onChangeText: text => onSearch(text),
|
|
145
147
|
style: searchInputStyle,
|
|
146
|
-
primaryColor:
|
|
148
|
+
primaryColor: primary
|
|
147
149
|
}), /*#__PURE__*/React.createElement(DropdownList, {
|
|
148
150
|
options: newOptions,
|
|
149
151
|
optionLabel: optionLabel,
|
|
@@ -153,7 +155,7 @@ export const DropdownSelect = (_ref, rest) => {
|
|
|
153
155
|
selectedItem: selectedItem,
|
|
154
156
|
handleMultipleSelections: handleMultipleSelections,
|
|
155
157
|
handleSingleSelection: handleSingleSelection,
|
|
156
|
-
primaryColor:
|
|
158
|
+
primaryColor: primary
|
|
157
159
|
})));
|
|
158
160
|
};
|
|
159
161
|
export default DropdownSelect;
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["React","useState","Dropdown","CustomModal","DropdownList","DEFAULT_OPTION_LABEL","DEFAULT_OPTION_VALUE","Input","DropdownSelect","rest","placeholder","label","error","helperText","options","optionLabel","optionValue","onValueChange","selectedValue","isMultiple","isSearchable","labelStyle","dropdownStyle","dropdownContainerStyle","dropdownErrorStyle","dropdownErrorTextStyle","dropdownHelperTextStyle","selectedItemStyle","multipleSelectedItemStyle","modalBackgroundStyle","modalOptionsContainer","searchInputStyle","primaryColor","disabled","newOptions","setNewOptions","open","setOpen","selectedItem","setSelectedItem","selectedItems","setSelectedItems","Array","isArray","undefined","searchValue","setSearchValue","handleSingleSelection","value","handleMultipleSelections","selectedValues","includes","filter","item","push","getSelectedItemsLabel","selectedLabels","forEach","element","selectedItemLabel","find","onSearch","searchText","toString","toLocaleLowerCase","trim","regexFilter","RegExp","searchResults","toLowerCase","search","handleToggleModal","text"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,QAAgC,OAAhC;AACA,OAAOC,QAAP,MAAqB,YAArB;AACA,OAAOC,WAAP,MAAwB,SAAxB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,SAASC,oBAAT,EAA+BC,oBAA/B,QAA2D,aAA3D;AAEA,SAASC,KAAT,QAAsB,SAAtB;AAEA,OAAO,MAAMC,cAAc,GAAG,OA2B5BC,IA3B4B,KA4BzB;AAAA,MA3BH;AACEC,IAAAA,WADF;AAEEC,IAAAA,KAFF;AAGEC,IAAAA,KAHF;AAIEC,IAAAA,UAJF;AAKEC,IAAAA,OALF;AAMEC,IAAAA,WANF;AAOEC,IAAAA,WAPF;AAQEC,IAAAA,aARF;AASEC,IAAAA,aATF;AAUEC,IAAAA,UAVF;AAWEC,IAAAA,YAXF;AAYEC,IAAAA,UAZF;AAaEC,IAAAA,aAbF;AAcEC,IAAAA,sBAdF;AAeEC,IAAAA,kBAfF;AAgBEC,IAAAA,sBAhBF;AAiBEC,IAAAA,uBAjBF;AAkBEC,IAAAA,iBAlBF;AAmBEC,IAAAA,yBAnBF;AAoBEC,IAAAA,oBApBF;AAqBEC,IAAAA,qBArBF;AAsBEC,IAAAA,gBAtBF;AAuBEC,IAAAA,YAvBF;AAwBEC,IAAAA;AAxBF,GA2BG;AACH,QAAM,CAACC,UAAD,EAAaC,aAAb,IAA8BlC,QAAQ,CAACa,OAAO,GAAGA,OAAH,GAAa,EAArB,CAA5C;AACA,QAAM,CAACsB,IAAD,EAAOC,OAAP,IAAkBpC,QAAQ,CAAC,KAAD,CAAhC;AACA,QAAM,CAACqC,YAAD,EAAeC,eAAf,IAAkCtC,QAAQ,CAACiB,aAAD,CAAhD,CAHG,CAG8D;;AACjE,QAAM,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C;AAGE,IAAA,KAAK,EAAEzC,gBAHT;AAIE,IAAA,YAAY,EAAEC;AAJhB,IARJ,eAeE,oBAAC,YAAD;AACE,IAAA,OAAO,EAAEE,UADX;AAEE,IAAA,WAAW,EAAEnB,WAFf;AAGE,IAAA,WAAW,EAAEC,WAHf;AAIE,IAAA,UAAU,EAAEG,UAJd;AAKE,IAAA,aAAa,EAAEqB,aALjB;AAME,IAAA,YAAY,EAAEF,YANhB;AAOE,IAAA,wBAAwB,EAAEW,wBAP5B;AAQE,IAAA,qBAAqB,EAAEF,qBARzB;AASE,IAAA,YAAY,EAAEf;AAThB,IAfF,CAvBF,CADF;AAqDD,CAvLM;AAyLP,eAAexB,cAAf","sourcesContent":["import React, { useState } from 'react';\nimport Dropdown from './Dropdown';\nimport CustomModal from './Modal';\nimport DropdownList from './DropdownList';\nimport { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';\nimport type { DropdownProps } from './types/index.types';\nimport { Input } from './Input';\n\nexport const DropdownSelect = (\n {\n placeholder,\n label,\n error,\n helperText,\n options,\n optionLabel,\n optionValue,\n onValueChange,\n selectedValue,\n isMultiple,\n isSearchable,\n labelStyle,\n dropdownStyle,\n dropdownContainerStyle,\n dropdownErrorStyle,\n dropdownErrorTextStyle,\n dropdownHelperTextStyle,\n selectedItemStyle,\n multipleSelectedItemStyle,\n modalBackgroundStyle,\n modalOptionsContainer,\n searchInputStyle,\n primaryColor,\n disabled,\n }: DropdownProps,\n rest: any\n) => {\n const [newOptions, setNewOptions] = useState(options ? options : []);\n const [open, setOpen] = useState(false);\n const [selectedItem, setSelectedItem] = useState(selectedValue); //for single selection\n const [selectedItems, setSelectedItems] = useState(\n Array.isArray(selectedValue)\n ? selectedValue\n : selectedValue === '' || selectedValue === undefined\n ? []\n : [selectedValue]\n ); //for multiple selection\n const [searchValue, setSearchValue] = useState('');\n\n /*===========================================\n * Selection handlers\n *==========================================*/\n const handleSingleSelection = (value: any) => {\n if (selectedItem === value) {\n setSelectedItem(null);\n } else {\n setSelectedItem(value);\n onValueChange(value); //send value to parent\n setOpen(false); //close modal upon selection\n }\n };\n\n const handleMultipleSelections = (value: any) => {\n let selectedValues = [...selectedItems];\n\n if (selectedValues.includes(value)) {\n selectedValues = selectedValues.filter((item) => item !== value);\n } else {\n selectedValues.push(value);\n }\n setSelectedItems(selectedValues);\n };\n\n /*===========================================\n * Get label handler\n *==========================================*/\n const getSelectedItemsLabel = () => {\n if (isMultiple) {\n let selectedLabels: Array<string> = [];\n selectedItems &&\n selectedItems.forEach((element) => {\n let selectedItemLabel =\n options &&\n options.find(\n (item: any) =>\n item[optionValue ?? DEFAULT_OPTION_VALUE] === element\n )?.[optionLabel];\n selectedLabels.push(selectedItemLabel);\n });\n return selectedLabels;\n }\n\n let selectedItemLabel =\n options &&\n options.find(\n (item: any) =>\n item[optionValue ?? DEFAULT_OPTION_VALUE] === selectedItem\n );\n return selectedItemLabel?.[optionLabel ?? DEFAULT_OPTION_LABEL];\n };\n\n /*===========================================\n * Search\n *==========================================*/\n const onSearch = (value: string) => {\n setSearchValue(value);\n\n let searchText = value.toString().toLocaleLowerCase().trim();\n\n const regexFilter = new RegExp(searchText, 'i');\n\n const searchResults = options.filter((item: any) => {\n if (\n item[optionLabel ?? DEFAULT_OPTION_LABEL]\n .toString()\n .toLowerCase()\n .search(regexFilter) !== -1 ||\n item[optionValue ?? DEFAULT_OPTION_VALUE]\n .toString(regexFilter)\n .toLowerCase()\n .search(regexFilter) !== -1\n ) {\n return item;\n }\n });\n\n setNewOptions(searchResults);\n };\n\n /*===========================================\n * Modal\n *==========================================*/\n const handleToggleModal = () => {\n setOpen(!open);\n setSearchValue('');\n setNewOptions(options);\n };\n\n return (\n <>\n <Dropdown\n label={label}\n placeholder={placeholder}\n helperText={helperText}\n error={error}\n getSelectedItemsLabel={getSelectedItemsLabel}\n selectedItem={selectedItem}\n selectedItems={selectedItems}\n handleToggleModal={handleToggleModal}\n labelStyle={labelStyle}\n dropdownStyle={dropdownStyle}\n dropdownContainerStyle={dropdownContainerStyle}\n dropdownErrorStyle={dropdownErrorStyle}\n dropdownErrorTextStyle={dropdownErrorTextStyle}\n dropdownHelperTextStyle={dropdownHelperTextStyle}\n selectedItemStyle={selectedItemStyle}\n multipleSelectedItemStyle={multipleSelectedItemStyle}\n isMultiple={isMultiple}\n primaryColor={primaryColor}\n disabled={disabled}\n {...rest}\n />\n <CustomModal\n open={open}\n handleToggleModal={handleToggleModal}\n modalBackgroundStyle={modalBackgroundStyle}\n modalOptionsContainer={modalOptionsContainer}\n onRequestClose={() => {}}\n >\n {isSearchable && (\n <Input\n value={searchValue}\n onChangeText={(text: string) => onSearch(text)}\n style={searchInputStyle}\n primaryColor={primaryColor}\n />\n )}\n <DropdownList\n options={newOptions}\n optionLabel={optionLabel}\n optionValue={optionValue}\n isMultiple={isMultiple}\n selectedItems={selectedItems}\n selectedItem={selectedItem}\n handleMultipleSelections={handleMultipleSelections}\n handleSingleSelection={handleSingleSelection}\n primaryColor={primaryColor}\n />\n </CustomModal>\n </>\n );\n};\n\nexport default DropdownSelect;\n"]}
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["React","useState","Dropdown","CustomModal","DropdownList","DEFAULT_OPTION_LABEL","DEFAULT_OPTION_VALUE","Input","colors","DropdownSelect","rest","placeholder","label","error","helperText","options","optionLabel","optionValue","onValueChange","selectedValue","isMultiple","isSearchable","labelStyle","dropdownStyle","dropdownContainerStyle","dropdownErrorStyle","dropdownErrorTextStyle","dropdownHelperTextStyle","selectedItemStyle","multipleSelectedItemStyle","modalBackgroundStyle","modalOptionsContainer","searchInputStyle","primaryColor","disabled","newOptions","setNewOptions","open","setOpen","selectedItem","setSelectedItem","selectedItems","setSelectedItems","Array","isArray","undefined","searchValue","setSearchValue","handleSingleSelection","value","handleMultipleSelections","selectedValues","includes","filter","item","push","getSelectedItemsLabel","selectedLabels","forEach","element","selectedItemLabel","find","onSearch","searchText","toString","toLocaleLowerCase","trim","regexFilter","RegExp","search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C;AAGE,IAAA,KAAK,EAAE3C,gBAHT;AAIE,IAAA,YAAY,EAAEyC;AAJhB,IARJ,eAeE,oBAAC,YAAD;AACE,IAAA,OAAO,EAAEtC,UADX;AAEE,IAAA,WAAW,EAAEnB,WAFf;AAGE,IAAA,WAAW,EAAEC,WAHf;AAIE,IAAA,UAAU,EAAEG,UAJd;AAKE,IAAA,aAAa,EAAEqB,aALjB;AAME,IAAA,YAAY,EAAEF,YANhB;AAOE,IAAA,wBAAwB,EAAEW,wBAP5B;AAQE,IAAA,qBAAqB,EAAEF,qBARzB;AASE,IAAA,YAAY,EAAEyB;AAThB,IAfF,CAvBF,CADF;AAqDD,CAxLM;AA0LP,eAAehE,cAAf","sourcesContent":["import React, { useState } from 'react';\nimport Dropdown from './Dropdown';\nimport CustomModal from './Modal';\nimport DropdownList from './DropdownList';\nimport { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';\nimport type { DropdownProps } from './types/index.types';\nimport { Input } from './Input';\nimport { colors } from './styles/colors';\n\nexport const DropdownSelect = (\n {\n placeholder,\n label,\n error,\n helperText,\n options,\n optionLabel,\n optionValue,\n onValueChange,\n selectedValue,\n isMultiple,\n isSearchable,\n labelStyle,\n dropdownStyle,\n dropdownContainerStyle,\n dropdownErrorStyle,\n dropdownErrorTextStyle,\n dropdownHelperTextStyle,\n selectedItemStyle,\n multipleSelectedItemStyle,\n modalBackgroundStyle,\n modalOptionsContainer,\n searchInputStyle,\n primaryColor,\n disabled,\n }: DropdownProps,\n rest: any\n) => {\n const [newOptions, setNewOptions] = useState(options ? options : []);\n const [open, setOpen] = useState(false);\n const [selectedItem, setSelectedItem] = useState(selectedValue); //for single selection\n const [selectedItems, setSelectedItems] = useState(\n Array.isArray(selectedValue)\n ? selectedValue\n : selectedValue === '' || selectedValue === undefined\n ? []\n : [selectedValue]\n ); //for multiple selection\n const [searchValue, setSearchValue] = useState('');\n\n /*===========================================\n * Selection handlers\n *==========================================*/\n const handleSingleSelection = (value: any) => {\n if (selectedItem === value) {\n setSelectedItem(null);\n } else {\n setSelectedItem(value);\n onValueChange(value); //send value to parent\n setOpen(false); //close modal upon selection\n }\n };\n\n const handleMultipleSelections = (value: any) => {\n let selectedValues = [...selectedItems];\n\n if (selectedValues.includes(value)) {\n selectedValues = selectedValues.filter((item) => item !== value);\n } else {\n selectedValues.push(value);\n }\n setSelectedItems(selectedValues);\n };\n\n /*===========================================\n * Get label handler\n *==========================================*/\n const getSelectedItemsLabel = () => {\n if (isMultiple) {\n let selectedLabels: Array<string> = [];\n selectedItems &&\n selectedItems.forEach((element) => {\n let selectedItemLabel =\n options &&\n options.find(\n (item: any) =>\n item[optionValue ?? DEFAULT_OPTION_VALUE] === element\n )?.[optionLabel];\n selectedLabels.push(selectedItemLabel);\n });\n return selectedLabels;\n }\n\n let selectedItemLabel =\n options &&\n options.find(\n (item: any) =>\n item[optionValue ?? DEFAULT_OPTION_VALUE] === selectedItem\n );\n return selectedItemLabel?.[optionLabel ?? DEFAULT_OPTION_LABEL];\n };\n\n /*===========================================\n * Search\n *==========================================*/\n const onSearch = (value: string) => {\n setSearchValue(value);\n\n let searchText = value.toString().toLocaleLowerCase().trim();\n\n const regexFilter = new RegExp(searchText, 'i');\n\n const searchResults = options.filter((item: any) => {\n if (\n item[optionLabel ?? DEFAULT_OPTION_LABEL]\n .toString()\n .toLowerCase()\n .search(regexFilter) !== -1 ||\n item[optionValue ?? DEFAULT_OPTION_VALUE]\n .toString(regexFilter)\n .toLowerCase()\n .search(regexFilter) !== -1\n ) {\n return item;\n }\n });\n\n setNewOptions(searchResults);\n };\n\n /*===========================================\n * Modal\n *==========================================*/\n const handleToggleModal = () => {\n setOpen(!open);\n setSearchValue('');\n setNewOptions(options);\n };\n\n let primary = primaryColor || colors.gray;\n return (\n <>\n <Dropdown\n label={label}\n placeholder={placeholder}\n helperText={helperText}\n error={error}\n getSelectedItemsLabel={getSelectedItemsLabel}\n selectedItem={selectedItem}\n selectedItems={selectedItems}\n handleToggleModal={handleToggleModal}\n labelStyle={labelStyle}\n dropdownStyle={dropdownStyle}\n dropdownContainerStyle={dropdownContainerStyle}\n dropdownErrorStyle={dropdownErrorStyle}\n dropdownErrorTextStyle={dropdownErrorTextStyle}\n dropdownHelperTextStyle={dropdownHelperTextStyle}\n selectedItemStyle={selectedItemStyle}\n multipleSelectedItemStyle={multipleSelectedItemStyle}\n isMultiple={isMultiple}\n primaryColor={primary}\n disabled={disabled}\n {...rest}\n />\n <CustomModal\n open={open}\n handleToggleModal={handleToggleModal}\n modalBackgroundStyle={modalBackgroundStyle}\n modalOptionsContainer={modalOptionsContainer}\n onRequestClose={() => {}}\n >\n {isSearchable && (\n <Input\n value={searchValue}\n onChangeText={(text: string) => onSearch(text)}\n style={searchInputStyle}\n primaryColor={primary}\n />\n )}\n <DropdownList\n options={newOptions}\n optionLabel={optionLabel}\n optionValue={optionValue}\n isMultiple={isMultiple}\n selectedItems={selectedItems}\n selectedItem={selectedItem}\n handleMultipleSelections={handleMultipleSelections}\n handleSingleSelection={handleSingleSelection}\n primaryColor={primary}\n />\n </CustomModal>\n </>\n );\n};\n\nexport default DropdownSelect;\n"]}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
declare const Dropdown: ({ label, placeholder, helperText, error, getSelectedItemsLabel, handleToggleModal, isMultiple, selectedItem, selectedItems, labelStyle, dropdownStyle, dropdownContainerStyle, selectedItemStyle, multipleSelectedItemStyle, dropdownErrorStyle, dropdownErrorTextStyle, dropdownHelperTextStyle, primaryColor, disabled, }: any) => JSX.Element;
|
|
2
3
|
export default Dropdown;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const SelectedItemsView: ({ placeholder, error, getSelectedItemsLabel, handleToggleModal, isMultiple, selectedItem, selectedItems, dropdownStyle, selectedItemStyle, multipleSelectedItemStyle, dropdownErrorStyle, primaryColor, disabled, }: any) => JSX.Element;
|
|
3
|
+
export default SelectedItemsView;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { DropdownProps } from './types/index.types';
|
|
2
3
|
export declare const DropdownSelect: ({ placeholder, label, error, helperText, options, optionLabel, optionValue, onValueChange, selectedValue, isMultiple, isSearchable, labelStyle, dropdownStyle, dropdownContainerStyle, dropdownErrorStyle, dropdownErrorTextStyle, dropdownHelperTextStyle, selectedItemStyle, multipleSelectedItemStyle, modalBackgroundStyle, modalOptionsContainer, searchInputStyle, primaryColor, disabled, }: DropdownProps, rest: any) => JSX.Element;
|
|
3
4
|
export default DropdownSelect;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import type { CSSProperties } from 'react';
|
|
2
2
|
export declare type DropdownProps = {
|
|
3
|
-
placeholder
|
|
4
|
-
label
|
|
5
|
-
error
|
|
6
|
-
helperText
|
|
3
|
+
placeholder?: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
helperText?: string;
|
|
7
7
|
options: any[];
|
|
8
8
|
optionLabel: string;
|
|
9
|
-
optionValue
|
|
9
|
+
optionValue?: string;
|
|
10
10
|
onValueChange: Function;
|
|
11
|
-
selectedValue
|
|
12
|
-
isMultiple
|
|
13
|
-
isSearchable
|
|
14
|
-
labelStyle
|
|
15
|
-
dropdownStyle
|
|
16
|
-
dropdownContainerStyle
|
|
17
|
-
dropdownErrorStyle
|
|
18
|
-
dropdownErrorTextStyle
|
|
19
|
-
dropdownHelperTextStyle
|
|
20
|
-
selectedItemStyle
|
|
21
|
-
multipleSelectedItemStyle
|
|
22
|
-
modalBackgroundStyle
|
|
23
|
-
modalOptionsContainer
|
|
24
|
-
searchInputStyle
|
|
25
|
-
primaryColor
|
|
26
|
-
disabled
|
|
11
|
+
selectedValue?: string | any[] | null;
|
|
12
|
+
isMultiple?: boolean;
|
|
13
|
+
isSearchable?: boolean;
|
|
14
|
+
labelStyle?: CSSProperties;
|
|
15
|
+
dropdownStyle?: CSSProperties;
|
|
16
|
+
dropdownContainerStyle?: CSSProperties;
|
|
17
|
+
dropdownErrorStyle?: CSSProperties;
|
|
18
|
+
dropdownErrorTextStyle?: CSSProperties;
|
|
19
|
+
dropdownHelperTextStyle?: CSSProperties;
|
|
20
|
+
selectedItemStyle?: CSSProperties;
|
|
21
|
+
multipleSelectedItemStyle?: CSSProperties;
|
|
22
|
+
modalBackgroundStyle?: CSSProperties;
|
|
23
|
+
modalOptionsContainer?: CSSProperties;
|
|
24
|
+
searchInputStyle?: CSSProperties;
|
|
25
|
+
primaryColor?: string;
|
|
26
|
+
disabled?: boolean;
|
|
27
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-input-select",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A customizable dropdown selection package for react-native for android and iOS with multiple select and search capabilities.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -32,14 +32,17 @@
|
|
|
32
32
|
"bootstrap": "yarn example && yarn && yarn pods",
|
|
33
33
|
"start": "yarn example start",
|
|
34
34
|
"android": "yarn example android",
|
|
35
|
-
"ios": "yarn example ios"
|
|
35
|
+
"ios": "yarn example ios",
|
|
36
|
+
"clean": "yarn example clean",
|
|
37
|
+
"watchman:clear": "watchman watch-del-all"
|
|
36
38
|
},
|
|
37
39
|
"keywords": [
|
|
38
40
|
"react-native",
|
|
39
41
|
"ios",
|
|
40
42
|
"android",
|
|
41
43
|
"dropdown",
|
|
42
|
-
"selection"
|
|
44
|
+
"selection",
|
|
45
|
+
"multiple select"
|
|
43
46
|
],
|
|
44
47
|
"repository": "https://github.com/azeezat/react-native-select",
|
|
45
48
|
"author": "Azeezat <azeezat94@gmail.com> (https://github.com/azeezat)",
|
|
@@ -56,8 +59,8 @@
|
|
|
56
59
|
"@react-native-community/eslint-config": "^2.0.0",
|
|
57
60
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
58
61
|
"@types/jest": "^26.0.0",
|
|
59
|
-
"@types/react": "
|
|
60
|
-
"@types/react-native": "^0.66.
|
|
62
|
+
"@types/react": "17.0.14",
|
|
63
|
+
"@types/react-native": "^0.66.27",
|
|
61
64
|
"commitlint": "^11.0.0",
|
|
62
65
|
"eslint": "^7.2.0",
|
|
63
66
|
"eslint-config-prettier": "^7.0.0",
|
package/src/Dropdown.tsx
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
Text,
|
|
5
|
-
Pressable,
|
|
6
|
-
ScrollView,
|
|
7
|
-
StyleSheet,
|
|
8
|
-
Image,
|
|
9
|
-
TouchableOpacity,
|
|
10
|
-
} from 'react-native';
|
|
2
|
+
import { View, Text, StyleSheet } from 'react-native';
|
|
3
|
+
import SelectedItemsView from './SelectedItemsView';
|
|
11
4
|
import { colors } from './styles/colors';
|
|
12
|
-
import { inputStyles } from './styles/input';
|
|
13
5
|
import { typography } from './styles/typography';
|
|
14
6
|
|
|
15
7
|
const Dropdown = ({
|
|
@@ -38,73 +30,21 @@ const Dropdown = ({
|
|
|
38
30
|
{label && label !== '' && (
|
|
39
31
|
<Text style={[styles.label, labelStyle]}>{label}</Text>
|
|
40
32
|
)}
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
...dropdownErrorStyle,
|
|
55
|
-
},
|
|
56
|
-
]}
|
|
33
|
+
<SelectedItemsView
|
|
34
|
+
placeholder={placeholder}
|
|
35
|
+
error={error}
|
|
36
|
+
getSelectedItemsLabel={getSelectedItemsLabel}
|
|
37
|
+
handleToggleModal={handleToggleModal}
|
|
38
|
+
isMultiple={isMultiple}
|
|
39
|
+
selectedItem={selectedItem}
|
|
40
|
+
selectedItems={selectedItems}
|
|
41
|
+
dropdownStyle={dropdownStyle}
|
|
42
|
+
selectedItemStyle={selectedItemStyle}
|
|
43
|
+
multipleSelectedItemStyle={multipleSelectedItemStyle}
|
|
44
|
+
dropdownErrorStyle={dropdownErrorStyle}
|
|
45
|
+
primaryColor={primaryColor}
|
|
57
46
|
disabled={disabled}
|
|
58
|
-
|
|
59
|
-
<ScrollView
|
|
60
|
-
horizontal
|
|
61
|
-
alwaysBounceHorizontal
|
|
62
|
-
showsHorizontalScrollIndicator={false}
|
|
63
|
-
>
|
|
64
|
-
<View
|
|
65
|
-
style={styles.selectedItemsContainer}
|
|
66
|
-
onStartShouldSetResponder={() => true}
|
|
67
|
-
>
|
|
68
|
-
{isMultiple ? (
|
|
69
|
-
getSelectedItemsLabel().map((item: any, i: Number) => (
|
|
70
|
-
<TouchableOpacity
|
|
71
|
-
onPress={() => handleToggleModal()}
|
|
72
|
-
key={`SelectedItems${i}`}
|
|
73
|
-
disabled={disabled}
|
|
74
|
-
>
|
|
75
|
-
<Text
|
|
76
|
-
style={[
|
|
77
|
-
styles.selectedItems,
|
|
78
|
-
{ backgroundColor: primaryColor },
|
|
79
|
-
multipleSelectedItemStyle,
|
|
80
|
-
]}
|
|
81
|
-
>
|
|
82
|
-
{item}
|
|
83
|
-
</Text>
|
|
84
|
-
</TouchableOpacity>
|
|
85
|
-
))
|
|
86
|
-
) : (
|
|
87
|
-
<TouchableOpacity
|
|
88
|
-
onPress={() => handleToggleModal()}
|
|
89
|
-
disabled={disabled}
|
|
90
|
-
>
|
|
91
|
-
<Text style={[styles.blackText, selectedItemStyle]}>
|
|
92
|
-
{getSelectedItemsLabel()}
|
|
93
|
-
</Text>
|
|
94
|
-
</TouchableOpacity>
|
|
95
|
-
)}
|
|
96
|
-
</View>
|
|
97
|
-
|
|
98
|
-
{!selectedItem && selectedItems?.length === 0 && (
|
|
99
|
-
<Text style={styles.blackText}>
|
|
100
|
-
{placeholder ?? 'Select an option'}
|
|
101
|
-
</Text>
|
|
102
|
-
)}
|
|
103
|
-
</ScrollView>
|
|
104
|
-
<View style={styles.iconStyle}>
|
|
105
|
-
<Image source={require('../src/asset/arrow-down.png')} />
|
|
106
|
-
</View>
|
|
107
|
-
</Pressable>
|
|
47
|
+
/>
|
|
108
48
|
|
|
109
49
|
{error && error !== '' && (
|
|
110
50
|
<Text style={[styles.error, dropdownErrorTextStyle]}>{error}</Text>
|
|
@@ -126,19 +66,9 @@ const styles = StyleSheet.create({
|
|
|
126
66
|
borderStyle: 'solid',
|
|
127
67
|
borderColor: colors.red,
|
|
128
68
|
},
|
|
129
|
-
iconStyle: { position: 'absolute', right: 25, top: 25 },
|
|
130
69
|
error: { color: colors.red, marginTop: 8, ...typography.caption },
|
|
131
70
|
helper: { marginTop: 8, color: colors.primary, ...typography.caption },
|
|
132
71
|
dropdownInputContainer: { marginBottom: 23, width: '100%' },
|
|
133
|
-
selectedItemsContainer: { flexDirection: 'row', flexWrap: 'nowrap' },
|
|
134
|
-
selectedItems: {
|
|
135
|
-
color: colors.white,
|
|
136
|
-
paddingHorizontal: 10,
|
|
137
|
-
paddingVertical: 5,
|
|
138
|
-
borderRadius: 10,
|
|
139
|
-
backgroundColor: colors.primary,
|
|
140
|
-
marginRight: 10,
|
|
141
|
-
},
|
|
142
72
|
blackText: { color: colors.black },
|
|
143
73
|
});
|
|
144
74
|
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
Pressable,
|
|
6
|
+
ScrollView,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Image,
|
|
9
|
+
TouchableOpacity,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import { colors } from './styles/colors';
|
|
12
|
+
import { inputStyles } from './styles/input';
|
|
13
|
+
|
|
14
|
+
const SelectedItemsView = ({
|
|
15
|
+
placeholder,
|
|
16
|
+
error,
|
|
17
|
+
getSelectedItemsLabel,
|
|
18
|
+
handleToggleModal,
|
|
19
|
+
isMultiple,
|
|
20
|
+
selectedItem,
|
|
21
|
+
selectedItems,
|
|
22
|
+
dropdownStyle,
|
|
23
|
+
selectedItemStyle,
|
|
24
|
+
multipleSelectedItemStyle,
|
|
25
|
+
dropdownErrorStyle,
|
|
26
|
+
primaryColor,
|
|
27
|
+
disabled,
|
|
28
|
+
}: any) => {
|
|
29
|
+
return (
|
|
30
|
+
<Pressable
|
|
31
|
+
onPress={() => handleToggleModal()}
|
|
32
|
+
style={({ pressed }) => [
|
|
33
|
+
pressed && {
|
|
34
|
+
...inputStyles.inputFocusState,
|
|
35
|
+
borderColor: primaryColor,
|
|
36
|
+
},
|
|
37
|
+
inputStyles.input,
|
|
38
|
+
dropdownStyle,
|
|
39
|
+
error && //this must be last
|
|
40
|
+
error !== '' &&
|
|
41
|
+
!pressed && {
|
|
42
|
+
...inputStyles.inputFocusErrorState,
|
|
43
|
+
...dropdownErrorStyle,
|
|
44
|
+
},
|
|
45
|
+
]}
|
|
46
|
+
disabled={disabled}
|
|
47
|
+
>
|
|
48
|
+
<ScrollView
|
|
49
|
+
horizontal
|
|
50
|
+
alwaysBounceHorizontal
|
|
51
|
+
showsHorizontalScrollIndicator={false}
|
|
52
|
+
>
|
|
53
|
+
<View
|
|
54
|
+
style={styles.selectedItemsContainer}
|
|
55
|
+
onStartShouldSetResponder={() => true}
|
|
56
|
+
>
|
|
57
|
+
{isMultiple ? (
|
|
58
|
+
getSelectedItemsLabel().map((item: any, i: Number) => (
|
|
59
|
+
<TouchableOpacity
|
|
60
|
+
onPress={() => handleToggleModal()}
|
|
61
|
+
key={`react-native-input-select-${Math.random()}-${i}`}
|
|
62
|
+
disabled={disabled}
|
|
63
|
+
>
|
|
64
|
+
<Text
|
|
65
|
+
style={[
|
|
66
|
+
styles.selectedItems,
|
|
67
|
+
{ backgroundColor: primaryColor },
|
|
68
|
+
multipleSelectedItemStyle,
|
|
69
|
+
]}
|
|
70
|
+
>
|
|
71
|
+
{item}
|
|
72
|
+
</Text>
|
|
73
|
+
</TouchableOpacity>
|
|
74
|
+
))
|
|
75
|
+
) : (
|
|
76
|
+
<TouchableOpacity
|
|
77
|
+
onPress={() => handleToggleModal()}
|
|
78
|
+
disabled={disabled}
|
|
79
|
+
>
|
|
80
|
+
<Text style={[styles.blackText, selectedItemStyle]}>
|
|
81
|
+
{getSelectedItemsLabel()}
|
|
82
|
+
</Text>
|
|
83
|
+
</TouchableOpacity>
|
|
84
|
+
)}
|
|
85
|
+
</View>
|
|
86
|
+
|
|
87
|
+
{!selectedItem && selectedItems?.length === 0 && (
|
|
88
|
+
<Text style={styles.blackText}>
|
|
89
|
+
{placeholder ?? 'Select an option'}
|
|
90
|
+
</Text>
|
|
91
|
+
)}
|
|
92
|
+
</ScrollView>
|
|
93
|
+
<View style={styles.iconStyle}>
|
|
94
|
+
<Image source={require('../src/asset/arrow-down.png')} />
|
|
95
|
+
</View>
|
|
96
|
+
</Pressable>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const styles = StyleSheet.create({
|
|
101
|
+
iconStyle: { position: 'absolute', right: 25, top: 25 },
|
|
102
|
+
selectedItemsContainer: { flexDirection: 'row', flexWrap: 'nowrap' },
|
|
103
|
+
selectedItems: {
|
|
104
|
+
color: colors.white,
|
|
105
|
+
paddingHorizontal: 10,
|
|
106
|
+
paddingVertical: 5,
|
|
107
|
+
borderRadius: 10,
|
|
108
|
+
backgroundColor: colors.primary,
|
|
109
|
+
marginRight: 10,
|
|
110
|
+
},
|
|
111
|
+
blackText: { color: colors.black },
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export default SelectedItemsView;
|
package/src/index.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import DropdownList from './DropdownList';
|
|
|
5
5
|
import { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';
|
|
6
6
|
import type { DropdownProps } from './types/index.types';
|
|
7
7
|
import { Input } from './Input';
|
|
8
|
+
import { colors } from './styles/colors';
|
|
8
9
|
|
|
9
10
|
export const DropdownSelect = (
|
|
10
11
|
{
|
|
@@ -136,6 +137,7 @@ export const DropdownSelect = (
|
|
|
136
137
|
setNewOptions(options);
|
|
137
138
|
};
|
|
138
139
|
|
|
140
|
+
let primary = primaryColor || colors.gray;
|
|
139
141
|
return (
|
|
140
142
|
<>
|
|
141
143
|
<Dropdown
|
|
@@ -156,7 +158,7 @@ export const DropdownSelect = (
|
|
|
156
158
|
selectedItemStyle={selectedItemStyle}
|
|
157
159
|
multipleSelectedItemStyle={multipleSelectedItemStyle}
|
|
158
160
|
isMultiple={isMultiple}
|
|
159
|
-
primaryColor={
|
|
161
|
+
primaryColor={primary}
|
|
160
162
|
disabled={disabled}
|
|
161
163
|
{...rest}
|
|
162
164
|
/>
|
|
@@ -172,7 +174,7 @@ export const DropdownSelect = (
|
|
|
172
174
|
value={searchValue}
|
|
173
175
|
onChangeText={(text: string) => onSearch(text)}
|
|
174
176
|
style={searchInputStyle}
|
|
175
|
-
primaryColor={
|
|
177
|
+
primaryColor={primary}
|
|
176
178
|
/>
|
|
177
179
|
)}
|
|
178
180
|
<DropdownList
|
|
@@ -184,7 +186,7 @@ export const DropdownSelect = (
|
|
|
184
186
|
selectedItem={selectedItem}
|
|
185
187
|
handleMultipleSelections={handleMultipleSelections}
|
|
186
188
|
handleSingleSelection={handleSingleSelection}
|
|
187
|
-
primaryColor={
|
|
189
|
+
primaryColor={primary}
|
|
188
190
|
/>
|
|
189
191
|
</CustomModal>
|
|
190
192
|
</>
|
package/src/types/index.types.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import type { CSSProperties } from 'react';
|
|
2
2
|
|
|
3
3
|
export type DropdownProps = {
|
|
4
|
-
placeholder
|
|
5
|
-
label
|
|
6
|
-
error
|
|
7
|
-
helperText
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
helperText?: string;
|
|
8
8
|
options: any[];
|
|
9
9
|
optionLabel: string;
|
|
10
|
-
optionValue
|
|
10
|
+
optionValue?: string;
|
|
11
11
|
onValueChange: Function;
|
|
12
|
-
selectedValue
|
|
13
|
-
isMultiple
|
|
14
|
-
isSearchable
|
|
15
|
-
labelStyle
|
|
16
|
-
dropdownStyle
|
|
17
|
-
dropdownContainerStyle
|
|
18
|
-
dropdownErrorStyle
|
|
19
|
-
dropdownErrorTextStyle
|
|
20
|
-
dropdownHelperTextStyle
|
|
21
|
-
selectedItemStyle
|
|
22
|
-
multipleSelectedItemStyle
|
|
23
|
-
modalBackgroundStyle
|
|
24
|
-
modalOptionsContainer
|
|
25
|
-
searchInputStyle
|
|
26
|
-
primaryColor
|
|
27
|
-
disabled
|
|
12
|
+
selectedValue?: string | any[] | null;
|
|
13
|
+
isMultiple?: boolean;
|
|
14
|
+
isSearchable?: boolean;
|
|
15
|
+
labelStyle?: CSSProperties;
|
|
16
|
+
dropdownStyle?: CSSProperties;
|
|
17
|
+
dropdownContainerStyle?: CSSProperties;
|
|
18
|
+
dropdownErrorStyle?: CSSProperties;
|
|
19
|
+
dropdownErrorTextStyle?: CSSProperties;
|
|
20
|
+
dropdownHelperTextStyle?: CSSProperties;
|
|
21
|
+
selectedItemStyle?: CSSProperties;
|
|
22
|
+
multipleSelectedItemStyle?: CSSProperties;
|
|
23
|
+
modalBackgroundStyle?: CSSProperties;
|
|
24
|
+
modalOptionsContainer?: CSSProperties;
|
|
25
|
+
searchInputStyle?: CSSProperties;
|
|
26
|
+
primaryColor?: string;
|
|
27
|
+
disabled?: boolean;
|
|
28
28
|
};
|