@rn-components-dropdown/dropdown 1.0.12 → 1.0.13
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 -7
- package/dist/components/dropdown/Dropdown.js +10 -4
- package/dist/components/dropdown/DropdownStyle.d.ts +2 -0
- package/dist/components/dropdown/DropdownStyle.js +4 -2
- package/dist/components/dropdown/hooks/useDropdown.js +4 -5
- package/dist/components/dropdown/interface/DropdownInterface.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/dropdown/Dropdown.tsx +13 -5
- package/src/components/dropdown/DropdownStyle.ts +10 -3
- package/src/components/dropdown/hooks/useDropdown.ts +6 -5
- package/src/components/dropdown/interface/DropdownInterface.ts +1 -1
package/README.md
CHANGED
|
@@ -9,13 +9,13 @@ Supports **single** & **multiple selection**, custom icons, styling, and easy in
|
|
|
9
9
|
|
|
10
10
|
### Install Package
|
|
11
11
|
|
|
12
|
-
```bash
|
|
12
|
+
```bash title="install.sh" copy
|
|
13
13
|
npm install @rn-components-dropdown/dropdown
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
### React Hook Form (optional — required only for DropdownController)
|
|
17
17
|
|
|
18
|
-
```bash
|
|
18
|
+
```bash title="install.sh" copy
|
|
19
19
|
npm install react-hook-form
|
|
20
20
|
```
|
|
21
21
|
|
|
@@ -102,8 +102,7 @@ export default function FormScreen() {
|
|
|
102
102
|
return (
|
|
103
103
|
<DropdownController
|
|
104
104
|
control={control}
|
|
105
|
-
|
|
106
|
-
rules={{ required: "Please select a fruit" }}
|
|
105
|
+
controller="fruit"
|
|
107
106
|
dropProps={{
|
|
108
107
|
data: [
|
|
109
108
|
{ id: 1, label: "Apple" },
|
|
@@ -125,10 +124,10 @@ export default function FormScreen() {
|
|
|
125
124
|
| Prop | Type | Description |
|
|
126
125
|
|---------------|-------------|-----------------------------------------------|
|
|
127
126
|
| control | Control | React Hook Form control object |
|
|
128
|
-
|
|
|
127
|
+
| controller | string | Field name in the form |
|
|
129
128
|
| rules | object | Validation rules (optional) |
|
|
130
|
-
| dropProps | object | All dropdown props
|
|
131
|
-
| defaultValue | any | Initial/default value
|
|
129
|
+
| dropProps | object | All dropdown props |
|
|
130
|
+
| defaultValue | any | Initial/default value |
|
|
132
131
|
|
|
133
132
|
---
|
|
134
133
|
|
|
@@ -49,9 +49,12 @@ const CheckIcon_1 = __importDefault(require("../../assets/svg/CheckIcon"));
|
|
|
49
49
|
const svg_1 = require("../../assets/svg");
|
|
50
50
|
const TextInput_1 = __importDefault(require("./components/input/TextInput"));
|
|
51
51
|
const DropdownComponent = (props) => {
|
|
52
|
-
const { label, testID, iconStyle, renderItem, style = {}, subfixIcon, labelField, valueField, onChangeText, itemTextStyle, flatListProps, minHeight = 0, containerStyle, search = false, renderLeftIcon, multiSelectIcon, itemTestIDField, maxHeight = 300, inverted = true, renderRightIcon, backgroundColor, placeholderStyle, inputSearchStyle, searchPlaceholder, selectedTextStyle, renderInputSearch, iconColor = 'gray', accessibilityLabel, itemContainerStyle, labelContainer = {}, labelTextStyle = {}, selectedTextProps = {}, chipContainerProps = {}, selectionType = 'single', activeColor = 'lightGray',
|
|
52
|
+
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, backgroundColor, 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;
|
|
53
53
|
const { chipColor, clearIcon, textColor, onClearPress: onClear, } = chipContainerProps;
|
|
54
|
-
const { styles, colors } = (0, DropdownStyle_1.useDropdownStyle)({
|
|
54
|
+
const { styles, colors } = (0, DropdownStyle_1.useDropdownStyle)({
|
|
55
|
+
checkIconColor: checkIconColor,
|
|
56
|
+
radioIconColor: radioIconColor,
|
|
57
|
+
});
|
|
55
58
|
const { ref, font, visible, refList, position, onSelect, listData, onSearch, onMeasure, searchText, showOrClose, scrollIndex, currentValue, onCheckPress, onClearPress, setSearchText, keyboardHeight, } = (0, useDropdown_1.default)({ ...props });
|
|
56
59
|
const renderRight = () => {
|
|
57
60
|
return renderRightIcon ? (renderRightIcon(visible)) : (<SvgButton_1.default icon={subfixIcon ? (subfixIcon) : visible ? (<svg_1.ArrowUp color={iconColor}/>) : (<svg_1.ArrowDown color={iconColor}/>)} onPress={showOrClose} style={react_native_1.StyleSheet.flatten([
|
|
@@ -102,7 +105,11 @@ const DropdownComponent = (props) => {
|
|
|
102
105
|
<SvgButton_1.default icon={multiSelectIcon ? (multiSelectIcon) : (<CheckIcon_1.default color={colors.white}/>)} onPress={() => onCheckPress(item)} style={[
|
|
103
106
|
styles.checkContainer,
|
|
104
107
|
{
|
|
105
|
-
backgroundColor: isSelected
|
|
108
|
+
backgroundColor: isSelected
|
|
109
|
+
? checkIconColor
|
|
110
|
+
? checkIconColor
|
|
111
|
+
: colors.gray
|
|
112
|
+
: colors.white,
|
|
106
113
|
},
|
|
107
114
|
]}/>
|
|
108
115
|
<AppText_1.default style={react_native_1.StyleSheet.flatten([
|
|
@@ -255,7 +262,6 @@ const DropdownComponent = (props) => {
|
|
|
255
262
|
<react_native_1.View style={react_native_1.StyleSheet.flatten([
|
|
256
263
|
styles.flex1,
|
|
257
264
|
isFull && styles.styleContainerVertical,
|
|
258
|
-
backgroundColor && { backgroundColor: backgroundColor },
|
|
259
265
|
keyboardStyle,
|
|
260
266
|
])}>
|
|
261
267
|
<react_native_1.View style={react_native_1.StyleSheet.flatten([
|
|
@@ -48,6 +48,7 @@ export declare const useDropdownStyle: (props: Props) => {
|
|
|
48
48
|
};
|
|
49
49
|
title: {
|
|
50
50
|
fontSize: number;
|
|
51
|
+
color: string;
|
|
51
52
|
marginVertical: number;
|
|
52
53
|
writingDirection: "ltr" | "rtl";
|
|
53
54
|
};
|
|
@@ -62,6 +63,7 @@ export declare const useDropdownStyle: (props: Props) => {
|
|
|
62
63
|
textItem: {
|
|
63
64
|
flex: number;
|
|
64
65
|
fontSize: number;
|
|
66
|
+
color: string;
|
|
65
67
|
writingDirection: "ltr" | "rtl";
|
|
66
68
|
};
|
|
67
69
|
icon: {
|
|
@@ -6,8 +6,8 @@ const react_native_1 = require("react-native");
|
|
|
6
6
|
const useOrientation_1 = require("./hooks/useOrientation");
|
|
7
7
|
const style_1 = require("../../style");
|
|
8
8
|
const useDropdownStyle = (props) => {
|
|
9
|
-
const orientation = (0, useOrientation_1.useDeviceOrientation)();
|
|
10
9
|
const { ...colors } = style_1.LIGHT_COLORS;
|
|
10
|
+
const orientation = (0, useOrientation_1.useDeviceOrientation)();
|
|
11
11
|
const { size = 16, radioIconColor, checkIconColor } = props;
|
|
12
12
|
const styles = (0, react_1.useMemo)(() => {
|
|
13
13
|
return react_native_1.StyleSheet.create({
|
|
@@ -53,6 +53,7 @@ const useDropdownStyle = (props) => {
|
|
|
53
53
|
},
|
|
54
54
|
title: {
|
|
55
55
|
fontSize: 16,
|
|
56
|
+
color: colors.gray,
|
|
56
57
|
marginVertical: style_1.SPACING.s6,
|
|
57
58
|
writingDirection: react_native_1.I18nManager.isRTL ? 'rtl' : 'ltr',
|
|
58
59
|
},
|
|
@@ -67,6 +68,7 @@ const useDropdownStyle = (props) => {
|
|
|
67
68
|
textItem: {
|
|
68
69
|
flex: 1,
|
|
69
70
|
fontSize: 16,
|
|
71
|
+
color: colors.gray,
|
|
70
72
|
writingDirection: react_native_1.I18nManager.isRTL ? 'rtl' : 'ltr',
|
|
71
73
|
},
|
|
72
74
|
icon: {
|
|
@@ -90,7 +92,7 @@ const useDropdownStyle = (props) => {
|
|
|
90
92
|
paddingVertical: style_1.SPACING.s6,
|
|
91
93
|
},
|
|
92
94
|
labelTextStyle: {
|
|
93
|
-
color: colors.
|
|
95
|
+
color: colors.gray,
|
|
94
96
|
},
|
|
95
97
|
itemIconContainer: {
|
|
96
98
|
borderWidth: 2,
|
|
@@ -234,12 +234,11 @@ const useDropdown = (props) => {
|
|
|
234
234
|
});
|
|
235
235
|
}, [setCurrentValue, valueField, onChange, currentValue]);
|
|
236
236
|
const onClearPress = (0, react_1.useCallback)((item) => {
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
setCurrentValue(rem);
|
|
237
|
+
const updated = currentValue.filter((i) => i[valueField] !== item[valueField]);
|
|
238
|
+
const val = currentValue.map((i) => i[valueField]);
|
|
239
|
+
setCurrentValue(updated);
|
|
241
240
|
onChange?.(item[valueField], val);
|
|
242
|
-
}, [onChange]);
|
|
241
|
+
}, [currentValue, valueField, onChange, setCurrentValue]);
|
|
243
242
|
return {
|
|
244
243
|
ref,
|
|
245
244
|
font,
|
|
@@ -67,7 +67,7 @@ export type DropdownProps<S, T extends SelectionType> = {
|
|
|
67
67
|
onChange?: (selecteValue?: keyof S, selectedList?: SelectionType extends 'single' | 'multi' ? S[] : S) => void;
|
|
68
68
|
};
|
|
69
69
|
export interface IUseDetectDevice {
|
|
70
|
-
isAndroid: boolean;
|
|
71
70
|
isIOS: boolean;
|
|
72
71
|
isTablet: boolean;
|
|
72
|
+
isAndroid: boolean;
|
|
73
73
|
}
|
package/package.json
CHANGED
|
@@ -40,6 +40,8 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
|
|
|
40
40
|
containerStyle,
|
|
41
41
|
search = false,
|
|
42
42
|
renderLeftIcon,
|
|
43
|
+
checkIconColor,
|
|
44
|
+
radioIconColor,
|
|
43
45
|
multiSelectIcon,
|
|
44
46
|
itemTestIDField,
|
|
45
47
|
maxHeight = 300,
|
|
@@ -58,12 +60,12 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
|
|
|
58
60
|
labelTextStyle = {},
|
|
59
61
|
selectedTextProps = {},
|
|
60
62
|
chipContainerProps = {},
|
|
63
|
+
keyboardAvoiding = true,
|
|
61
64
|
selectionType = 'single',
|
|
62
65
|
activeColor = 'lightGray',
|
|
63
|
-
keyboardAvoiding = true,
|
|
64
66
|
dropdownPosition = 'auto',
|
|
65
|
-
placeholder = 'Select item',
|
|
66
67
|
itemAccessibilityLabelField,
|
|
68
|
+
placeholder = 'Please select',
|
|
67
69
|
showsVerticalScrollIndicator = true,
|
|
68
70
|
} = props;
|
|
69
71
|
|
|
@@ -74,7 +76,10 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
|
|
|
74
76
|
onClearPress: onClear,
|
|
75
77
|
} = chipContainerProps;
|
|
76
78
|
|
|
77
|
-
const { styles, colors } = useDropdownStyle({
|
|
79
|
+
const { styles, colors } = useDropdownStyle({
|
|
80
|
+
checkIconColor: checkIconColor,
|
|
81
|
+
radioIconColor: radioIconColor,
|
|
82
|
+
});
|
|
78
83
|
const {
|
|
79
84
|
ref,
|
|
80
85
|
font,
|
|
@@ -222,7 +227,11 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
|
|
|
222
227
|
style={[
|
|
223
228
|
styles.checkContainer,
|
|
224
229
|
{
|
|
225
|
-
backgroundColor: isSelected
|
|
230
|
+
backgroundColor: isSelected
|
|
231
|
+
? checkIconColor
|
|
232
|
+
? checkIconColor
|
|
233
|
+
: colors.gray
|
|
234
|
+
: colors.white,
|
|
226
235
|
},
|
|
227
236
|
]}
|
|
228
237
|
/>
|
|
@@ -457,7 +466,6 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
|
|
|
457
466
|
style={StyleSheet.flatten([
|
|
458
467
|
styles.flex1,
|
|
459
468
|
isFull && styles.styleContainerVertical,
|
|
460
|
-
backgroundColor && { backgroundColor: backgroundColor },
|
|
461
469
|
keyboardStyle,
|
|
462
470
|
])}
|
|
463
471
|
>
|
|
@@ -2,7 +2,12 @@ import { useMemo } from 'react';
|
|
|
2
2
|
import { I18nManager, StyleSheet } from 'react-native';
|
|
3
3
|
import { useDeviceOrientation } from './hooks/useOrientation';
|
|
4
4
|
import { ThemeColors } from '../../interface/colors.interface';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_COLORS,
|
|
7
|
+
SCREEN_WIDTH,
|
|
8
|
+
SPACING,
|
|
9
|
+
LIGHT_COLORS,
|
|
10
|
+
} from '../../style';
|
|
6
11
|
|
|
7
12
|
interface Props {
|
|
8
13
|
size?: number;
|
|
@@ -11,8 +16,8 @@ interface Props {
|
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
export const useDropdownStyle = (props: Props) => {
|
|
19
|
+
const { ...colors } = LIGHT_COLORS;
|
|
14
20
|
const orientation = useDeviceOrientation();
|
|
15
|
-
const { ...colors } = LIGHT_COLORS
|
|
16
21
|
const { size = 16, radioIconColor, checkIconColor } = props;
|
|
17
22
|
|
|
18
23
|
const styles = useMemo(() => {
|
|
@@ -59,6 +64,7 @@ export const useDropdownStyle = (props: Props) => {
|
|
|
59
64
|
},
|
|
60
65
|
title: {
|
|
61
66
|
fontSize: 16,
|
|
67
|
+
color: colors.gray,
|
|
62
68
|
marginVertical: SPACING.s6,
|
|
63
69
|
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
|
|
64
70
|
},
|
|
@@ -73,6 +79,7 @@ export const useDropdownStyle = (props: Props) => {
|
|
|
73
79
|
textItem: {
|
|
74
80
|
flex: 1,
|
|
75
81
|
fontSize: 16,
|
|
82
|
+
color: colors.gray,
|
|
76
83
|
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
|
|
77
84
|
},
|
|
78
85
|
icon: {
|
|
@@ -96,7 +103,7 @@ export const useDropdownStyle = (props: Props) => {
|
|
|
96
103
|
paddingVertical: SPACING.s6,
|
|
97
104
|
},
|
|
98
105
|
labelTextStyle: {
|
|
99
|
-
color: colors.
|
|
106
|
+
color: colors.gray,
|
|
100
107
|
},
|
|
101
108
|
itemIconContainer: {
|
|
102
109
|
borderWidth: 2,
|
|
@@ -323,13 +323,14 @@ const useDropdown = <T, Mode extends 'single' | 'multi'>(
|
|
|
323
323
|
|
|
324
324
|
const onClearPress = useCallback(
|
|
325
325
|
(item: T) => {
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
326
|
+
const updated = currentValue.filter(
|
|
327
|
+
(i: any) => i[valueField] !== item[valueField],
|
|
328
|
+
);
|
|
329
|
+
const val = currentValue.map((i: any) => i[valueField]);
|
|
330
|
+
setCurrentValue(updated);
|
|
330
331
|
onChange?.(item[valueField] as keyof T, val);
|
|
331
332
|
},
|
|
332
|
-
[onChange],
|
|
333
|
+
[currentValue, valueField, onChange, setCurrentValue],
|
|
333
334
|
);
|
|
334
335
|
|
|
335
336
|
return {
|