@rn-components-dropdown/dropdown 1.0.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/dist/components/dropdown/Dropdown.d.ts +4 -0
- package/dist/components/dropdown/Dropdown.js +313 -0
- package/dist/components/dropdown/DropdownStyle.d.ts +151 -0
- package/dist/components/dropdown/DropdownStyle.js +148 -0
- package/dist/components/dropdown/components/chip/Chip.d.ts +3 -0
- package/dist/components/dropdown/components/chip/Chip.js +22 -0
- package/dist/components/dropdown/components/chip/ChipStyle.d.ts +84 -0
- package/dist/components/dropdown/components/chip/ChipStyle.js +63 -0
- package/dist/components/dropdown/components/input/TextInput.d.ts +3 -0
- package/dist/components/dropdown/components/input/TextInput.js +60 -0
- package/dist/components/dropdown/components/input/TextInputStyle.d.ts +32 -0
- package/dist/components/dropdown/components/input/TextInputStyle.js +33 -0
- package/dist/components/dropdown/hooks/useDetectDevice.d.ts +3 -0
- package/dist/components/dropdown/hooks/useDetectDevice.js +22 -0
- package/dist/components/dropdown/hooks/useDropdown.d.ts +26 -0
- package/dist/components/dropdown/hooks/useDropdown.js +263 -0
- package/dist/components/dropdown/hooks/useOrientation.d.ts +1 -0
- package/dist/components/dropdown/hooks/useOrientation.js +30 -0
- package/dist/components/dropdown/interface/ChipInterface.d.ts +8 -0
- package/dist/components/dropdown/interface/ChipInterface.js +2 -0
- package/dist/components/dropdown/interface/DropdownInterface.d.ts +71 -0
- package/dist/components/dropdown/interface/DropdownInterface.js +2 -0
- package/dist/components/dropdown/interface/InputProps.d.ts +8 -0
- package/dist/components/dropdown/interface/InputProps.js +2 -0
- package/dist/components/svgButton/SvgButton.d.ts +11 -0
- package/dist/components/svgButton/SvgButton.js +16 -0
- package/dist/components/svgButton/SvgButtonStyle.d.ts +28 -0
- package/dist/components/svgButton/SvgButtonStyle.js +29 -0
- package/dist/components/text/AppText.d.ts +12 -0
- package/dist/components/text/AppText.js +24 -0
- package/dist/components/text/AppTextStyle.d.ts +171 -0
- package/dist/components/text/AppTextStyle.js +27 -0
- package/dist/components/textInput/AppTextInput.d.ts +20 -0
- package/dist/components/textInput/AppTextInput.js +89 -0
- package/dist/components/textInput/AppTextInputStyle.d.ts +79 -0
- package/dist/components/textInput/AppTextInputStyle.js +61 -0
- package/dist/controller/dropDownController/DropdownController.d.ts +10 -0
- package/dist/controller/dropDownController/DropdownController.js +25 -0
- package/dist/controller/dropDownController/DropdownControllerStyle.d.ts +50 -0
- package/dist/controller/dropDownController/DropdownControllerStyle.js +48 -0
- package/dist/controller/textInputController/AppTextInputController.d.ts +13 -0
- package/dist/controller/textInputController/AppTextInputController.js +14 -0
- package/dist/controller/textInputController/InputControllerStyle.d.ts +31 -0
- package/dist/controller/textInputController/InputControllerStyle.js +29 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -0
- package/dist/interface/colors.interface.d.ts +20 -0
- package/dist/interface/colors.interface.js +2 -0
- package/dist/style/colors.d.ts +33 -0
- package/dist/style/colors.js +44 -0
- package/dist/style/index.d.ts +7 -0
- package/dist/style/index.js +29 -0
- package/dist/style/shadow.d.ts +161 -0
- package/dist/style/shadow.js +158 -0
- package/dist/style/spacing.d.ts +23 -0
- package/dist/style/spacing.js +26 -0
- package/package.json +33 -0
- package/src/components/dropdown/Dropdown.tsx +512 -0
- package/src/components/dropdown/DropdownStyle.ts +154 -0
- package/src/components/dropdown/components/chip/Chip.tsx +31 -0
- package/src/components/dropdown/components/chip/ChipStyle.ts +64 -0
- package/src/components/dropdown/components/input/TextInput.tsx +46 -0
- package/src/components/dropdown/components/input/TextInputStyle.ts +32 -0
- package/src/components/dropdown/hooks/useDetectDevice.ts +25 -0
- package/src/components/dropdown/hooks/useDropdown.ts +356 -0
- package/src/components/dropdown/hooks/useOrientation.ts +36 -0
- package/src/components/dropdown/interface/ChipInterface.ts +9 -0
- package/src/components/dropdown/interface/DropdownInterface.ts +90 -0
- package/src/components/dropdown/interface/InputProps.ts +9 -0
- package/src/components/svgButton/SvgButton.tsx +37 -0
- package/src/components/svgButton/SvgButtonStyle.ts +27 -0
- package/src/components/text/AppText.tsx +41 -0
- package/src/components/text/AppTextStyle.ts +40 -0
- package/src/components/textInput/AppTextInput.tsx +148 -0
- package/src/components/textInput/AppTextInputStyle.ts +72 -0
- package/src/controller/dropDownController/DropdownController.tsx +81 -0
- package/src/controller/dropDownController/DropdownControllerStyle.ts +47 -0
- package/src/controller/textInputController/AppTextInputController.tsx +50 -0
- package/src/controller/textInputController/InputControllerStyle.ts +28 -0
- package/src/index.ts +5 -0
- package/src/interface/colors.interface.ts +22 -0
- package/src/style/colors.ts +46 -0
- package/src/style/index.ts +14 -0
- package/src/style/shadow.ts +155 -0
- package/src/style/spacing.ts +23 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
View,
|
|
5
|
+
Modal,
|
|
6
|
+
FlatList,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
ScrollView,
|
|
10
|
+
TouchableHighlight,
|
|
11
|
+
TouchableWithoutFeedback,
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
import _ from 'lodash';
|
|
14
|
+
import AppText from '../text/AppText';
|
|
15
|
+
import Chip from './components/chip/Chip';
|
|
16
|
+
import useDropdown from './hooks/useDropdown';
|
|
17
|
+
import SvgButton from '../svgButton/SvgButton';
|
|
18
|
+
import { useDropdownStyle } from './DropdownStyle';
|
|
19
|
+
import SearchInput from './components/input/TextInput';
|
|
20
|
+
import { DropdownProps } from './interface/DropdownInterface';
|
|
21
|
+
|
|
22
|
+
const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
|
|
23
|
+
props: DropdownProps<T, Mode>,
|
|
24
|
+
) => {
|
|
25
|
+
const {
|
|
26
|
+
label,
|
|
27
|
+
testID,
|
|
28
|
+
iconStyle,
|
|
29
|
+
renderItem,
|
|
30
|
+
style = {},
|
|
31
|
+
subfixIcon,
|
|
32
|
+
labelField,
|
|
33
|
+
valueField,
|
|
34
|
+
onChangeText,
|
|
35
|
+
itemTextStyle,
|
|
36
|
+
flatListProps,
|
|
37
|
+
minHeight = 0,
|
|
38
|
+
containerStyle,
|
|
39
|
+
search = false,
|
|
40
|
+
renderLeftIcon,
|
|
41
|
+
multiSelectIcon,
|
|
42
|
+
itemTestIDField,
|
|
43
|
+
maxHeight = 300,
|
|
44
|
+
inverted = true,
|
|
45
|
+
renderRightIcon,
|
|
46
|
+
backgroundColor,
|
|
47
|
+
placeholderStyle,
|
|
48
|
+
inputSearchStyle,
|
|
49
|
+
searchPlaceholder,
|
|
50
|
+
selectedTextStyle,
|
|
51
|
+
renderInputSearch,
|
|
52
|
+
iconColor = 'gray',
|
|
53
|
+
accessibilityLabel,
|
|
54
|
+
itemContainerStyle,
|
|
55
|
+
labelContainer = {},
|
|
56
|
+
labelTextStyle = {},
|
|
57
|
+
selectedTextProps = {},
|
|
58
|
+
selectionType = 'single',
|
|
59
|
+
activeColor = 'lightGray',
|
|
60
|
+
keyboardAvoiding = true,
|
|
61
|
+
dropdownPosition = 'auto',
|
|
62
|
+
placeholder = 'Select item',
|
|
63
|
+
itemAccessibilityLabelField,
|
|
64
|
+
showsVerticalScrollIndicator = true,
|
|
65
|
+
} = props;
|
|
66
|
+
|
|
67
|
+
const { styles, colors } = useDropdownStyle({});
|
|
68
|
+
const {
|
|
69
|
+
ref,
|
|
70
|
+
font,
|
|
71
|
+
visible,
|
|
72
|
+
refList,
|
|
73
|
+
position,
|
|
74
|
+
onSelect,
|
|
75
|
+
listData,
|
|
76
|
+
onSearch,
|
|
77
|
+
onMeasure,
|
|
78
|
+
searchText,
|
|
79
|
+
showOrClose,
|
|
80
|
+
scrollIndex,
|
|
81
|
+
currentValue,
|
|
82
|
+
onCheckPress,
|
|
83
|
+
onClearPress,
|
|
84
|
+
setSearchText,
|
|
85
|
+
keyboardHeight,
|
|
86
|
+
} = useDropdown({ ...props });
|
|
87
|
+
|
|
88
|
+
const renderRight = () => {
|
|
89
|
+
return renderRightIcon ? (
|
|
90
|
+
renderRightIcon(visible)
|
|
91
|
+
) : (
|
|
92
|
+
<SvgButton
|
|
93
|
+
icon={subfixIcon}
|
|
94
|
+
onPress={showOrClose}
|
|
95
|
+
style={StyleSheet.flatten([
|
|
96
|
+
iconStyle,
|
|
97
|
+
styles.icon,
|
|
98
|
+
{ tintColor: iconColor },
|
|
99
|
+
])}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const _renderDropdown = () => {
|
|
105
|
+
const isSelected = currentValue && _.get(currentValue, valueField);
|
|
106
|
+
return (
|
|
107
|
+
<TouchableWithoutFeedback
|
|
108
|
+
testID={testID}
|
|
109
|
+
accessible={!!accessibilityLabel}
|
|
110
|
+
accessibilityLabel={accessibilityLabel}
|
|
111
|
+
onPress={() => (selectionType === 'single' ? showOrClose() : null)}
|
|
112
|
+
>
|
|
113
|
+
<View style={styles.dropdown}>
|
|
114
|
+
{renderLeftIcon?.(visible)}
|
|
115
|
+
{selectionType === 'single' ? (
|
|
116
|
+
<AppText
|
|
117
|
+
style={[
|
|
118
|
+
styles.textItem,
|
|
119
|
+
isSelected !== null ? selectedTextStyle : placeholderStyle,
|
|
120
|
+
font(),
|
|
121
|
+
]}
|
|
122
|
+
{...selectedTextProps}
|
|
123
|
+
>
|
|
124
|
+
{isSelected !== null
|
|
125
|
+
? _.get(currentValue, labelField)
|
|
126
|
+
: placeholder}
|
|
127
|
+
</AppText>
|
|
128
|
+
) : currentValue?.length === 0 ? (
|
|
129
|
+
<AppText
|
|
130
|
+
style={[styles.textItem, placeholderStyle, font()]}
|
|
131
|
+
{...selectedTextProps}
|
|
132
|
+
>
|
|
133
|
+
{placeholder}
|
|
134
|
+
</AppText>
|
|
135
|
+
) : (
|
|
136
|
+
<View style={styles.showMultiSelectContainer}>
|
|
137
|
+
<ScrollView showsVerticalScrollIndicator={false}>
|
|
138
|
+
<View style={styles.wraps}>
|
|
139
|
+
{currentValue?.map?.((i: any) => (
|
|
140
|
+
<Chip
|
|
141
|
+
label={i.name}
|
|
142
|
+
chipColor={'red'}
|
|
143
|
+
textColor={'white'}
|
|
144
|
+
key={i?.[valueField]}
|
|
145
|
+
onClearPress={() => onClearPress(i)}
|
|
146
|
+
/>
|
|
147
|
+
))}
|
|
148
|
+
</View>
|
|
149
|
+
</ScrollView>
|
|
150
|
+
</View>
|
|
151
|
+
)}
|
|
152
|
+
{renderRight()}
|
|
153
|
+
</View>
|
|
154
|
+
</TouchableWithoutFeedback>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const renderRadio = useCallback(
|
|
159
|
+
(selected: boolean) => {
|
|
160
|
+
return (
|
|
161
|
+
<View style={styles.itemIconContainer}>
|
|
162
|
+
{selected && <View style={styles.iconSubContainer} />}
|
|
163
|
+
</View>
|
|
164
|
+
);
|
|
165
|
+
},
|
|
166
|
+
[styles],
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
const renderCheckItem = useCallback(
|
|
170
|
+
({ item, index }: { item: any; index: number }) => {
|
|
171
|
+
const isSelected = _.some(currentValue, h =>
|
|
172
|
+
_.isEqual(_.get(h, valueField), _.get(item, valueField)),
|
|
173
|
+
);
|
|
174
|
+
return (
|
|
175
|
+
<TouchableHighlight
|
|
176
|
+
key={index.toString()}
|
|
177
|
+
testID={_.get(item, itemTestIDField || labelField)}
|
|
178
|
+
accessible={!!accessibilityLabel}
|
|
179
|
+
accessibilityLabel={_.get(
|
|
180
|
+
item,
|
|
181
|
+
itemAccessibilityLabelField || labelField,
|
|
182
|
+
)}
|
|
183
|
+
underlayColor={colors[activeColor]}
|
|
184
|
+
onPress={() => onCheckPress(item)}
|
|
185
|
+
>
|
|
186
|
+
<View style={StyleSheet.flatten([itemContainerStyle])}>
|
|
187
|
+
{renderItem ? (
|
|
188
|
+
renderItem(item, isSelected)
|
|
189
|
+
) : (
|
|
190
|
+
<View style={styles.item}>
|
|
191
|
+
<SvgButton
|
|
192
|
+
icon={multiSelectIcon}
|
|
193
|
+
onPress={() => onCheckPress(item)}
|
|
194
|
+
style={[
|
|
195
|
+
styles.checkContainer,
|
|
196
|
+
{
|
|
197
|
+
backgroundColor: isSelected ? colors.gray : colors.white,
|
|
198
|
+
},
|
|
199
|
+
]}
|
|
200
|
+
/>
|
|
201
|
+
<AppText
|
|
202
|
+
style={StyleSheet.flatten([
|
|
203
|
+
styles.textItem,
|
|
204
|
+
itemTextStyle,
|
|
205
|
+
font(),
|
|
206
|
+
])}
|
|
207
|
+
>
|
|
208
|
+
{_.get(item, labelField)}
|
|
209
|
+
</AppText>
|
|
210
|
+
</View>
|
|
211
|
+
)}
|
|
212
|
+
</View>
|
|
213
|
+
</TouchableHighlight>
|
|
214
|
+
);
|
|
215
|
+
},
|
|
216
|
+
[
|
|
217
|
+
font,
|
|
218
|
+
colors,
|
|
219
|
+
styles,
|
|
220
|
+
labelField,
|
|
221
|
+
renderItem,
|
|
222
|
+
valueField,
|
|
223
|
+
activeColor,
|
|
224
|
+
currentValue,
|
|
225
|
+
itemTextStyle,
|
|
226
|
+
itemTestIDField,
|
|
227
|
+
accessibilityLabel,
|
|
228
|
+
itemContainerStyle,
|
|
229
|
+
itemAccessibilityLabelField,
|
|
230
|
+
],
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const _renderItem = useCallback(
|
|
234
|
+
({ item, index }: { item: any; index: number }) => {
|
|
235
|
+
const isSelected = currentValue && _.get(currentValue, valueField);
|
|
236
|
+
const selected = _.isEqual(_.get(item, valueField), isSelected);
|
|
237
|
+
_.assign(item, { _index: index });
|
|
238
|
+
return (
|
|
239
|
+
<TouchableHighlight
|
|
240
|
+
key={index.toString()}
|
|
241
|
+
testID={_.get(item, itemTestIDField || labelField)}
|
|
242
|
+
accessible={!!accessibilityLabel}
|
|
243
|
+
accessibilityLabel={_.get(
|
|
244
|
+
item,
|
|
245
|
+
itemAccessibilityLabelField || labelField,
|
|
246
|
+
)}
|
|
247
|
+
underlayColor={colors[activeColor]}
|
|
248
|
+
onPress={() => onSelect(item)}
|
|
249
|
+
>
|
|
250
|
+
<View style={StyleSheet.flatten([itemContainerStyle])}>
|
|
251
|
+
{renderItem ? (
|
|
252
|
+
renderItem(item, selected)
|
|
253
|
+
) : (
|
|
254
|
+
<View style={styles.item}>
|
|
255
|
+
{renderRadio(selected)}
|
|
256
|
+
<AppText
|
|
257
|
+
style={StyleSheet.flatten([
|
|
258
|
+
styles.textItem,
|
|
259
|
+
itemTextStyle,
|
|
260
|
+
font(),
|
|
261
|
+
])}
|
|
262
|
+
>
|
|
263
|
+
{_.get(item, labelField)}
|
|
264
|
+
</AppText>
|
|
265
|
+
</View>
|
|
266
|
+
)}
|
|
267
|
+
</View>
|
|
268
|
+
</TouchableHighlight>
|
|
269
|
+
);
|
|
270
|
+
},
|
|
271
|
+
[
|
|
272
|
+
font,
|
|
273
|
+
colors,
|
|
274
|
+
styles,
|
|
275
|
+
onSelect,
|
|
276
|
+
labelField,
|
|
277
|
+
renderItem,
|
|
278
|
+
valueField,
|
|
279
|
+
renderRadio,
|
|
280
|
+
activeColor,
|
|
281
|
+
currentValue,
|
|
282
|
+
itemTextStyle,
|
|
283
|
+
itemTestIDField,
|
|
284
|
+
accessibilityLabel,
|
|
285
|
+
itemContainerStyle,
|
|
286
|
+
itemAccessibilityLabelField,
|
|
287
|
+
],
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const renderSearch = useCallback(() => {
|
|
291
|
+
if (search) {
|
|
292
|
+
if (renderInputSearch) {
|
|
293
|
+
return renderInputSearch(text => {
|
|
294
|
+
if (onChangeText) {
|
|
295
|
+
setSearchText(text);
|
|
296
|
+
onChangeText(text);
|
|
297
|
+
}
|
|
298
|
+
onSearch(text);
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
return (
|
|
302
|
+
<SearchInput
|
|
303
|
+
value={searchText}
|
|
304
|
+
autoCorrect={false}
|
|
305
|
+
testID={testID + ' input'}
|
|
306
|
+
placeholder={searchPlaceholder}
|
|
307
|
+
placeholderTextColor={colors.black}
|
|
308
|
+
style={[styles.input, inputSearchStyle]}
|
|
309
|
+
accessibilityLabel={accessibilityLabel + ' input'}
|
|
310
|
+
onChangeText={(e: any) => {
|
|
311
|
+
if (onChangeText) {
|
|
312
|
+
setSearchText(e);
|
|
313
|
+
onChangeText(e);
|
|
314
|
+
}
|
|
315
|
+
onSearch(e);
|
|
316
|
+
}}
|
|
317
|
+
/>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return null;
|
|
322
|
+
}, [
|
|
323
|
+
search,
|
|
324
|
+
testID,
|
|
325
|
+
colors,
|
|
326
|
+
styles,
|
|
327
|
+
onSearch,
|
|
328
|
+
searchText,
|
|
329
|
+
onChangeText,
|
|
330
|
+
inputSearchStyle,
|
|
331
|
+
renderInputSearch,
|
|
332
|
+
searchPlaceholder,
|
|
333
|
+
accessibilityLabel,
|
|
334
|
+
]);
|
|
335
|
+
|
|
336
|
+
const _renderList = useCallback(
|
|
337
|
+
(isTopPosition: boolean) => {
|
|
338
|
+
const isInverted = !inverted ? false : isTopPosition;
|
|
339
|
+
|
|
340
|
+
const _renderListHelper = () => {
|
|
341
|
+
return (
|
|
342
|
+
<FlatList
|
|
343
|
+
ref={refList}
|
|
344
|
+
data={listData}
|
|
345
|
+
{...flatListProps}
|
|
346
|
+
testID={testID + ' flatlist'}
|
|
347
|
+
keyboardShouldPersistTaps="handled"
|
|
348
|
+
onScrollToIndexFailed={scrollIndex}
|
|
349
|
+
inverted={isTopPosition ? inverted : false}
|
|
350
|
+
keyExtractor={(_item, index) => index.toString()}
|
|
351
|
+
accessibilityLabel={accessibilityLabel + ' flatlist'}
|
|
352
|
+
showsVerticalScrollIndicator={showsVerticalScrollIndicator}
|
|
353
|
+
renderItem={
|
|
354
|
+
selectionType === 'single' ? _renderItem : renderCheckItem
|
|
355
|
+
}
|
|
356
|
+
/>
|
|
357
|
+
);
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
return (
|
|
361
|
+
<TouchableWithoutFeedback>
|
|
362
|
+
<View style={styles.flexShrink}>
|
|
363
|
+
{isInverted && _renderListHelper()}
|
|
364
|
+
{renderSearch()}
|
|
365
|
+
{!isInverted && _renderListHelper()}
|
|
366
|
+
</View>
|
|
367
|
+
</TouchableWithoutFeedback>
|
|
368
|
+
);
|
|
369
|
+
},
|
|
370
|
+
[
|
|
371
|
+
inverted,
|
|
372
|
+
styles,
|
|
373
|
+
testID,
|
|
374
|
+
listData,
|
|
375
|
+
scrollIndex,
|
|
376
|
+
renderSearch,
|
|
377
|
+
flatListProps,
|
|
378
|
+
renderCheckItem,
|
|
379
|
+
accessibilityLabel,
|
|
380
|
+
showsVerticalScrollIndicator,
|
|
381
|
+
],
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
const _renderModal = useCallback(() => {
|
|
385
|
+
if (visible && position) {
|
|
386
|
+
const { isFull, width, height, top, bottom, left } = position;
|
|
387
|
+
|
|
388
|
+
const onAutoPosition = () => {
|
|
389
|
+
if (keyboardHeight > 0) {
|
|
390
|
+
return bottom < keyboardHeight + height;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return bottom < (search ? 150 : 100);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
if (width && top && bottom) {
|
|
397
|
+
const styleVertical: ViewStyle = {
|
|
398
|
+
left: left,
|
|
399
|
+
maxHeight: maxHeight,
|
|
400
|
+
minHeight: minHeight,
|
|
401
|
+
};
|
|
402
|
+
const isTopPosition =
|
|
403
|
+
dropdownPosition === 'auto'
|
|
404
|
+
? onAutoPosition()
|
|
405
|
+
: dropdownPosition === 'top';
|
|
406
|
+
|
|
407
|
+
let keyboardStyle: ViewStyle = {};
|
|
408
|
+
|
|
409
|
+
let extendHeight = !isTopPosition ? top : bottom;
|
|
410
|
+
if (
|
|
411
|
+
keyboardAvoiding &&
|
|
412
|
+
keyboardHeight > 0 &&
|
|
413
|
+
isTopPosition &&
|
|
414
|
+
dropdownPosition === 'auto'
|
|
415
|
+
) {
|
|
416
|
+
extendHeight = keyboardHeight;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return (
|
|
420
|
+
<Modal
|
|
421
|
+
transparent
|
|
422
|
+
visible={visible}
|
|
423
|
+
statusBarTranslucent
|
|
424
|
+
onRequestClose={showOrClose}
|
|
425
|
+
supportedOrientations={['landscape', 'portrait']}
|
|
426
|
+
>
|
|
427
|
+
<TouchableWithoutFeedback onPress={showOrClose}>
|
|
428
|
+
<View
|
|
429
|
+
style={StyleSheet.flatten([
|
|
430
|
+
styles.flex1,
|
|
431
|
+
isFull && styles.styleContainerVertical,
|
|
432
|
+
backgroundColor && { backgroundColor: backgroundColor },
|
|
433
|
+
keyboardStyle,
|
|
434
|
+
])}
|
|
435
|
+
>
|
|
436
|
+
<View
|
|
437
|
+
style={StyleSheet.flatten([
|
|
438
|
+
styles.flex1,
|
|
439
|
+
!isTopPosition
|
|
440
|
+
? { paddingTop: extendHeight }
|
|
441
|
+
: {
|
|
442
|
+
justifyContent: 'flex-end',
|
|
443
|
+
paddingBottom: extendHeight,
|
|
444
|
+
},
|
|
445
|
+
isFull && styles.fullScreen,
|
|
446
|
+
])}
|
|
447
|
+
>
|
|
448
|
+
<View
|
|
449
|
+
style={StyleSheet.flatten([
|
|
450
|
+
styles.container,
|
|
451
|
+
isFull ? styles.styleHorizontal : styleVertical,
|
|
452
|
+
{
|
|
453
|
+
width,
|
|
454
|
+
},
|
|
455
|
+
containerStyle,
|
|
456
|
+
])}
|
|
457
|
+
>
|
|
458
|
+
{_renderList(isTopPosition)}
|
|
459
|
+
</View>
|
|
460
|
+
</View>
|
|
461
|
+
</View>
|
|
462
|
+
</TouchableWithoutFeedback>
|
|
463
|
+
</Modal>
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
return null;
|
|
469
|
+
}, [
|
|
470
|
+
search,
|
|
471
|
+
styles,
|
|
472
|
+
visible,
|
|
473
|
+
position,
|
|
474
|
+
maxHeight,
|
|
475
|
+
minHeight,
|
|
476
|
+
showOrClose,
|
|
477
|
+
_renderList,
|
|
478
|
+
keyboardHeight,
|
|
479
|
+
containerStyle,
|
|
480
|
+
backgroundColor,
|
|
481
|
+
dropdownPosition,
|
|
482
|
+
keyboardAvoiding,
|
|
483
|
+
]);
|
|
484
|
+
|
|
485
|
+
const _renderLabel = useCallback(() => {
|
|
486
|
+
return label ? (
|
|
487
|
+
<View style={[styles.labelContainer, labelContainer]}>
|
|
488
|
+
<AppText style={[styles.labelTextStyle, labelTextStyle]}>
|
|
489
|
+
{label}
|
|
490
|
+
</AppText>
|
|
491
|
+
</View>
|
|
492
|
+
) : (
|
|
493
|
+
<></>
|
|
494
|
+
);
|
|
495
|
+
}, [label, labelContainer, labelTextStyle, styles]);
|
|
496
|
+
|
|
497
|
+
return (
|
|
498
|
+
<View style={styles.mainContainer}>
|
|
499
|
+
{_renderLabel()}
|
|
500
|
+
<View
|
|
501
|
+
ref={ref}
|
|
502
|
+
onLayout={onMeasure}
|
|
503
|
+
style={StyleSheet.flatten([styles.mainWrap, style])}
|
|
504
|
+
>
|
|
505
|
+
{_renderDropdown()}
|
|
506
|
+
{_renderModal()}
|
|
507
|
+
</View>
|
|
508
|
+
</View>
|
|
509
|
+
);
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
export default DropdownComponent;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { I18nManager, StyleSheet } from 'react-native';
|
|
3
|
+
import { useDeviceOrientation } from './hooks/useOrientation';
|
|
4
|
+
import { ThemeColors } from '../../interface/colors.interface';
|
|
5
|
+
import { DEFAULT_COLORS, SCREEN_WIDTH, SPACING, LIGHT_COLORS } from '../../style';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
size?: number;
|
|
9
|
+
radioIconColor?: keyof ThemeColors;
|
|
10
|
+
checkIconColor?: keyof ThemeColors;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const useDropdownStyle = (props: Props) => {
|
|
14
|
+
const orientation = useDeviceOrientation();
|
|
15
|
+
const { ...colors } = LIGHT_COLORS
|
|
16
|
+
const { size = 16, radioIconColor, checkIconColor } = props;
|
|
17
|
+
|
|
18
|
+
const styles = useMemo(() => {
|
|
19
|
+
return StyleSheet.create({
|
|
20
|
+
mainContainer: {
|
|
21
|
+
width: '100%',
|
|
22
|
+
},
|
|
23
|
+
mainWrap: {
|
|
24
|
+
borderWidth: 1,
|
|
25
|
+
borderRadius: 6,
|
|
26
|
+
paddingHorizontal: 6,
|
|
27
|
+
justifyContent: 'center',
|
|
28
|
+
borderColor: colors.lightGray,
|
|
29
|
+
},
|
|
30
|
+
container: {
|
|
31
|
+
flexShrink: 1,
|
|
32
|
+
borderWidth: 0.5,
|
|
33
|
+
borderColor: '#EEEEEE',
|
|
34
|
+
shadowColor: colors.black,
|
|
35
|
+
backgroundColor: colors.white,
|
|
36
|
+
shadowOffset: {
|
|
37
|
+
width: 0,
|
|
38
|
+
height: 1,
|
|
39
|
+
},
|
|
40
|
+
elevation: 2,
|
|
41
|
+
shadowOpacity: 0.2,
|
|
42
|
+
shadowRadius: 1.41,
|
|
43
|
+
},
|
|
44
|
+
flex1: {
|
|
45
|
+
flex: 1,
|
|
46
|
+
},
|
|
47
|
+
flexShrink: {
|
|
48
|
+
flexShrink: 1,
|
|
49
|
+
},
|
|
50
|
+
wrapTop: {
|
|
51
|
+
justifyContent: 'flex-end',
|
|
52
|
+
},
|
|
53
|
+
dropdown: {
|
|
54
|
+
minHeight: 48,
|
|
55
|
+
maxHeight: 170,
|
|
56
|
+
alignItems: 'center',
|
|
57
|
+
justifyContent: 'space-between',
|
|
58
|
+
flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row',
|
|
59
|
+
},
|
|
60
|
+
title: {
|
|
61
|
+
fontSize: 16,
|
|
62
|
+
marginVertical: SPACING.s6,
|
|
63
|
+
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
|
|
64
|
+
},
|
|
65
|
+
item: {
|
|
66
|
+
padding: 17,
|
|
67
|
+
alignItems: 'center',
|
|
68
|
+
borderBottomWidth: 0.5,
|
|
69
|
+
borderColor: colors.lightGray,
|
|
70
|
+
justifyContent: 'space-between',
|
|
71
|
+
flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row',
|
|
72
|
+
},
|
|
73
|
+
textItem: {
|
|
74
|
+
flex: 1,
|
|
75
|
+
fontSize: 16,
|
|
76
|
+
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
|
|
77
|
+
},
|
|
78
|
+
icon: {
|
|
79
|
+
width: 20,
|
|
80
|
+
height: 20,
|
|
81
|
+
},
|
|
82
|
+
input: {
|
|
83
|
+
margin: 6,
|
|
84
|
+
height: 45,
|
|
85
|
+
borderWidth: 0.5,
|
|
86
|
+
borderColor: '#DDDDDD',
|
|
87
|
+
marginBottom: SPACING.s8,
|
|
88
|
+
paddingHorizontal: SPACING.s8,
|
|
89
|
+
},
|
|
90
|
+
fullScreen: {
|
|
91
|
+
alignItems: 'center',
|
|
92
|
+
justifyContent: 'center',
|
|
93
|
+
},
|
|
94
|
+
labelContainer: {
|
|
95
|
+
marginBottom: SPACING.s6,
|
|
96
|
+
paddingVertical: SPACING.s6,
|
|
97
|
+
},
|
|
98
|
+
labelTextStyle: {
|
|
99
|
+
color: colors.black,
|
|
100
|
+
},
|
|
101
|
+
itemIconContainer: {
|
|
102
|
+
borderWidth: 2,
|
|
103
|
+
marginRight: 10,
|
|
104
|
+
borderRadius: 100,
|
|
105
|
+
width: size || 24,
|
|
106
|
+
height: size || 24,
|
|
107
|
+
alignItems: 'center',
|
|
108
|
+
justifyContent: 'center',
|
|
109
|
+
padding: (size || 24) / 8,
|
|
110
|
+
borderColor: radioIconColor || colors.gray,
|
|
111
|
+
},
|
|
112
|
+
iconSubContainer: {
|
|
113
|
+
width: '100%',
|
|
114
|
+
height: '100%',
|
|
115
|
+
borderRadius: 100,
|
|
116
|
+
backgroundColor: radioIconColor || colors.gray,
|
|
117
|
+
},
|
|
118
|
+
styleHorizontal: {
|
|
119
|
+
width: orientation === 'LANDSCAPE' ? SCREEN_WIDTH / 2 : '100%',
|
|
120
|
+
alignSelf: 'center',
|
|
121
|
+
},
|
|
122
|
+
styleContainerVertical: {
|
|
123
|
+
alignItems: 'center',
|
|
124
|
+
backgroundColor: DEFAULT_COLORS.blackOpacity,
|
|
125
|
+
},
|
|
126
|
+
checkContainer: {
|
|
127
|
+
borderWidth: 2,
|
|
128
|
+
borderRadius: 2,
|
|
129
|
+
marginRight: 10,
|
|
130
|
+
width: size || 16,
|
|
131
|
+
height: size || 16,
|
|
132
|
+
alignItems: 'center',
|
|
133
|
+
justifyContent: 'center',
|
|
134
|
+
borderColor: checkIconColor ? checkIconColor : colors.gray,
|
|
135
|
+
},
|
|
136
|
+
showMultiSelectContainer: {
|
|
137
|
+
width: '90%',
|
|
138
|
+
height: 'auto',
|
|
139
|
+
maxHeight: 200,
|
|
140
|
+
},
|
|
141
|
+
wraps: {
|
|
142
|
+
flexWrap: 'wrap',
|
|
143
|
+
paddingVertical: 6,
|
|
144
|
+
flexDirection: 'row',
|
|
145
|
+
paddingHorizontal: 10,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}, [size, colors, orientation, radioIconColor, checkIconColor]);
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
styles,
|
|
152
|
+
colors,
|
|
153
|
+
};
|
|
154
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import useChipStyle from './ChipStyle';
|
|
3
|
+
import AppText from '../../../text/AppText';
|
|
4
|
+
import SvgButton from '../../../svgButton/SvgButton';
|
|
5
|
+
import { ChipInterface } from '../../interface/ChipInterface';
|
|
6
|
+
|
|
7
|
+
const Chip = (props: ChipInterface) => {
|
|
8
|
+
const { styles } = useChipStyle({ ...props });
|
|
9
|
+
const { label, onClearPress, textColor, clearIcon } = props;
|
|
10
|
+
return (
|
|
11
|
+
<View style={styles.box}>
|
|
12
|
+
<AppText
|
|
13
|
+
size={12}
|
|
14
|
+
fontFamily={'semiBold'}
|
|
15
|
+
style={styles.chipText}
|
|
16
|
+
color={textColor ? textColor : 'gray'}
|
|
17
|
+
>
|
|
18
|
+
{label}
|
|
19
|
+
</AppText>
|
|
20
|
+
<View style={styles.clearContainer}>
|
|
21
|
+
<SvgButton
|
|
22
|
+
icon={clearIcon}
|
|
23
|
+
onPress={onClearPress}
|
|
24
|
+
style={styles.clearIcon}
|
|
25
|
+
/>
|
|
26
|
+
</View>
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default Chip;
|