@rn-components-dropdown/dropdown 1.0.33 → 1.0.35
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 +6 -9
- package/dist/components/dropdown/Dropdown.js +15 -16
- package/dist/components/dropdown/hooks/useDropdown.js +15 -13
- package/dist/components/dropdown/interface/ChipInterface.d.ts +2 -2
- package/package.json +1 -3
- package/src/components/dropdown/Dropdown.tsx +27 -29
- package/src/components/dropdown/hooks/useDropdown.ts +19 -15
- package/src/components/dropdown/interface/ChipInterface.ts +2 -2
package/README.md
CHANGED
|
@@ -113,15 +113,13 @@ export default function FormScreen() {
|
|
|
113
113
|
<DropdownController
|
|
114
114
|
control={control}
|
|
115
115
|
controller="fruit"
|
|
116
|
-
|
|
117
|
-
data: [
|
|
116
|
+
data={[
|
|
118
117
|
{ id: 1, label: "Apple" },
|
|
119
118
|
{ id: 2, label: "Banana" },
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}}
|
|
119
|
+
]}
|
|
120
|
+
labelField="label"
|
|
121
|
+
valueField= "id"
|
|
122
|
+
placeholder= "Pick a fruit"
|
|
125
123
|
/>
|
|
126
124
|
);
|
|
127
125
|
}
|
|
@@ -136,8 +134,7 @@ export default function FormScreen() {
|
|
|
136
134
|
| control | Control | React Hook Form control object |
|
|
137
135
|
| controller | string | Field name in the form |
|
|
138
136
|
| rules | object | Validation rules (optional) |
|
|
139
|
-
| dropProps
|
|
140
|
-
| defaultValue | any | Initial/default value |
|
|
137
|
+
| ...dropProps | object | All dropdown props |
|
|
141
138
|
|
|
142
139
|
---
|
|
143
140
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { View, Modal, FlatList, StyleSheet, ScrollView, TouchableHighlight, TouchableWithoutFeedback, } from 'react-native';
|
|
2
|
-
import _ from 'lodash';
|
|
3
2
|
import AppText from '../text/AppText';
|
|
4
3
|
import Chip from './component/chip/Chip';
|
|
5
4
|
import React, { useCallback } from 'react';
|
|
@@ -9,8 +8,8 @@ import { useDropdownStyle } from './DropdownStyle';
|
|
|
9
8
|
import SearchInput from './component/input/TextInput';
|
|
10
9
|
import { ArrowDown, ArrowUp, CheckIcon } from '../../assets/svg';
|
|
11
10
|
const DropdownComponent = (props) => {
|
|
12
|
-
const { label, testID, iconStyle, renderItem, style = {}, subfixIcon, labelField, valueField, onChangeText, itemTextStyle, flatListProps, minHeight = 0, containerStyle, search = false, renderLeftIcon, checkIconColor, radioIconColor, multiSelectIcon, itemTestIDField, maxHeight = 300, inverted = true, renderRightIcon, placeholderStyle, inputSearchStyle, searchPlaceholder, selectedTextStyle, renderInputSearch, iconColor = 'gray', accessibilityLabel, itemContainerStyle, labelContainer = {}, labelTextStyle = {}, selectedTextProps = {}, chipContainerProps = {}, keyboardAvoiding = true, selectionType = 'single', activeColor = 'lightGray', dropdownPosition = 'auto', itemAccessibilityLabelField, placeholder = 'Please select', showsVerticalScrollIndicator = true, } = props;
|
|
13
|
-
const { chipColor, clearIcon, textColor
|
|
11
|
+
const { label, testID, iconStyle, renderItem, style = {}, subfixIcon, labelField, valueField, onChangeText, itemTextStyle, flatListProps, minHeight = 0, containerStyle, search = false, renderLeftIcon, checkIconColor, radioIconColor, multiSelectIcon, itemTestIDField, maxHeight = 300, inverted = true, renderRightIcon, placeholderStyle, inputSearchStyle, searchPlaceholder, selectedTextStyle, renderInputSearch, iconColor = 'gray', accessibilityLabel, itemContainerStyle, labelContainer = {}, labelTextStyle = {}, selectedTextProps = {}, chipContainerProps = {}, keyboardAvoiding = true, selectionType = 'single', onClear: onChipClearPress, activeColor = 'lightGray', dropdownPosition = 'auto', itemAccessibilityLabelField, placeholder = 'Please select', showsVerticalScrollIndicator = true, } = props;
|
|
12
|
+
const { chipColor, clearIcon, textColor } = chipContainerProps;
|
|
14
13
|
const { styles, colors } = useDropdownStyle({
|
|
15
14
|
checkIconColor: checkIconColor,
|
|
16
15
|
radioIconColor: radioIconColor,
|
|
@@ -24,7 +23,7 @@ const DropdownComponent = (props) => {
|
|
|
24
23
|
])}/>);
|
|
25
24
|
};
|
|
26
25
|
const _renderDropdown = () => {
|
|
27
|
-
const isSelected = currentValue &&
|
|
26
|
+
const isSelected = currentValue && currentValue?.[valueField];
|
|
28
27
|
return (<TouchableWithoutFeedback testID={testID} accessible={!!accessibilityLabel} accessibilityLabel={accessibilityLabel} onPress={() => (selectionType === 'single' ? showOrClose() : null)}>
|
|
29
28
|
<View style={styles.dropdown}>
|
|
30
29
|
{renderLeftIcon?.(visible)}
|
|
@@ -33,17 +32,15 @@ const DropdownComponent = (props) => {
|
|
|
33
32
|
isSelected !== null ? selectedTextStyle : placeholderStyle,
|
|
34
33
|
font(),
|
|
35
34
|
]} {...selectedTextProps}>
|
|
36
|
-
{isSelected !== null
|
|
37
|
-
? _.get(currentValue, labelField)
|
|
38
|
-
: placeholder}
|
|
35
|
+
{isSelected !== null ? currentValue?.[labelField] : placeholder}
|
|
39
36
|
</AppText>) : currentValue?.length === 0 ? (<AppText style={[styles.textItem, placeholderStyle, font()]} {...selectedTextProps}>
|
|
40
37
|
{placeholder}
|
|
41
38
|
</AppText>) : (<View style={styles.showMultiSelectContainer}>
|
|
42
39
|
<ScrollView showsVerticalScrollIndicator={false}>
|
|
43
40
|
<View style={styles.wraps}>
|
|
44
41
|
{currentValue?.map?.((i) => (<Chip chipColor={chipColor || 'red'} textColor={textColor || 'white'} clearIcon={clearIcon} key={i?.[valueField]} label={i?.[labelField]} onClearPress={() => {
|
|
45
|
-
onClear?.();
|
|
46
42
|
onClearPress?.(i);
|
|
43
|
+
onChipClearPress?.(i?.[valueField]);
|
|
47
44
|
}}/>))}
|
|
48
45
|
</View>
|
|
49
46
|
</ScrollView>
|
|
@@ -58,8 +55,9 @@ const DropdownComponent = (props) => {
|
|
|
58
55
|
</View>);
|
|
59
56
|
}, [styles]);
|
|
60
57
|
const renderCheckItem = useCallback(({ item, index }) => {
|
|
61
|
-
const isSelected =
|
|
62
|
-
return (<TouchableHighlight key={index.toString()} testID={
|
|
58
|
+
const isSelected = currentValue.some((h) => h?.[valueField] === item?.[valueField]);
|
|
59
|
+
return (<TouchableHighlight key={index.toString()} testID={String(item?.[itemTestIDField] || item?.[labelField])} accessible={!!accessibilityLabel} accessibilityLabel={(item?.[itemAccessibilityLabelField] ||
|
|
60
|
+
item?.[labelField])} underlayColor={activeColor} onPress={() => onCheckPress(item)}>
|
|
63
61
|
<View style={StyleSheet.flatten([itemContainerStyle])}>
|
|
64
62
|
{renderItem ? (renderItem(item, isSelected, labelField, valueField)) : (<View style={styles.item}>
|
|
65
63
|
<SvgButton icon={multiSelectIcon ? (multiSelectIcon) : (<CheckIcon color={colors.white}/>)} onPress={() => onCheckPress(item)} style={[
|
|
@@ -77,7 +75,7 @@ const DropdownComponent = (props) => {
|
|
|
77
75
|
itemTextStyle,
|
|
78
76
|
font(),
|
|
79
77
|
])}>
|
|
80
|
-
{
|
|
78
|
+
{String(item?.[labelField])}
|
|
81
79
|
</AppText>
|
|
82
80
|
</View>)}
|
|
83
81
|
</View>
|
|
@@ -101,10 +99,11 @@ const DropdownComponent = (props) => {
|
|
|
101
99
|
onCheckPress,
|
|
102
100
|
]);
|
|
103
101
|
const _renderItem = useCallback(({ item, index }) => {
|
|
104
|
-
const isSelected = currentValue &&
|
|
105
|
-
const selected =
|
|
106
|
-
|
|
107
|
-
return (<TouchableHighlight key={index.toString()} testID={
|
|
102
|
+
const isSelected = currentValue && currentValue?.[valueField];
|
|
103
|
+
const selected = item?.[valueField] === isSelected;
|
|
104
|
+
Object.assign(item, { _index: index });
|
|
105
|
+
return (<TouchableHighlight key={index.toString()} testID={String(item?.[itemTestIDField] || item?.[labelField])} accessible={!!accessibilityLabel} accessibilityLabel={(item?.[itemAccessibilityLabelField] ||
|
|
106
|
+
item?.[labelField])} underlayColor={activeColor} onPress={() => onSelect(item)}>
|
|
108
107
|
<View style={StyleSheet.flatten([itemContainerStyle])}>
|
|
109
108
|
{renderItem ? (renderItem(item, selected, labelField, valueField)) : (<View style={styles.item}>
|
|
110
109
|
{renderRadio(selected)}
|
|
@@ -113,7 +112,7 @@ const DropdownComponent = (props) => {
|
|
|
113
112
|
itemTextStyle,
|
|
114
113
|
font(),
|
|
115
114
|
])}>
|
|
116
|
-
{
|
|
115
|
+
{String(item?.[labelField])}
|
|
117
116
|
</AppText>
|
|
118
117
|
</View>)}
|
|
119
118
|
</View>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
2
|
import { useRef, useState, useEffect, useCallback, useImperativeHandle, } from 'react';
|
|
3
3
|
import { Keyboard, StatusBar, I18nManager, } from 'react-native';
|
|
4
|
-
import _ from 'lodash';
|
|
5
4
|
import { useDetectDevice } from './useDetectDevice';
|
|
6
5
|
import { useDeviceOrientation } from './useOrientation';
|
|
7
6
|
import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../../style';
|
|
@@ -110,8 +109,10 @@ const useDropdown = (props) => {
|
|
|
110
109
|
return;
|
|
111
110
|
}
|
|
112
111
|
else {
|
|
113
|
-
const defaultValue = typeof value === 'object'
|
|
114
|
-
|
|
112
|
+
const defaultValue = typeof value === 'object'
|
|
113
|
+
? valueField && value?.[valueField]
|
|
114
|
+
: value;
|
|
115
|
+
const getItem = data.filter(e => JSON.stringify(defaultValue) === JSON.stringify(e?.[valueField]));
|
|
115
116
|
if (getItem.length > 0) {
|
|
116
117
|
setCurrentValue(getItem[0]);
|
|
117
118
|
}
|
|
@@ -125,8 +126,8 @@ const useDropdown = (props) => {
|
|
|
125
126
|
if (autoScroll && data.length > 0 && listData.length === data.length) {
|
|
126
127
|
setTimeout(() => {
|
|
127
128
|
if (refList && refList?.current) {
|
|
128
|
-
const defaultValue = typeof value === 'object' ?
|
|
129
|
-
const index =
|
|
129
|
+
const defaultValue = typeof value === 'object' ? value?.[valueField] : value;
|
|
130
|
+
const index = listData.findIndex((e) => JSON.stringify(defaultValue) === JSON.stringify(e?.[valueField]));
|
|
130
131
|
if (index > -1 && index <= listData.length - 1) {
|
|
131
132
|
refList?.current?.scrollToIndex({
|
|
132
133
|
index: index,
|
|
@@ -174,11 +175,12 @@ const useDropdown = (props) => {
|
|
|
174
175
|
const onSearch = useCallback((text) => {
|
|
175
176
|
if (text.length > 0) {
|
|
176
177
|
const defaultFilterFunction = (e) => {
|
|
177
|
-
const item =
|
|
178
|
-
?.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
const item = e?.[searchField] ||
|
|
179
|
+
e?.[labelField]
|
|
180
|
+
?.toLowerCase()
|
|
181
|
+
.replace(' ', '')
|
|
182
|
+
.normalize('NFD')
|
|
183
|
+
.replace(/[\u0300-\u036f]/g, '');
|
|
182
184
|
const key = text
|
|
183
185
|
.toLowerCase()
|
|
184
186
|
.replace(' ', '')
|
|
@@ -187,7 +189,7 @@ const useDropdown = (props) => {
|
|
|
187
189
|
return item.indexOf(key) >= 0;
|
|
188
190
|
};
|
|
189
191
|
const propSearchFunction = (e) => {
|
|
190
|
-
const labelText =
|
|
192
|
+
const labelText = e?.[searchField] || e?.[labelField];
|
|
191
193
|
return searchQuery?.(text, labelText);
|
|
192
194
|
};
|
|
193
195
|
const dataSearch = data.filter(searchQuery ? propSearchFunction : defaultFilterFunction);
|
|
@@ -221,7 +223,7 @@ const useDropdown = (props) => {
|
|
|
221
223
|
setCurrentValue?.((prev) => {
|
|
222
224
|
const exists = prev?.some?.((i) => i[valueField] === item[valueField]);
|
|
223
225
|
const va = exists
|
|
224
|
-
?
|
|
226
|
+
? prev?.filter?.(i => i?.[valueField] !== item?.[valueField])
|
|
225
227
|
: [...prev, item];
|
|
226
228
|
const v = va?.map(i => i[valueField]);
|
|
227
229
|
onChange?.(item[valueField], selectionType === 'multi' ? v : item[valueField]);
|
|
@@ -230,7 +232,7 @@ const useDropdown = (props) => {
|
|
|
230
232
|
}, [setCurrentValue, valueField, onChange, currentValue]);
|
|
231
233
|
const onClearPress = useCallback((item) => {
|
|
232
234
|
const updated = currentValue.filter((i) => i[valueField] !== item[valueField]);
|
|
233
|
-
const val =
|
|
235
|
+
const val = updated.map((i) => i[valueField]);
|
|
234
236
|
setCurrentValue(updated);
|
|
235
237
|
onChange?.(item[valueField], val);
|
|
236
238
|
}, [currentValue, valueField, onChange, setCurrentValue]);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ColorValue } from
|
|
1
|
+
import { ColorValue } from 'react-native';
|
|
2
2
|
export interface ChipInterface {
|
|
3
3
|
label?: string;
|
|
4
4
|
chipColor?: ColorValue;
|
|
5
5
|
textColor?: ColorValue;
|
|
6
|
-
onClearPress?: () => void;
|
|
7
6
|
clearIcon?: React.JSX.Element;
|
|
7
|
+
onClearPress?: (item?: any) => void;
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rn-components-dropdown/dropdown",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"homepage": "https://www.npmjs.com/package/@rn-components-dropdown/dropdown",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"description": "Package use for dropdown for single and multi selection with radio and checkbox",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/lodash": "^4.17.20",
|
|
38
37
|
"@types/react": "^19.2.2",
|
|
39
38
|
"typescript": "^5.9.3"
|
|
40
39
|
},
|
|
@@ -44,7 +43,6 @@
|
|
|
44
43
|
"react-native-svg": ">=15.14.0"
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"lodash": "^4.17.21",
|
|
48
46
|
"react-hook-form": "^7.66.0",
|
|
49
47
|
"react-native-svg": ">=15.14.0"
|
|
50
48
|
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
TouchableHighlight,
|
|
9
9
|
TouchableWithoutFeedback,
|
|
10
10
|
} from 'react-native';
|
|
11
|
-
import _ from 'lodash';
|
|
12
11
|
import AppText from '../text/AppText';
|
|
13
12
|
import Chip from './component/chip/Chip';
|
|
14
13
|
import React, { useCallback } from 'react';
|
|
@@ -59,6 +58,7 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
59
58
|
chipContainerProps = {},
|
|
60
59
|
keyboardAvoiding = true,
|
|
61
60
|
selectionType = 'single',
|
|
61
|
+
onClear: onChipClearPress,
|
|
62
62
|
activeColor = 'lightGray',
|
|
63
63
|
dropdownPosition = 'auto',
|
|
64
64
|
itemAccessibilityLabelField,
|
|
@@ -66,12 +66,7 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
66
66
|
showsVerticalScrollIndicator = true,
|
|
67
67
|
} = props;
|
|
68
68
|
|
|
69
|
-
const {
|
|
70
|
-
chipColor,
|
|
71
|
-
clearIcon,
|
|
72
|
-
textColor,
|
|
73
|
-
onClearPress: onClear,
|
|
74
|
-
} = chipContainerProps;
|
|
69
|
+
const { chipColor, clearIcon, textColor } = chipContainerProps;
|
|
75
70
|
|
|
76
71
|
const { styles, colors } = useDropdownStyle({
|
|
77
72
|
checkIconColor: checkIconColor,
|
|
@@ -122,7 +117,7 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
122
117
|
};
|
|
123
118
|
|
|
124
119
|
const _renderDropdown = () => {
|
|
125
|
-
const isSelected: boolean = currentValue &&
|
|
120
|
+
const isSelected: boolean = currentValue && currentValue?.[valueField];
|
|
126
121
|
return (
|
|
127
122
|
<TouchableWithoutFeedback
|
|
128
123
|
testID={testID}
|
|
@@ -141,9 +136,7 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
141
136
|
]}
|
|
142
137
|
{...selectedTextProps}
|
|
143
138
|
>
|
|
144
|
-
{isSelected !== null
|
|
145
|
-
? _.get(currentValue, labelField)
|
|
146
|
-
: placeholder}
|
|
139
|
+
{isSelected !== null ? currentValue?.[labelField] : placeholder}
|
|
147
140
|
</AppText>
|
|
148
141
|
) : currentValue?.length === 0 ? (
|
|
149
142
|
<AppText
|
|
@@ -164,8 +157,8 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
164
157
|
key={i?.[valueField]}
|
|
165
158
|
label={i?.[labelField]}
|
|
166
159
|
onClearPress={() => {
|
|
167
|
-
onClear?.();
|
|
168
160
|
onClearPress?.(i);
|
|
161
|
+
onChipClearPress?.(i?.[valueField]);
|
|
169
162
|
}}
|
|
170
163
|
/>
|
|
171
164
|
))}
|
|
@@ -192,18 +185,21 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
192
185
|
|
|
193
186
|
const renderCheckItem = useCallback(
|
|
194
187
|
({ item, index }: { item: T; index: number }) => {
|
|
195
|
-
const isSelected =
|
|
196
|
-
|
|
188
|
+
const isSelected = currentValue.some(
|
|
189
|
+
(h: any) => h?.[valueField] === item?.[valueField],
|
|
197
190
|
);
|
|
191
|
+
|
|
198
192
|
return (
|
|
199
193
|
<TouchableHighlight
|
|
200
194
|
key={index.toString()}
|
|
201
|
-
testID={
|
|
202
|
-
|
|
203
|
-
accessibilityLabel={_.get(
|
|
204
|
-
item,
|
|
205
|
-
itemAccessibilityLabelField || labelField,
|
|
195
|
+
testID={String(
|
|
196
|
+
item?.[itemTestIDField as keyof T] || item?.[labelField],
|
|
206
197
|
)}
|
|
198
|
+
accessible={!!accessibilityLabel}
|
|
199
|
+
accessibilityLabel={
|
|
200
|
+
(item?.[itemAccessibilityLabelField as keyof T] ||
|
|
201
|
+
item?.[labelField]) as string | undefined
|
|
202
|
+
}
|
|
207
203
|
underlayColor={activeColor}
|
|
208
204
|
onPress={() => onCheckPress(item)}
|
|
209
205
|
>
|
|
@@ -239,7 +235,7 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
239
235
|
font(),
|
|
240
236
|
])}
|
|
241
237
|
>
|
|
242
|
-
{
|
|
238
|
+
{String(item?.[labelField])}
|
|
243
239
|
</AppText>
|
|
244
240
|
</View>
|
|
245
241
|
)}
|
|
@@ -269,18 +265,20 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
269
265
|
|
|
270
266
|
const _renderItem = useCallback(
|
|
271
267
|
({ item, index }: { item: T; index: number }) => {
|
|
272
|
-
const isSelected = currentValue &&
|
|
273
|
-
const selected =
|
|
274
|
-
|
|
268
|
+
const isSelected = currentValue && currentValue?.[valueField];
|
|
269
|
+
const selected = item?.[valueField] === isSelected;
|
|
270
|
+
Object.assign(item as object, { _index: index });
|
|
275
271
|
return (
|
|
276
272
|
<TouchableHighlight
|
|
277
273
|
key={index.toString()}
|
|
278
|
-
testID={
|
|
279
|
-
|
|
280
|
-
accessibilityLabel={_.get(
|
|
281
|
-
item,
|
|
282
|
-
itemAccessibilityLabelField || labelField,
|
|
274
|
+
testID={String(
|
|
275
|
+
item?.[itemTestIDField as keyof T] || item?.[labelField],
|
|
283
276
|
)}
|
|
277
|
+
accessible={!!accessibilityLabel}
|
|
278
|
+
accessibilityLabel={
|
|
279
|
+
(item?.[itemAccessibilityLabelField as keyof T] ||
|
|
280
|
+
item?.[labelField]) as string | undefined
|
|
281
|
+
}
|
|
284
282
|
underlayColor={activeColor}
|
|
285
283
|
onPress={() => onSelect(item)}
|
|
286
284
|
>
|
|
@@ -297,7 +295,7 @@ const DropdownComponent = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
297
295
|
font(),
|
|
298
296
|
])}
|
|
299
297
|
>
|
|
300
|
-
{
|
|
298
|
+
{String(item?.[labelField])}
|
|
301
299
|
</AppText>
|
|
302
300
|
</View>
|
|
303
301
|
)}
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
I18nManager,
|
|
15
15
|
KeyboardEvent,
|
|
16
16
|
} from 'react-native';
|
|
17
|
-
import _ from 'lodash';
|
|
18
17
|
import { useDetectDevice } from './useDetectDevice';
|
|
19
18
|
import { useDeviceOrientation } from './useOrientation';
|
|
20
19
|
import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../../style';
|
|
@@ -181,10 +180,12 @@ const useDropdown = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
181
180
|
return;
|
|
182
181
|
} else {
|
|
183
182
|
const defaultValue =
|
|
184
|
-
typeof value === 'object'
|
|
183
|
+
typeof value === 'object'
|
|
184
|
+
? valueField && value?.[valueField as any]
|
|
185
|
+
: value;
|
|
185
186
|
|
|
186
|
-
const getItem = data.filter(
|
|
187
|
-
|
|
187
|
+
const getItem = data.filter(
|
|
188
|
+
e => JSON.stringify(defaultValue) === JSON.stringify(e?.[valueField]),
|
|
188
189
|
);
|
|
189
190
|
if (getItem.length > 0) {
|
|
190
191
|
setCurrentValue(getItem[0]);
|
|
@@ -201,10 +202,11 @@ const useDropdown = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
201
202
|
setTimeout(() => {
|
|
202
203
|
if (refList && refList?.current) {
|
|
203
204
|
const defaultValue =
|
|
204
|
-
typeof value === 'object' ?
|
|
205
|
+
typeof value === 'object' ? (value as T)?.[valueField] : value;
|
|
205
206
|
|
|
206
|
-
const index =
|
|
207
|
-
|
|
207
|
+
const index = listData.findIndex(
|
|
208
|
+
(e: any) =>
|
|
209
|
+
JSON.stringify(defaultValue) === JSON.stringify(e?.[valueField]),
|
|
208
210
|
);
|
|
209
211
|
if (index > -1 && index <= listData.length - 1) {
|
|
210
212
|
refList?.current?.scrollToIndex({
|
|
@@ -256,11 +258,13 @@ const useDropdown = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
256
258
|
(text: string) => {
|
|
257
259
|
if (text.length > 0) {
|
|
258
260
|
const defaultFilterFunction = (e: any) => {
|
|
259
|
-
const item =
|
|
260
|
-
?.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
261
|
+
const item =
|
|
262
|
+
e?.[searchField] ||
|
|
263
|
+
e?.[labelField]
|
|
264
|
+
?.toLowerCase()
|
|
265
|
+
.replace(' ', '')
|
|
266
|
+
.normalize('NFD')
|
|
267
|
+
.replace(/[\u0300-\u036f]/g, '');
|
|
264
268
|
const key = text
|
|
265
269
|
.toLowerCase()
|
|
266
270
|
.replace(' ', '')
|
|
@@ -271,7 +275,7 @@ const useDropdown = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
271
275
|
};
|
|
272
276
|
|
|
273
277
|
const propSearchFunction = (e: any) => {
|
|
274
|
-
const labelText =
|
|
278
|
+
const labelText = e?.[searchField] || e?.[labelField];
|
|
275
279
|
|
|
276
280
|
return searchQuery?.(text, labelText);
|
|
277
281
|
};
|
|
@@ -319,7 +323,7 @@ const useDropdown = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
319
323
|
(i: any) => i[valueField] === item[valueField],
|
|
320
324
|
);
|
|
321
325
|
const va: T[] = exists
|
|
322
|
-
?
|
|
326
|
+
? prev?.filter?.(i => i?.[valueField] !== item?.[valueField])
|
|
323
327
|
: [...prev, item];
|
|
324
328
|
const v = va?.map(i => i[valueField]);
|
|
325
329
|
onChange?.(
|
|
@@ -337,7 +341,7 @@ const useDropdown = <T, Mode extends SELECTIONS_TYPE>(
|
|
|
337
341
|
const updated = currentValue.filter(
|
|
338
342
|
(i: any) => i[valueField] !== item[valueField],
|
|
339
343
|
);
|
|
340
|
-
const val =
|
|
344
|
+
const val = updated.map((i: any) => i[valueField]);
|
|
341
345
|
setCurrentValue(updated);
|
|
342
346
|
onChange?.(item[valueField] as keyof T, val);
|
|
343
347
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ColorValue } from
|
|
1
|
+
import { ColorValue } from 'react-native';
|
|
2
2
|
|
|
3
3
|
export interface ChipInterface {
|
|
4
4
|
label?: string;
|
|
5
5
|
chipColor?: ColorValue;
|
|
6
6
|
textColor?: ColorValue;
|
|
7
|
-
onClearPress?: () => void;
|
|
8
7
|
clearIcon?: React.JSX.Element;
|
|
8
|
+
onClearPress?: (item?: any) => void;
|
|
9
9
|
}
|