react-native-input-select 0.9.0 → 0.13.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 +13 -10
- package/lib/commonjs/Dropdown.js +17 -8
- package/lib/commonjs/Dropdown.js.map +1 -1
- package/lib/commonjs/index.js +17 -9
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/styles/input.js +5 -0
- package/lib/commonjs/styles/input.js.map +1 -1
- package/lib/commonjs/types/index.types.js +6 -0
- package/lib/commonjs/types/index.types.js.map +1 -0
- package/lib/module/Dropdown.js +17 -8
- package/lib/module/Dropdown.js.map +1 -1
- package/lib/module/index.js +17 -9
- package/lib/module/index.js.map +1 -1
- package/lib/module/styles/input.js +5 -0
- package/lib/module/styles/input.js.map +1 -1
- package/lib/module/types/index.types.js +2 -0
- package/lib/module/types/index.types.js.map +1 -0
- package/lib/typescript/Dropdown.d.ts +1 -1
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/types/index.types.d.ts +27 -0
- package/package.json +3 -4
- package/src/Dropdown.tsx +26 -6
- package/src/index.tsx +42 -29
- package/src/styles/input.ts +5 -0
- package/src/types/index.types.ts +28 -0
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# react-native-select
|
|
1
|
+
# react-native-input-select
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Works perfectly on android and iOS.
|
|
3
|
+
A customizable dropdown selection package for react-native for android and iOS with multiple select and search capabilities.
|
|
5
4
|
|
|
6
5
|
## Installation
|
|
7
6
|
|
|
8
7
|
```sh
|
|
9
8
|
npm install react-native-input-select
|
|
9
|
+
yarn add react-native-input-select
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
## Demo
|
|
@@ -18,16 +18,14 @@ npm install react-native-input-select
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```js
|
|
21
|
-
import
|
|
22
|
-
|
|
23
|
-
import { StyleSheet, View } from 'react-native';
|
|
24
|
-
import DropdownSelect from 'react-native-select';
|
|
21
|
+
import React from 'react';
|
|
22
|
+
import Dropdown from 'react-native-input-select';
|
|
25
23
|
|
|
26
24
|
export default function App() {
|
|
27
25
|
const [country, setCountry] = React.useState<number | undefined>();
|
|
28
26
|
|
|
29
27
|
return (
|
|
30
|
-
<
|
|
28
|
+
<Dropdown
|
|
31
29
|
label="Country"
|
|
32
30
|
placeholder="Select an option..."
|
|
33
31
|
options={[
|
|
@@ -60,18 +58,23 @@ export default function App() {
|
|
|
60
58
|
| options | `Array` | `[{ name: 'Albania', code: 'AL' }, { name: 'Åland Islands', code: 'AX' }]` |
|
|
61
59
|
| optionLabel | `string` | `name` |
|
|
62
60
|
| optionValue | `string` | `code` |
|
|
61
|
+
| error | `string` | `This is a required field` |
|
|
62
|
+
| helperText | `string` | `Only countries in the east are listed` |
|
|
63
63
|
| selectedValue | `string` or `Array` | `AL` or `[AL, AX]` |
|
|
64
64
|
| onValueChange | `function` | `()=>{}` |
|
|
65
65
|
| isMultiple | `Boolean` | `true` |
|
|
66
66
|
| isSearchable | `Boolean` | `true` |
|
|
67
67
|
| labelStyle | `Object` | `{backgroundColor: 'red', borderRadius: 0, ...}` |
|
|
68
|
-
| dropdownStyle | `Object` | `{
|
|
69
|
-
| dropdownContainerStyle | `Object` | `{backgroundColor: 'red',
|
|
68
|
+
| dropdownStyle | `Object` | `{borderColor: 'blue', margin: 5, borderWidth:0 ...}` |
|
|
69
|
+
| dropdownContainerStyle | `Object` | `{backgroundColor: 'red', width: '30%', ...}` |
|
|
70
70
|
| searchInputStyle | `Object` | `{backgroundColor: 'red', borderRadius: 0, ...}` |
|
|
71
71
|
| selectedItemStyle | `Object` | `{backgroundColor: 'red', color: 'yellow', ...}` |
|
|
72
72
|
| multipleSelectedItemStyle | `Object` | `{backgroundColor: 'red', color: 'yellow', ...}` |
|
|
73
73
|
| modalBackgroundStyle | `Object` | `{backgroundColor: 'blue', ...}` |
|
|
74
74
|
| modalOptionsContainer | `Object` | `{padding: 5}` |
|
|
75
|
+
| dropdownErrorStyle | `Object` | `{borderWidth: 2, borderStyle: 'solid'}` |
|
|
76
|
+
| dropdownErrorTextStyle | `Object` | `{color: 'red', fontWeight:500}` |
|
|
77
|
+
| dropdownHelperTextStyle | `Object` | `{color: 'green', fontWeight:500}` |
|
|
75
78
|
| primaryColor | `string` | `blue` |
|
|
76
79
|
|
|
77
80
|
## Contributing
|
package/lib/commonjs/Dropdown.js
CHANGED
|
@@ -33,7 +33,11 @@ const Dropdown = _ref => {
|
|
|
33
33
|
dropdownContainerStyle,
|
|
34
34
|
selectedItemStyle,
|
|
35
35
|
multipleSelectedItemStyle,
|
|
36
|
-
|
|
36
|
+
dropdownErrorStyle,
|
|
37
|
+
dropdownErrorTextStyle,
|
|
38
|
+
dropdownHelperTextStyle,
|
|
39
|
+
primaryColor,
|
|
40
|
+
disabled
|
|
37
41
|
} = _ref;
|
|
38
42
|
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
39
43
|
style: [styles.dropdownInputContainer, dropdownContainerStyle]
|
|
@@ -45,10 +49,14 @@ const Dropdown = _ref => {
|
|
|
45
49
|
let {
|
|
46
50
|
pressed
|
|
47
51
|
} = _ref2;
|
|
48
|
-
return [pressed && _input.inputStyles.inputFocusState
|
|
52
|
+
return [pressed && { ..._input.inputStyles.inputFocusState,
|
|
49
53
|
borderColor: primaryColor
|
|
50
|
-
}, _input.inputStyles.input, dropdownStyle
|
|
51
|
-
|
|
54
|
+
}, _input.inputStyles.input, dropdownStyle, error && //order matters
|
|
55
|
+
error !== '' && !pressed && { ..._input.inputStyles.inputFocusErrorState,
|
|
56
|
+
...dropdownErrorStyle
|
|
57
|
+
}];
|
|
58
|
+
},
|
|
59
|
+
disabled: disabled
|
|
52
60
|
}, /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
|
|
53
61
|
horizontal: true,
|
|
54
62
|
alwaysBounceHorizontal: true,
|
|
@@ -57,9 +65,10 @@ const Dropdown = _ref => {
|
|
|
57
65
|
style: styles.selectedItemsContainer,
|
|
58
66
|
onStartShouldSetResponder: () => true
|
|
59
67
|
}, isMultiple ? getSelectedItemsLabel().map((item, i) => /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
|
|
60
|
-
onPress: () => handleToggleModal()
|
|
61
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
68
|
+
onPress: () => handleToggleModal(),
|
|
62
69
|
key: `SelectedItems${i}`,
|
|
70
|
+
disabled: disabled
|
|
71
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
63
72
|
style: [styles.selectedItems, {
|
|
64
73
|
backgroundColor: primaryColor
|
|
65
74
|
}, multipleSelectedItemStyle]
|
|
@@ -72,9 +81,9 @@ const Dropdown = _ref => {
|
|
|
72
81
|
}, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
|
|
73
82
|
source: require('../src/asset/arrow-down.png')
|
|
74
83
|
}))), error && error !== '' && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
75
|
-
style: styles.error
|
|
84
|
+
style: [styles.error, dropdownErrorTextStyle]
|
|
76
85
|
}, error), helperText && helperText !== '' && !error && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
77
|
-
style: styles.helper
|
|
86
|
+
style: [styles.helper, dropdownHelperTextStyle]
|
|
78
87
|
}, helperText));
|
|
79
88
|
};
|
|
80
89
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Dropdown.tsx"],"names":["Dropdown","label","placeholder","helperText","error","getSelectedItemsLabel","handleToggleModal","isMultiple","selectedItem","selectedItems","labelStyle","dropdownStyle","dropdownContainerStyle","selectedItemStyle","multipleSelectedItemStyle","primaryColor","styles","dropdownInputContainer","pressed","inputStyles","inputFocusState","borderColor","input","selectedItemsContainer","map","item","i","backgroundColor","blackText","length","iconStyle","require","helper","StyleSheet","create","marginBottom","color","colors","gray","typography","caption","
|
|
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","pressed","inputStyles","inputFocusState","borderColor","input","inputFocusErrorState","selectedItemsContainer","map","item","i","backgroundColor","blackText","length","iconStyle","require","helper","StyleSheet","create","marginBottom","color","colors","gray","typography","caption","borderWidth","borderStyle","red","position","right","top","marginTop","primary","width","flexDirection","flexWrap","white","paddingHorizontal","paddingVertical","borderRadius","marginRight","black"],"mappings":";;;;;;;AAAA;;AACA;;AASA;;AACA;;AACA;;;;AAEA,MAAMA,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,YAlBgB;AAmBhBC,IAAAA;AAnBgB,GAoBP;AACT,sBACE,6BAAC,iBAAD;AAAM,IAAA,KAAK,EAAE,CAACC,MAAM,CAACC,sBAAR,EAAgCT,sBAAhC;AAAb,KACGX,KAAK,IAAIA,KAAK,KAAK,EAAnB,iBACC,6BAAC,iBAAD;AAAM,IAAA,KAAK,EAAE,CAACmB,MAAM,CAACnB,KAAR,EAAeS,UAAf;AAAb,KAA0CT,KAA1C,CAFJ,eAI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AOM,GAAhB;AAAqBI,IAAAA,SAAS,EAAE,CAAhC;AAAmC,OAAGR,uBAAWC;AAAjD,GARwB;AAS/BR,EAAAA,MAAM,EAAE;AAAEe,IAAAA,SAAS,EAAE,CAAb;AAAgBX,IAAAA,KAAK,EAAEC,eAAOW,OAA9B;AAAuC,OAAGT,uBAAWC;AAArD,GATuB;AAU/BxB,EAAAA,sBAAsB,EAAE;AAAEmB,IAAAA,YAAY,EAAE,EAAhB;AAAoBc,IAAAA,KAAK,EAAE;AAA3B,GAVO;AAW/B1B,EAAAA,sBAAsB,EAAE;AAAE2B,IAAAA,aAAa,EAAE,KAAjB;AAAwBC,IAAAA,QAAQ,EAAE;AAAlC,GAXO;AAY/B/C,EAAAA,aAAa,EAAE;AACbgC,IAAAA,KAAK,EAAEC,eAAOe,KADD;AAEbC,IAAAA,iBAAiB,EAAE,EAFN;AAGbC,IAAAA,eAAe,EAAE,CAHJ;AAIbC,IAAAA,YAAY,EAAE,EAJD;AAKb5B,IAAAA,eAAe,EAAEU,eAAOW,OALX;AAMbQ,IAAAA,WAAW,EAAE;AANA,GAZgB;AAoB/B5B,EAAAA,SAAS,EAAE;AAAEQ,IAAAA,KAAK,EAAEC,eAAOoB;AAAhB;AApBoB,CAAlB,CAAf;;eAuBe9D,Q","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';\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 <Pressable\n onPress={() => handleToggleModal()}\n style={({ pressed }) => [\n pressed && {\n ...inputStyles.inputFocusState,\n borderColor: primaryColor,\n },\n inputStyles.input,\n dropdownStyle,\n error && //order matters\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={`SelectedItems${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 <Text style={[styles.blackText, selectedItemStyle]}>\n {getSelectedItemsLabel()}\n </Text>\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 {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 iconStyle: { position: 'absolute', right: 25, top: 25 },\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 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 Dropdown;\n"]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -23,7 +23,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
23
23
|
|
|
24
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
27
|
+
|
|
28
|
+
const DropdownSelect = (_ref, rest) => {
|
|
27
29
|
let {
|
|
28
30
|
placeholder,
|
|
29
31
|
label,
|
|
@@ -39,12 +41,16 @@ const DropdownSelect = _ref => {
|
|
|
39
41
|
labelStyle,
|
|
40
42
|
dropdownStyle,
|
|
41
43
|
dropdownContainerStyle,
|
|
44
|
+
dropdownErrorStyle,
|
|
45
|
+
dropdownErrorTextStyle,
|
|
46
|
+
dropdownHelperTextStyle,
|
|
42
47
|
selectedItemStyle,
|
|
43
48
|
multipleSelectedItemStyle,
|
|
44
49
|
modalBackgroundStyle,
|
|
45
50
|
modalOptionsContainer,
|
|
46
51
|
searchInputStyle,
|
|
47
|
-
primaryColor
|
|
52
|
+
primaryColor,
|
|
53
|
+
disabled
|
|
48
54
|
} = _ref;
|
|
49
55
|
const [newOptions, setNewOptions] = (0, _react.useState)(options ? options : []);
|
|
50
56
|
const [open, setOpen] = (0, _react.useState)(false);
|
|
@@ -106,10 +112,8 @@ const DropdownSelect = _ref => {
|
|
|
106
112
|
|
|
107
113
|
const onSearch = value => {
|
|
108
114
|
setSearchValue(value);
|
|
109
|
-
let searchTerm = value.toString().toLocaleLowerCase();
|
|
110
|
-
const searchResults = options.filter(item =>
|
|
111
|
-
return item[optionLabel !== null && optionLabel !== void 0 ? optionLabel : _constants.DEFAULT_OPTION_LABEL].toString().toLowerCase().includes(searchTerm) || item[optionValue !== null && optionValue !== void 0 ? optionValue : _constants.DEFAULT_OPTION_VALUE].toString(searchTerm).toLowerCase().includes();
|
|
112
|
-
});
|
|
115
|
+
let searchTerm = value.toString().toLocaleLowerCase().trim();
|
|
116
|
+
const searchResults = options.filter(item => item[optionLabel !== null && optionLabel !== void 0 ? optionLabel : _constants.DEFAULT_OPTION_LABEL].toString().toLowerCase().includes(searchTerm) || item[optionValue !== null && optionValue !== void 0 ? optionValue : _constants.DEFAULT_OPTION_VALUE].toString(searchTerm).toLowerCase().includes());
|
|
113
117
|
setNewOptions(searchResults);
|
|
114
118
|
};
|
|
115
119
|
/*===========================================
|
|
@@ -123,7 +127,7 @@ const DropdownSelect = _ref => {
|
|
|
123
127
|
setNewOptions(options);
|
|
124
128
|
};
|
|
125
129
|
|
|
126
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Dropdown.default, {
|
|
130
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Dropdown.default, _extends({
|
|
127
131
|
label: label,
|
|
128
132
|
placeholder: placeholder,
|
|
129
133
|
helperText: helperText,
|
|
@@ -135,11 +139,15 @@ const DropdownSelect = _ref => {
|
|
|
135
139
|
labelStyle: labelStyle,
|
|
136
140
|
dropdownStyle: dropdownStyle,
|
|
137
141
|
dropdownContainerStyle: dropdownContainerStyle,
|
|
142
|
+
dropdownErrorStyle: dropdownErrorStyle,
|
|
143
|
+
dropdownErrorTextStyle: dropdownErrorTextStyle,
|
|
144
|
+
dropdownHelperTextStyle: dropdownHelperTextStyle,
|
|
138
145
|
selectedItemStyle: selectedItemStyle,
|
|
139
146
|
multipleSelectedItemStyle: multipleSelectedItemStyle,
|
|
140
147
|
isMultiple: isMultiple,
|
|
141
|
-
primaryColor: primaryColor
|
|
142
|
-
|
|
148
|
+
primaryColor: primaryColor,
|
|
149
|
+
disabled: disabled
|
|
150
|
+
}, rest)), /*#__PURE__*/_react.default.createElement(_Modal.default, {
|
|
143
151
|
open: open,
|
|
144
152
|
handleToggleModal: handleToggleModal,
|
|
145
153
|
modalBackgroundStyle: modalBackgroundStyle,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["DropdownSelect","placeholder","label","error","helperText","options","optionLabel","optionValue","onValueChange","selectedValue","isMultiple","isSearchable","labelStyle","dropdownStyle","dropdownContainerStyle","selectedItemStyle","multipleSelectedItemStyle","modalBackgroundStyle","modalOptionsContainer","searchInputStyle","primaryColor","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","searchTerm","toString","toLocaleLowerCase","searchResults","toLowerCase","handleToggleModal","text"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;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AAEC,iBAZrB;AAaE,IAAA,yBAAyB,EAAEC,yBAb7B;AAcE,IAAA,UAAU,EAAEN,UAdd;AAeE,IAAA,YAAY,EAAEU;AAfhB,IADF,eAkBE,6BAAC,cAAD;AACE,IAAA,IAAI,EAAEG,IADR;AAEE,IAAA,iBAAiB,EAAEiC,iBAFrB;AAGE,IAAA,oBAAoB,EAAEvC,oBAHxB;AAIE,IAAA,qBAAqB,EAAEC,qBAJzB;AAKE,IAAA,cAAc,EAAE,MAAM,CAAE;AAL1B,KAOGP,YAAY,iBACX,6BAAC,YAAD;AACE,IAAA,KAAK,EAAEqB,WADT;AAEE,IAAA,YAAY,EAAGyB,IAAD,IAAkBP,QAAQ,CAACO,IAAD,CAF1C;AAGE,IAAA,KAAK,EAAEtC,gBAHT;AAIE,IAAA,YAAY,EAAEC;AAJhB,IARJ,eAeE,6BAAC,qBAAD;AACE,IAAA,OAAO,EAAEC,UADX;AAEE,IAAA,WAAW,EAAEf,WAFf;AAGE,IAAA,WAAW,EAAEC,WAHf;AAIE,IAAA,UAAU,EAAEG,UAJd;AAKE,IAAA,aAAa,EAAEiB,aALjB;AAME,IAAA,YAAY,EAAEF,YANhB;AAOE,IAAA,wBAAwB,EAAEW,wBAP5B;AAQE,IAAA,qBAAqB,EAAEF,qBARzB;AASE,IAAA,YAAY,EAAEd;AAThB,IAfF,CAlBF,CADF;AAgDD,CArKM;;;eAuKQpB,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 { Input } from './Input';\n\nexport const DropdownSelect = ({\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 selectedItemStyle,\n multipleSelectedItemStyle,\n modalBackgroundStyle,\n modalOptionsContainer,\n searchInputStyle,\n primaryColor,\n}: any) => {\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: string) =>\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: string) =>\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 let searchTerm = value.toString().toLocaleLowerCase();\n const searchResults = options.filter((item: any) => {\n return (\n item[optionLabel ?? DEFAULT_OPTION_LABEL]\n .toString()\n .toLowerCase()\n .includes(searchTerm) ||\n item[optionValue ?? DEFAULT_OPTION_VALUE]\n .toString(searchTerm)\n .toLowerCase()\n .includes()\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 selectedItemStyle={selectedItemStyle}\n multipleSelectedItemStyle={multipleSelectedItemStyle}\n isMultiple={isMultiple}\n primaryColor={primaryColor}\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","searchTerm","toString","toLocaleLowerCase","trim","searchResults","toLowerCase","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;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,qBAASrB,aAAT,CAAxC,CAHG,CAG8D;;AACjE,QAAM,CAACsB,aAAD,EAAgBC,gBAAhB,IAAoC,qBACxCC,KAAK,CAACC,OAAN,CAAczB,aAAd,IACIA,aADJ,GAEIA,aAAa,KAAK,EAAlB,IAAwBA,aAAa,KAAK0B,SAA1C,GACA,EADA,GAEA,CAAC1B,aAAD,CALoC,CAA1C,CAJG,CAUA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CAvBF,CADF;AAqDD,CAjLM;;;eAmLQxB,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 searchTerm = value.toString().toLocaleLowerCase().trim();\n const searchResults = options.filter(\n (item: any) =>\n item[optionLabel ?? DEFAULT_OPTION_LABEL]\n .toString()\n .toLowerCase()\n .includes(searchTerm) ||\n item[optionValue ?? DEFAULT_OPTION_VALUE]\n .toString(searchTerm)\n .toLowerCase()\n .includes()\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"]}
|
|
@@ -21,6 +21,11 @@ const inputStyles = _reactNative.StyleSheet.create({
|
|
|
21
21
|
width: '100%',
|
|
22
22
|
minHeight: 64
|
|
23
23
|
},
|
|
24
|
+
inputFocusErrorState: {
|
|
25
|
+
borderWidth: 2,
|
|
26
|
+
borderStyle: 'solid',
|
|
27
|
+
borderColor: _colors.colors.red
|
|
28
|
+
},
|
|
24
29
|
inputFocusState: {
|
|
25
30
|
borderWidth: 2,
|
|
26
31
|
borderStyle: 'solid',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["input.ts"],"names":["inputStyles","StyleSheet","create","input","paddingVertical","paddingHorizontal","backgroundColor","colors","lightGray","borderRadius","borderColor","dark","borderWidth","color","width","minHeight","
|
|
1
|
+
{"version":3,"sources":["input.ts"],"names":["inputStyles","StyleSheet","create","input","paddingVertical","paddingHorizontal","backgroundColor","colors","lightGray","borderRadius","borderColor","dark","borderWidth","color","width","minHeight","inputFocusErrorState","borderStyle","red","inputFocusState","primary"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,WAAgB,GAAGC,wBAAWC,MAAX,CAAkB;AAChDC,EAAAA,KAAK,EAAE;AACLC,IAAAA,eAAe,EAAE,EADZ;AAELC,IAAAA,iBAAiB,EAAE,EAFd;AAGLC,IAAAA,eAAe,EAAEC,eAAOC,SAHnB;AAILC,IAAAA,YAAY,EAAE,CAJT;AAKLC,IAAAA,WAAW,EAAEH,eAAOI,IALf;AAMLC,IAAAA,WAAW,EAAE,CANR;AAOLC,IAAAA,KAAK,EAAEN,eAAOI,IAPT;AAQLG,IAAAA,KAAK,EAAE,MARF;AASLC,IAAAA,SAAS,EAAE;AATN,GADyC;AAYhDC,EAAAA,oBAAoB,EAAE;AACpBJ,IAAAA,WAAW,EAAE,CADO;AAEpBK,IAAAA,WAAW,EAAE,OAFO;AAGpBP,IAAAA,WAAW,EAAEH,eAAOW;AAHA,GAZ0B;AAiBhDC,EAAAA,eAAe,EAAE;AACfP,IAAAA,WAAW,EAAE,CADE;AAEfK,IAAAA,WAAW,EAAE,OAFE;AAGfP,IAAAA,WAAW,EAAEH,eAAOa;AAHL;AAjB+B,CAAlB,CAAzB","sourcesContent":["import { StyleSheet } from 'react-native';\nimport { colors } from './colors';\n\nexport const inputStyles: any = StyleSheet.create({\n input: {\n paddingVertical: 18,\n paddingHorizontal: 23,\n backgroundColor: colors.lightGray,\n borderRadius: 8,\n borderColor: colors.dark,\n borderWidth: 1,\n color: colors.dark,\n width: '100%',\n minHeight: 64,\n },\n inputFocusErrorState: {\n borderWidth: 2,\n borderStyle: 'solid',\n borderColor: colors.red,\n },\n inputFocusState: {\n borderWidth: 2,\n borderStyle: 'solid',\n borderColor: colors.primary,\n },\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
package/lib/module/Dropdown.js
CHANGED
|
@@ -20,7 +20,11 @@ const Dropdown = _ref => {
|
|
|
20
20
|
dropdownContainerStyle,
|
|
21
21
|
selectedItemStyle,
|
|
22
22
|
multipleSelectedItemStyle,
|
|
23
|
-
|
|
23
|
+
dropdownErrorStyle,
|
|
24
|
+
dropdownErrorTextStyle,
|
|
25
|
+
dropdownHelperTextStyle,
|
|
26
|
+
primaryColor,
|
|
27
|
+
disabled
|
|
24
28
|
} = _ref;
|
|
25
29
|
return /*#__PURE__*/React.createElement(View, {
|
|
26
30
|
style: [styles.dropdownInputContainer, dropdownContainerStyle]
|
|
@@ -32,10 +36,14 @@ const Dropdown = _ref => {
|
|
|
32
36
|
let {
|
|
33
37
|
pressed
|
|
34
38
|
} = _ref2;
|
|
35
|
-
return [pressed && inputStyles.inputFocusState
|
|
39
|
+
return [pressed && { ...inputStyles.inputFocusState,
|
|
36
40
|
borderColor: primaryColor
|
|
37
|
-
}, inputStyles.input, dropdownStyle
|
|
38
|
-
|
|
41
|
+
}, inputStyles.input, dropdownStyle, error && //order matters
|
|
42
|
+
error !== '' && !pressed && { ...inputStyles.inputFocusErrorState,
|
|
43
|
+
...dropdownErrorStyle
|
|
44
|
+
}];
|
|
45
|
+
},
|
|
46
|
+
disabled: disabled
|
|
39
47
|
}, /*#__PURE__*/React.createElement(ScrollView, {
|
|
40
48
|
horizontal: true,
|
|
41
49
|
alwaysBounceHorizontal: true,
|
|
@@ -44,9 +52,10 @@ const Dropdown = _ref => {
|
|
|
44
52
|
style: styles.selectedItemsContainer,
|
|
45
53
|
onStartShouldSetResponder: () => true
|
|
46
54
|
}, isMultiple ? getSelectedItemsLabel().map((item, i) => /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
47
|
-
onPress: () => handleToggleModal()
|
|
48
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
55
|
+
onPress: () => handleToggleModal(),
|
|
49
56
|
key: `SelectedItems${i}`,
|
|
57
|
+
disabled: disabled
|
|
58
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
50
59
|
style: [styles.selectedItems, {
|
|
51
60
|
backgroundColor: primaryColor
|
|
52
61
|
}, multipleSelectedItemStyle]
|
|
@@ -59,9 +68,9 @@ const Dropdown = _ref => {
|
|
|
59
68
|
}, /*#__PURE__*/React.createElement(Image, {
|
|
60
69
|
source: require('../src/asset/arrow-down.png')
|
|
61
70
|
}))), error && error !== '' && /*#__PURE__*/React.createElement(Text, {
|
|
62
|
-
style: styles.error
|
|
71
|
+
style: [styles.error, dropdownErrorTextStyle]
|
|
63
72
|
}, error), helperText && helperText !== '' && !error && /*#__PURE__*/React.createElement(Text, {
|
|
64
|
-
style: styles.helper
|
|
73
|
+
style: [styles.helper, dropdownHelperTextStyle]
|
|
65
74
|
}, helperText));
|
|
66
75
|
};
|
|
67
76
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Dropdown.tsx"],"names":["React","View","Text","Pressable","ScrollView","StyleSheet","Image","TouchableOpacity","colors","inputStyles","typography","Dropdown","label","placeholder","helperText","error","getSelectedItemsLabel","handleToggleModal","isMultiple","selectedItem","selectedItems","labelStyle","dropdownStyle","dropdownContainerStyle","selectedItemStyle","multipleSelectedItemStyle","primaryColor","styles","dropdownInputContainer","pressed","inputFocusState","borderColor","input","selectedItemsContainer","map","item","i","backgroundColor","blackText","length","iconStyle","require","helper","create","marginBottom","color","gray","caption","
|
|
1
|
+
{"version":3,"sources":["Dropdown.tsx"],"names":["React","View","Text","Pressable","ScrollView","StyleSheet","Image","TouchableOpacity","colors","inputStyles","typography","Dropdown","label","placeholder","helperText","error","getSelectedItemsLabel","handleToggleModal","isMultiple","selectedItem","selectedItems","labelStyle","dropdownStyle","dropdownContainerStyle","selectedItemStyle","multipleSelectedItemStyle","dropdownErrorStyle","dropdownErrorTextStyle","dropdownHelperTextStyle","primaryColor","disabled","styles","dropdownInputContainer","pressed","inputFocusState","borderColor","input","inputFocusErrorState","selectedItemsContainer","map","item","i","backgroundColor","blackText","length","iconStyle","require","helper","create","marginBottom","color","gray","caption","borderWidth","borderStyle","red","position","right","top","marginTop","primary","width","flexDirection","flexWrap","white","paddingHorizontal","paddingVertical","borderRadius","marginRight","black"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SACEC,IADF,EAEEC,IAFF,EAGEC,SAHF,EAIEC,UAJF,EAKEC,UALF,EAMEC,KANF,EAOEC,gBAPF,QAQO,cARP;AASA,SAASC,MAAT,QAAuB,iBAAvB;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,UAAT,QAA2B,qBAA3B;;AAEA,MAAMC,QAAQ,GAAG,QAoBN;AAAA,MApBO;AAChBC,IAAAA,KADgB;AAEhBC,IAAAA,WAFgB;AAGh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AAAA,iBAAiB,EAAE,EAFN;AAGbC,IAAAA,eAAe,EAAE,CAHJ;AAIbC,IAAAA,YAAY,EAAE,EAJD;AAKbzB,IAAAA,eAAe,EAAElC,MAAM,CAACoD,OALX;AAMbQ,IAAAA,WAAW,EAAE;AANA,GAZgB;AAoB/BzB,EAAAA,SAAS,EAAE;AAAEO,IAAAA,KAAK,EAAE1C,MAAM,CAAC6D;AAAhB;AApBoB,CAAlB,CAAf;AAuBA,eAAe1D,QAAf","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';\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 <Pressable\n onPress={() => handleToggleModal()}\n style={({ pressed }) => [\n pressed && {\n ...inputStyles.inputFocusState,\n borderColor: primaryColor,\n },\n inputStyles.input,\n dropdownStyle,\n error && //order matters\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={`SelectedItems${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 <Text style={[styles.blackText, selectedItemStyle]}>\n {getSelectedItemsLabel()}\n </Text>\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 {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 iconStyle: { position: 'absolute', right: 25, top: 25 },\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 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 Dropdown;\n"]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
1
3
|
import React, { useState } from 'react';
|
|
2
4
|
import Dropdown from './Dropdown';
|
|
3
5
|
import CustomModal from './Modal';
|
|
4
6
|
import DropdownList from './DropdownList';
|
|
5
7
|
import { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';
|
|
6
8
|
import { Input } from './Input';
|
|
7
|
-
export const DropdownSelect = _ref => {
|
|
9
|
+
export const DropdownSelect = (_ref, rest) => {
|
|
8
10
|
let {
|
|
9
11
|
placeholder,
|
|
10
12
|
label,
|
|
@@ -20,12 +22,16 @@ export const DropdownSelect = _ref => {
|
|
|
20
22
|
labelStyle,
|
|
21
23
|
dropdownStyle,
|
|
22
24
|
dropdownContainerStyle,
|
|
25
|
+
dropdownErrorStyle,
|
|
26
|
+
dropdownErrorTextStyle,
|
|
27
|
+
dropdownHelperTextStyle,
|
|
23
28
|
selectedItemStyle,
|
|
24
29
|
multipleSelectedItemStyle,
|
|
25
30
|
modalBackgroundStyle,
|
|
26
31
|
modalOptionsContainer,
|
|
27
32
|
searchInputStyle,
|
|
28
|
-
primaryColor
|
|
33
|
+
primaryColor,
|
|
34
|
+
disabled
|
|
29
35
|
} = _ref;
|
|
30
36
|
const [newOptions, setNewOptions] = useState(options ? options : []);
|
|
31
37
|
const [open, setOpen] = useState(false);
|
|
@@ -87,10 +93,8 @@ export const DropdownSelect = _ref => {
|
|
|
87
93
|
|
|
88
94
|
const onSearch = value => {
|
|
89
95
|
setSearchValue(value);
|
|
90
|
-
let searchTerm = value.toString().toLocaleLowerCase();
|
|
91
|
-
const searchResults = options.filter(item =>
|
|
92
|
-
return item[optionLabel !== null && optionLabel !== void 0 ? optionLabel : DEFAULT_OPTION_LABEL].toString().toLowerCase().includes(searchTerm) || item[optionValue !== null && optionValue !== void 0 ? optionValue : DEFAULT_OPTION_VALUE].toString(searchTerm).toLowerCase().includes();
|
|
93
|
-
});
|
|
96
|
+
let searchTerm = value.toString().toLocaleLowerCase().trim();
|
|
97
|
+
const searchResults = options.filter(item => item[optionLabel !== null && optionLabel !== void 0 ? optionLabel : DEFAULT_OPTION_LABEL].toString().toLowerCase().includes(searchTerm) || item[optionValue !== null && optionValue !== void 0 ? optionValue : DEFAULT_OPTION_VALUE].toString(searchTerm).toLowerCase().includes());
|
|
94
98
|
setNewOptions(searchResults);
|
|
95
99
|
};
|
|
96
100
|
/*===========================================
|
|
@@ -104,7 +108,7 @@ export const DropdownSelect = _ref => {
|
|
|
104
108
|
setNewOptions(options);
|
|
105
109
|
};
|
|
106
110
|
|
|
107
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropdown, {
|
|
111
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropdown, _extends({
|
|
108
112
|
label: label,
|
|
109
113
|
placeholder: placeholder,
|
|
110
114
|
helperText: helperText,
|
|
@@ -116,11 +120,15 @@ export const DropdownSelect = _ref => {
|
|
|
116
120
|
labelStyle: labelStyle,
|
|
117
121
|
dropdownStyle: dropdownStyle,
|
|
118
122
|
dropdownContainerStyle: dropdownContainerStyle,
|
|
123
|
+
dropdownErrorStyle: dropdownErrorStyle,
|
|
124
|
+
dropdownErrorTextStyle: dropdownErrorTextStyle,
|
|
125
|
+
dropdownHelperTextStyle: dropdownHelperTextStyle,
|
|
119
126
|
selectedItemStyle: selectedItemStyle,
|
|
120
127
|
multipleSelectedItemStyle: multipleSelectedItemStyle,
|
|
121
128
|
isMultiple: isMultiple,
|
|
122
|
-
primaryColor: primaryColor
|
|
123
|
-
|
|
129
|
+
primaryColor: primaryColor,
|
|
130
|
+
disabled: disabled
|
|
131
|
+
}, rest)), /*#__PURE__*/React.createElement(CustomModal, {
|
|
124
132
|
open: open,
|
|
125
133
|
handleToggleModal: handleToggleModal,
|
|
126
134
|
modalBackgroundStyle: modalBackgroundStyle,
|
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","placeholder","label","error","helperText","options","optionLabel","optionValue","onValueChange","selectedValue","isMultiple","isSearchable","labelStyle","dropdownStyle","dropdownContainerStyle","selectedItemStyle","multipleSelectedItemStyle","modalBackgroundStyle","modalOptionsContainer","searchInputStyle","primaryColor","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","searchTerm","toString","toLocaleLowerCase","searchResults","toLowerCase","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;AACA,SAASC,KAAT,QAAsB,SAAtB;AAEA,OAAO,MAAMC,cAAc,GAAG,QAqBnB;AAAA,MArBoB;AAC7BC,IAAAA,WAD6B;AAE7BC,IAAAA,KAF6B;AAG7BC,IAAAA,KAH6B;AAI7BC,IAAAA,UAJ6B;AAK7BC,IAAAA,OAL6B;AAM7BC,IAAAA,WAN6B;AAO7BC,IAAAA,WAP6B;AAQ7BC,IAAAA,aAR6B;AAS7BC,IAAAA,aAT6B;AAU7BC,IAAAA,UAV6B;AAW7BC,IAAAA,YAX6B;AAY7BC,IAAAA,UAZ6B;AAa7BC,IAAAA,aAb6B;AAc7BC,IAAAA,sBAd6B;AAe7BC,IAAAA,iBAf6B;AAgB7BC,IAAAA,yBAhB6B;AAiB7BC,IAAAA,oBAjB6B;AAkB7BC,IAAAA,qBAlB6B;AAmB7BC,IAAAA,gBAnB6B;AAoB7BC,IAAAA;AApB6B,GAqBpB;AACT,QAAM,CAACC,UAAD,EAAaC,aAAb,IAA8B7B,QAAQ,CAACY,O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AEE,IAAA,WAAW,EAAEf,WAFf;AAGE,IAAA,WAAW,EAAEC,WAHf;AAIE,IAAA,UAAU,EAAEG,UAJd;AAKE,IAAA,aAAa,EAAEiB,aALjB;AAME,IAAA,YAAY,EAAEF,YANhB;AAOE,IAAA,wBAAwB,EAAEW,wBAP5B;AAQE,IAAA,qBAAqB,EAAEF,qBARzB;AASE,IAAA,YAAY,EAAEd;AAThB,IAfF,CAlBF,CADF;AAgDD,CArKM;AAuKP,eAAepB,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 { Input } from './Input';\n\nexport const DropdownSelect = ({\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 selectedItemStyle,\n multipleSelectedItemStyle,\n modalBackgroundStyle,\n modalOptionsContainer,\n searchInputStyle,\n primaryColor,\n}: any) => {\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: string) =>\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: string) =>\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 let searchTerm = value.toString().toLocaleLowerCase();\n const searchResults = options.filter((item: any) => {\n return (\n item[optionLabel ?? DEFAULT_OPTION_LABEL]\n .toString()\n .toLowerCase()\n .includes(searchTerm) ||\n item[optionValue ?? DEFAULT_OPTION_VALUE]\n .toString(searchTerm)\n .toLowerCase()\n .includes()\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 selectedItemStyle={selectedItemStyle}\n multipleSelectedItemStyle={multipleSelectedItemStyle}\n isMultiple={isMultiple}\n primaryColor={primaryColor}\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","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","searchTerm","toString","toLocaleLowerCase","trim","searchResults","toLowerCase","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,IAAA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E,IAAA,iBAAiB,EAAEC,iBAfrB;AAgBE,IAAA,yBAAyB,EAAEC,yBAhB7B;AAiBE,IAAA,UAAU,EAAET,UAjBd;AAkBE,IAAA,YAAY,EAAEa,YAlBhB;AAmBE,IAAA,QAAQ,EAAEC;AAnBZ,KAoBMxB,IApBN,EADF,eAuBE,oBAAC,WAAD;AACE,IAAA,IAAI,EAAE2B,IADR;AAEE,IAAA,iBAAiB,EAAEgC,iBAFrB;AAGE,IAAA,oBAAoB,EAAEvC,oBAHxB;AAIE,IAAA,qBAAqB,EAAEC,qBAJzB;AAKE,IAAA,cAAc,EAAE,MAAM,CAAE;AAL1B,KAOGV,YAAY,iBACX,oBAAC,KAAD;AACE,IAAA,KAAK,EAAEyB,WADT;AAEE,IAAA,YAAY,EAAGwB,IAAD,IAAkBR,QAAQ,CAACQ,IAAD,CAF1C;AAGE,IAAA,KAAK,EAAEtC,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,CAjLM;AAmLP,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 searchTerm = value.toString().toLocaleLowerCase().trim();\n const searchResults = options.filter(\n (item: any) =>\n item[optionLabel ?? DEFAULT_OPTION_LABEL]\n .toString()\n .toLowerCase()\n .includes(searchTerm) ||\n item[optionValue ?? DEFAULT_OPTION_VALUE]\n .toString(searchTerm)\n .toLowerCase()\n .includes()\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"]}
|
|
@@ -12,6 +12,11 @@ export const inputStyles = StyleSheet.create({
|
|
|
12
12
|
width: '100%',
|
|
13
13
|
minHeight: 64
|
|
14
14
|
},
|
|
15
|
+
inputFocusErrorState: {
|
|
16
|
+
borderWidth: 2,
|
|
17
|
+
borderStyle: 'solid',
|
|
18
|
+
borderColor: colors.red
|
|
19
|
+
},
|
|
15
20
|
inputFocusState: {
|
|
16
21
|
borderWidth: 2,
|
|
17
22
|
borderStyle: 'solid',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["input.ts"],"names":["StyleSheet","colors","inputStyles","create","input","paddingVertical","paddingHorizontal","backgroundColor","lightGray","borderRadius","borderColor","dark","borderWidth","color","width","minHeight","
|
|
1
|
+
{"version":3,"sources":["input.ts"],"names":["StyleSheet","colors","inputStyles","create","input","paddingVertical","paddingHorizontal","backgroundColor","lightGray","borderRadius","borderColor","dark","borderWidth","color","width","minHeight","inputFocusErrorState","borderStyle","red","inputFocusState","primary"],"mappings":"AAAA,SAASA,UAAT,QAA2B,cAA3B;AACA,SAASC,MAAT,QAAuB,UAAvB;AAEA,OAAO,MAAMC,WAAgB,GAAGF,UAAU,CAACG,MAAX,CAAkB;AAChDC,EAAAA,KAAK,EAAE;AACLC,IAAAA,eAAe,EAAE,EADZ;AAELC,IAAAA,iBAAiB,EAAE,EAFd;AAGLC,IAAAA,eAAe,EAAEN,MAAM,CAACO,SAHnB;AAILC,IAAAA,YAAY,EAAE,CAJT;AAKLC,IAAAA,WAAW,EAAET,MAAM,CAACU,IALf;AAMLC,IAAAA,WAAW,EAAE,CANR;AAOLC,IAAAA,KAAK,EAAEZ,MAAM,CAACU,IAPT;AAQLG,IAAAA,KAAK,EAAE,MARF;AASLC,IAAAA,SAAS,EAAE;AATN,GADyC;AAYhDC,EAAAA,oBAAoB,EAAE;AACpBJ,IAAAA,WAAW,EAAE,CADO;AAEpBK,IAAAA,WAAW,EAAE,OAFO;AAGpBP,IAAAA,WAAW,EAAET,MAAM,CAACiB;AAHA,GAZ0B;AAiBhDC,EAAAA,eAAe,EAAE;AACfP,IAAAA,WAAW,EAAE,CADE;AAEfK,IAAAA,WAAW,EAAE,OAFE;AAGfP,IAAAA,WAAW,EAAET,MAAM,CAACmB;AAHL;AAjB+B,CAAlB,CAAzB","sourcesContent":["import { StyleSheet } from 'react-native';\nimport { colors } from './colors';\n\nexport const inputStyles: any = StyleSheet.create({\n input: {\n paddingVertical: 18,\n paddingHorizontal: 23,\n backgroundColor: colors.lightGray,\n borderRadius: 8,\n borderColor: colors.dark,\n borderWidth: 1,\n color: colors.dark,\n width: '100%',\n minHeight: 64,\n },\n inputFocusErrorState: {\n borderWidth: 2,\n borderStyle: 'solid',\n borderColor: colors.red,\n },\n inputFocusState: {\n borderWidth: 2,\n borderStyle: 'solid',\n borderColor: colors.primary,\n },\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const Dropdown: ({ label, placeholder, helperText, error, getSelectedItemsLabel, handleToggleModal, isMultiple, selectedItem, selectedItems, labelStyle, dropdownStyle, dropdownContainerStyle, selectedItemStyle, multipleSelectedItemStyle, primaryColor, }: any) => JSX.Element;
|
|
1
|
+
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
2
|
export default Dropdown;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { DropdownProps } from './types/index.types';
|
|
2
|
+
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;
|
|
2
3
|
export default DropdownSelect;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
export declare type DropdownProps = {
|
|
3
|
+
placeholder: string;
|
|
4
|
+
label: string;
|
|
5
|
+
error: string;
|
|
6
|
+
helperText: string;
|
|
7
|
+
options: any[];
|
|
8
|
+
optionLabel: string;
|
|
9
|
+
optionValue: string;
|
|
10
|
+
onValueChange: Function;
|
|
11
|
+
selectedValue: string | any[] | null;
|
|
12
|
+
isMultiple: boolean;
|
|
13
|
+
isSearchable: boolean;
|
|
14
|
+
labelStyle: string;
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-input-select",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.13.0",
|
|
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",
|
|
7
7
|
"types": "lib/typescript/index.d.ts",
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
"ios",
|
|
40
40
|
"android",
|
|
41
41
|
"dropdown",
|
|
42
|
-
"selection"
|
|
43
|
-
"multiple selection"
|
|
42
|
+
"selection"
|
|
44
43
|
],
|
|
45
44
|
"repository": "https://github.com/azeezat/react-native-select",
|
|
46
45
|
"author": "Azeezat <azeezat94@gmail.com> (https://github.com/azeezat)",
|
package/src/Dropdown.tsx
CHANGED
|
@@ -27,7 +27,11 @@ const Dropdown = ({
|
|
|
27
27
|
dropdownContainerStyle,
|
|
28
28
|
selectedItemStyle,
|
|
29
29
|
multipleSelectedItemStyle,
|
|
30
|
+
dropdownErrorStyle,
|
|
31
|
+
dropdownErrorTextStyle,
|
|
32
|
+
dropdownHelperTextStyle,
|
|
30
33
|
primaryColor,
|
|
34
|
+
disabled,
|
|
31
35
|
}: any) => {
|
|
32
36
|
return (
|
|
33
37
|
<View style={[styles.dropdownInputContainer, dropdownContainerStyle]}>
|
|
@@ -37,11 +41,20 @@ const Dropdown = ({
|
|
|
37
41
|
<Pressable
|
|
38
42
|
onPress={() => handleToggleModal()}
|
|
39
43
|
style={({ pressed }) => [
|
|
40
|
-
pressed &&
|
|
41
|
-
inputStyles.inputFocusState
|
|
44
|
+
pressed && {
|
|
45
|
+
...inputStyles.inputFocusState,
|
|
46
|
+
borderColor: primaryColor,
|
|
47
|
+
},
|
|
42
48
|
inputStyles.input,
|
|
43
49
|
dropdownStyle,
|
|
50
|
+
error && //order matters
|
|
51
|
+
error !== '' &&
|
|
52
|
+
!pressed && {
|
|
53
|
+
...inputStyles.inputFocusErrorState,
|
|
54
|
+
...dropdownErrorStyle,
|
|
55
|
+
},
|
|
44
56
|
]}
|
|
57
|
+
disabled={disabled}
|
|
45
58
|
>
|
|
46
59
|
<ScrollView
|
|
47
60
|
horizontal
|
|
@@ -54,9 +67,12 @@ const Dropdown = ({
|
|
|
54
67
|
>
|
|
55
68
|
{isMultiple ? (
|
|
56
69
|
getSelectedItemsLabel().map((item: any, i: Number) => (
|
|
57
|
-
<TouchableOpacity
|
|
70
|
+
<TouchableOpacity
|
|
71
|
+
onPress={() => handleToggleModal()}
|
|
72
|
+
key={`SelectedItems${i}`}
|
|
73
|
+
disabled={disabled}
|
|
74
|
+
>
|
|
58
75
|
<Text
|
|
59
|
-
key={`SelectedItems${i}`}
|
|
60
76
|
style={[
|
|
61
77
|
styles.selectedItems,
|
|
62
78
|
{ backgroundColor: primaryColor },
|
|
@@ -85,10 +101,14 @@ const Dropdown = ({
|
|
|
85
101
|
</View>
|
|
86
102
|
</Pressable>
|
|
87
103
|
|
|
88
|
-
{error && error !== '' &&
|
|
104
|
+
{error && error !== '' && (
|
|
105
|
+
<Text style={[styles.error, dropdownErrorTextStyle]}>{error}</Text>
|
|
106
|
+
)}
|
|
89
107
|
|
|
90
108
|
{helperText && helperText !== '' && !error && (
|
|
91
|
-
<Text style={styles.helper}>
|
|
109
|
+
<Text style={[styles.helper, dropdownHelperTextStyle]}>
|
|
110
|
+
{helperText}
|
|
111
|
+
</Text>
|
|
92
112
|
)}
|
|
93
113
|
</View>
|
|
94
114
|
);
|
package/src/index.tsx
CHANGED
|
@@ -3,30 +3,38 @@ import Dropdown from './Dropdown';
|
|
|
3
3
|
import CustomModal from './Modal';
|
|
4
4
|
import DropdownList from './DropdownList';
|
|
5
5
|
import { DEFAULT_OPTION_LABEL, DEFAULT_OPTION_VALUE } from './constants';
|
|
6
|
+
import type { DropdownProps } from './types/index.types';
|
|
6
7
|
import { Input } from './Input';
|
|
7
8
|
|
|
8
|
-
export const DropdownSelect = (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
9
|
+
export const DropdownSelect = (
|
|
10
|
+
{
|
|
11
|
+
placeholder,
|
|
12
|
+
label,
|
|
13
|
+
error,
|
|
14
|
+
helperText,
|
|
15
|
+
options,
|
|
16
|
+
optionLabel,
|
|
17
|
+
optionValue,
|
|
18
|
+
onValueChange,
|
|
19
|
+
selectedValue,
|
|
20
|
+
isMultiple,
|
|
21
|
+
isSearchable,
|
|
22
|
+
labelStyle,
|
|
23
|
+
dropdownStyle,
|
|
24
|
+
dropdownContainerStyle,
|
|
25
|
+
dropdownErrorStyle,
|
|
26
|
+
dropdownErrorTextStyle,
|
|
27
|
+
dropdownHelperTextStyle,
|
|
28
|
+
selectedItemStyle,
|
|
29
|
+
multipleSelectedItemStyle,
|
|
30
|
+
modalBackgroundStyle,
|
|
31
|
+
modalOptionsContainer,
|
|
32
|
+
searchInputStyle,
|
|
33
|
+
primaryColor,
|
|
34
|
+
disabled,
|
|
35
|
+
}: DropdownProps,
|
|
36
|
+
rest: any
|
|
37
|
+
) => {
|
|
30
38
|
const [newOptions, setNewOptions] = useState(options ? options : []);
|
|
31
39
|
const [open, setOpen] = useState(false);
|
|
32
40
|
const [selectedItem, setSelectedItem] = useState(selectedValue); //for single selection
|
|
@@ -74,7 +82,7 @@ export const DropdownSelect = ({
|
|
|
74
82
|
let selectedItemLabel =
|
|
75
83
|
options &&
|
|
76
84
|
options.find(
|
|
77
|
-
(item:
|
|
85
|
+
(item: any) =>
|
|
78
86
|
item[optionValue ?? DEFAULT_OPTION_VALUE] === element
|
|
79
87
|
)?.[optionLabel];
|
|
80
88
|
selectedLabels.push(selectedItemLabel);
|
|
@@ -85,7 +93,7 @@ export const DropdownSelect = ({
|
|
|
85
93
|
let selectedItemLabel =
|
|
86
94
|
options &&
|
|
87
95
|
options.find(
|
|
88
|
-
(item:
|
|
96
|
+
(item: any) =>
|
|
89
97
|
item[optionValue ?? DEFAULT_OPTION_VALUE] === selectedItem
|
|
90
98
|
);
|
|
91
99
|
return selectedItemLabel?.[optionLabel ?? DEFAULT_OPTION_LABEL];
|
|
@@ -96,9 +104,10 @@ export const DropdownSelect = ({
|
|
|
96
104
|
*==========================================*/
|
|
97
105
|
const onSearch = (value: string) => {
|
|
98
106
|
setSearchValue(value);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
|
|
108
|
+
let searchTerm = value.toString().toLocaleLowerCase().trim();
|
|
109
|
+
const searchResults = options.filter(
|
|
110
|
+
(item: any) =>
|
|
102
111
|
item[optionLabel ?? DEFAULT_OPTION_LABEL]
|
|
103
112
|
.toString()
|
|
104
113
|
.toLowerCase()
|
|
@@ -107,8 +116,7 @@ export const DropdownSelect = ({
|
|
|
107
116
|
.toString(searchTerm)
|
|
108
117
|
.toLowerCase()
|
|
109
118
|
.includes()
|
|
110
|
-
|
|
111
|
-
});
|
|
119
|
+
);
|
|
112
120
|
|
|
113
121
|
setNewOptions(searchResults);
|
|
114
122
|
};
|
|
@@ -136,10 +144,15 @@ export const DropdownSelect = ({
|
|
|
136
144
|
labelStyle={labelStyle}
|
|
137
145
|
dropdownStyle={dropdownStyle}
|
|
138
146
|
dropdownContainerStyle={dropdownContainerStyle}
|
|
147
|
+
dropdownErrorStyle={dropdownErrorStyle}
|
|
148
|
+
dropdownErrorTextStyle={dropdownErrorTextStyle}
|
|
149
|
+
dropdownHelperTextStyle={dropdownHelperTextStyle}
|
|
139
150
|
selectedItemStyle={selectedItemStyle}
|
|
140
151
|
multipleSelectedItemStyle={multipleSelectedItemStyle}
|
|
141
152
|
isMultiple={isMultiple}
|
|
142
153
|
primaryColor={primaryColor}
|
|
154
|
+
disabled={disabled}
|
|
155
|
+
{...rest}
|
|
143
156
|
/>
|
|
144
157
|
<CustomModal
|
|
145
158
|
open={open}
|
package/src/styles/input.ts
CHANGED
|
@@ -13,6 +13,11 @@ export const inputStyles: any = StyleSheet.create({
|
|
|
13
13
|
width: '100%',
|
|
14
14
|
minHeight: 64,
|
|
15
15
|
},
|
|
16
|
+
inputFocusErrorState: {
|
|
17
|
+
borderWidth: 2,
|
|
18
|
+
borderStyle: 'solid',
|
|
19
|
+
borderColor: colors.red,
|
|
20
|
+
},
|
|
16
21
|
inputFocusState: {
|
|
17
22
|
borderWidth: 2,
|
|
18
23
|
borderStyle: 'solid',
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
export type DropdownProps = {
|
|
4
|
+
placeholder: string;
|
|
5
|
+
label: string;
|
|
6
|
+
error: string;
|
|
7
|
+
helperText: string;
|
|
8
|
+
options: any[];
|
|
9
|
+
optionLabel: string;
|
|
10
|
+
optionValue: string;
|
|
11
|
+
onValueChange: Function;
|
|
12
|
+
selectedValue: string | any[] | null;
|
|
13
|
+
isMultiple: boolean;
|
|
14
|
+
isSearchable: boolean;
|
|
15
|
+
labelStyle: string;
|
|
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
|
+
};
|