@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,64 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { LIGHT_COLORS } from '../../../../style';
|
|
3
|
+
import { Platform, StyleSheet } from 'react-native';
|
|
4
|
+
import { ChipInterface } from '../../interface/ChipInterface';
|
|
5
|
+
|
|
6
|
+
const useChipStyle = (props: ChipInterface) => {
|
|
7
|
+
const { chipColor } = props;
|
|
8
|
+
const { ...colors } = LIGHT_COLORS;
|
|
9
|
+
const styles = useMemo(() => {
|
|
10
|
+
return StyleSheet.create({
|
|
11
|
+
box: {
|
|
12
|
+
margin: 4,
|
|
13
|
+
height: 26,
|
|
14
|
+
...Platform.select({
|
|
15
|
+
android: {
|
|
16
|
+
elevation: 5,
|
|
17
|
+
},
|
|
18
|
+
ios: {
|
|
19
|
+
shadowRadius: 1.84,
|
|
20
|
+
shadowOpacity: 0.25,
|
|
21
|
+
shadowColor: colors.black,
|
|
22
|
+
shadowOffset: { width: 0, height: 2 },
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
elevation: 5,
|
|
26
|
+
width: 'auto',
|
|
27
|
+
borderRadius: 30,
|
|
28
|
+
flexDirection: 'row',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
justifyContent: 'center',
|
|
31
|
+
backgroundColor: chipColor ? colors[chipColor] : colors.lightGray,
|
|
32
|
+
},
|
|
33
|
+
chipText: {
|
|
34
|
+
paddingLeft: 10,
|
|
35
|
+
fontWeight: '600',
|
|
36
|
+
},
|
|
37
|
+
clearContainer: {
|
|
38
|
+
width: 18,
|
|
39
|
+
height: 18,
|
|
40
|
+
borderWidth: 1,
|
|
41
|
+
borderRadius: 100,
|
|
42
|
+
marginHorizontal: 4,
|
|
43
|
+
alignItems: 'center',
|
|
44
|
+
justifyContent: 'center',
|
|
45
|
+
borderColor: colors.white,
|
|
46
|
+
backgroundColor: chipColor ? colors[chipColor] : colors.lightGray,
|
|
47
|
+
},
|
|
48
|
+
clearIcon: {
|
|
49
|
+
height: 12,
|
|
50
|
+
width: 12,
|
|
51
|
+
borderRadius: 100,
|
|
52
|
+
alignItems: 'center',
|
|
53
|
+
justifyContent: 'center',
|
|
54
|
+
backgroundColor: colors.white,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}, [chipColor, colors]);
|
|
58
|
+
return {
|
|
59
|
+
styles,
|
|
60
|
+
colors,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default useChipStyle;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useTextStyle } from './TextInputStyle';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { TouchableWithoutFeedback } from 'react-native';
|
|
4
|
+
import AppTextInput from '../../../textInput/AppTextInput';
|
|
5
|
+
import type { CTextInput } from '../../interface/InputProps';
|
|
6
|
+
|
|
7
|
+
const TextInputComponent: CTextInput = props => {
|
|
8
|
+
const {
|
|
9
|
+
value,
|
|
10
|
+
placeholder = '',
|
|
11
|
+
placeholderTextColor = '#000',
|
|
12
|
+
onChangeText = (_value: string) => {},
|
|
13
|
+
searchIcon,
|
|
14
|
+
} = props;
|
|
15
|
+
|
|
16
|
+
const [searchtext, setSearchText] = useState<string>('');
|
|
17
|
+
const { styles } = useTextStyle();
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (value) {
|
|
21
|
+
setSearchText(value);
|
|
22
|
+
}
|
|
23
|
+
}, [value]);
|
|
24
|
+
|
|
25
|
+
const onChange = (text: string) => {
|
|
26
|
+
setSearchText(text);
|
|
27
|
+
onChangeText(text);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<TouchableWithoutFeedback>
|
|
32
|
+
<AppTextInput
|
|
33
|
+
{...props}
|
|
34
|
+
value={searchtext}
|
|
35
|
+
icon={searchIcon}
|
|
36
|
+
style={styles.input}
|
|
37
|
+
onChangeText={onChange}
|
|
38
|
+
placeholder={placeholder}
|
|
39
|
+
textStyle={styles.inputContainer}
|
|
40
|
+
placeholderTextColor={placeholderTextColor}
|
|
41
|
+
/>
|
|
42
|
+
</TouchableWithoutFeedback>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default TextInputComponent;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import { LIGHT_COLORS } from '../../../../style';
|
|
4
|
+
|
|
5
|
+
export const useTextStyle = () => {
|
|
6
|
+
const { ...colors } = LIGHT_COLORS;
|
|
7
|
+
|
|
8
|
+
const styles = useMemo(() => {
|
|
9
|
+
return StyleSheet.create({
|
|
10
|
+
input: {
|
|
11
|
+
height: 40,
|
|
12
|
+
width: '95%',
|
|
13
|
+
fontSize: 16,
|
|
14
|
+
borderWidth: 1,
|
|
15
|
+
borderRadius: 3,
|
|
16
|
+
marginVertical: 10,
|
|
17
|
+
marginHorizontal: 8,
|
|
18
|
+
borderColor: colors.border,
|
|
19
|
+
},
|
|
20
|
+
inputContainer: {
|
|
21
|
+
width: '90%',
|
|
22
|
+
fontSize: 14,
|
|
23
|
+
color: colors.gray,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}, [colors]);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
styles,
|
|
30
|
+
colors,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Platform, PixelRatio, Dimensions } from 'react-native';
|
|
2
|
+
import type { IUseDetectDevice } from '../interface/DropdownInterface';
|
|
3
|
+
|
|
4
|
+
const { width, height } = Dimensions.get('window');
|
|
5
|
+
|
|
6
|
+
const isTablet = () => {
|
|
7
|
+
let pixelDensity = PixelRatio.get();
|
|
8
|
+
const adjustedWidth = width * pixelDensity;
|
|
9
|
+
const adjustedHeight = height * pixelDensity;
|
|
10
|
+
if (pixelDensity < 2 && (adjustedWidth >= 1000 || adjustedHeight >= 1000)) {
|
|
11
|
+
return true;
|
|
12
|
+
} else {
|
|
13
|
+
return (
|
|
14
|
+
pixelDensity === 2 && (adjustedWidth >= 1824 || adjustedHeight >= 1824)
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const useDetectDevice: IUseDetectDevice = {
|
|
20
|
+
isAndroid: Platform.OS === 'android',
|
|
21
|
+
isIOS: Platform.OS === 'ios',
|
|
22
|
+
isTablet: isTablet(),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { useDetectDevice };
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import {
|
|
3
|
+
useRef,
|
|
4
|
+
useState,
|
|
5
|
+
useEffect,
|
|
6
|
+
useCallback,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import {
|
|
10
|
+
View,
|
|
11
|
+
FlatList,
|
|
12
|
+
Keyboard,
|
|
13
|
+
StatusBar,
|
|
14
|
+
I18nManager,
|
|
15
|
+
KeyboardEvent,
|
|
16
|
+
} from 'react-native';
|
|
17
|
+
import _ from 'lodash';
|
|
18
|
+
import { useDetectDevice } from './useDetectDevice';
|
|
19
|
+
import { useDeviceOrientation } from './useOrientation';
|
|
20
|
+
import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../../style';
|
|
21
|
+
import { DropdownProps } from '../interface/DropdownInterface';
|
|
22
|
+
|
|
23
|
+
const useDropdown = <T, Mode extends 'single' | 'multi'>(
|
|
24
|
+
props: DropdownProps<T, Mode>,
|
|
25
|
+
) => {
|
|
26
|
+
const {
|
|
27
|
+
value,
|
|
28
|
+
onBlur,
|
|
29
|
+
onFocus,
|
|
30
|
+
onChange,
|
|
31
|
+
data = [],
|
|
32
|
+
labelField,
|
|
33
|
+
valueField,
|
|
34
|
+
fontFamily,
|
|
35
|
+
searchQuery,
|
|
36
|
+
searchField,
|
|
37
|
+
onChangeText,
|
|
38
|
+
disable = false,
|
|
39
|
+
ref: currentRef,
|
|
40
|
+
mode = 'default',
|
|
41
|
+
autoScroll = true,
|
|
42
|
+
confirmSelectItem,
|
|
43
|
+
onConfirmSelectItem,
|
|
44
|
+
selectionType = 'single',
|
|
45
|
+
} = props;
|
|
46
|
+
|
|
47
|
+
const ref = useRef<View>(null);
|
|
48
|
+
const { isTablet } = useDetectDevice;
|
|
49
|
+
const refList = useRef<FlatList>(null);
|
|
50
|
+
const orientation = useDeviceOrientation();
|
|
51
|
+
const [position, setPosition] = useState<any>();
|
|
52
|
+
const [searchText, setSearchText] = useState('');
|
|
53
|
+
const [listData, setListData] = useState<any[]>(data);
|
|
54
|
+
const [visible, setVisible] = useState<boolean>(false);
|
|
55
|
+
const [currentValue, setCurrentValue] = useState<any>(null);
|
|
56
|
+
const statusBarHeight: number = StatusBar.currentHeight || 0;
|
|
57
|
+
const [keyboardHeight, setKeyboardHeight] = useState<number>(0);
|
|
58
|
+
|
|
59
|
+
useImperativeHandle(currentRef, () => {
|
|
60
|
+
return { open: eventOpen, close: eventClose };
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
useEffect(() => eventClose, []);
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
setListData([...data]);
|
|
67
|
+
if (searchText) {
|
|
68
|
+
onSearch(searchText);
|
|
69
|
+
}
|
|
70
|
+
}, [data, searchText]);
|
|
71
|
+
|
|
72
|
+
const eventOpen = () => {
|
|
73
|
+
if (!disable) {
|
|
74
|
+
setVisible(true);
|
|
75
|
+
if (onFocus) {
|
|
76
|
+
onFocus();
|
|
77
|
+
}
|
|
78
|
+
if (searchText.length > 0) {
|
|
79
|
+
onSearch(searchText);
|
|
80
|
+
}
|
|
81
|
+
scrollIndex();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const eventClose = useCallback(() => {
|
|
86
|
+
if (!disable) {
|
|
87
|
+
setVisible(false);
|
|
88
|
+
if (onBlur) {
|
|
89
|
+
onBlur();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, [disable, onBlur]);
|
|
93
|
+
|
|
94
|
+
const font = useCallback(() => {
|
|
95
|
+
if (fontFamily) {
|
|
96
|
+
return {
|
|
97
|
+
fontFamily: fontFamily,
|
|
98
|
+
};
|
|
99
|
+
} else {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
}, [fontFamily]);
|
|
103
|
+
|
|
104
|
+
const onMeasure = useCallback(() => {
|
|
105
|
+
if (ref && ref?.current) {
|
|
106
|
+
ref.current.measureInWindow((pageX, pageY, width, height) => {
|
|
107
|
+
let isFull = isTablet
|
|
108
|
+
? false
|
|
109
|
+
: mode === 'modal' || orientation === 'LANDSCAPE';
|
|
110
|
+
|
|
111
|
+
if (mode === 'auto') {
|
|
112
|
+
isFull = false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const top = isFull ? 20 : height + pageY + 2;
|
|
116
|
+
const bottom = SCREEN_HEIGHT - top + height;
|
|
117
|
+
const left = I18nManager.isRTL ? SCREEN_WIDTH - width - pageX : pageX;
|
|
118
|
+
|
|
119
|
+
setPosition({
|
|
120
|
+
isFull,
|
|
121
|
+
left: Math.floor(left),
|
|
122
|
+
width: Math.floor(width),
|
|
123
|
+
height: Math.floor(height),
|
|
124
|
+
top: Math.floor(top + statusBarHeight),
|
|
125
|
+
bottom: Math.floor(bottom - statusBarHeight),
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}, [isTablet, mode, orientation, statusBarHeight]);
|
|
130
|
+
|
|
131
|
+
const onKeyboardDidShow = useCallback(
|
|
132
|
+
(e: KeyboardEvent) => {
|
|
133
|
+
onMeasure();
|
|
134
|
+
setKeyboardHeight(e.endCoordinates.height);
|
|
135
|
+
},
|
|
136
|
+
[onMeasure],
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const onKeyboardDidHide = useCallback(() => {
|
|
140
|
+
setKeyboardHeight(0);
|
|
141
|
+
onMeasure();
|
|
142
|
+
}, [onMeasure]);
|
|
143
|
+
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
const susbcriptionKeyboardDidShow = Keyboard.addListener(
|
|
146
|
+
'keyboardDidShow',
|
|
147
|
+
onKeyboardDidShow,
|
|
148
|
+
);
|
|
149
|
+
const susbcriptionKeyboardDidHide = Keyboard.addListener(
|
|
150
|
+
'keyboardDidHide',
|
|
151
|
+
onKeyboardDidHide,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
return () => {
|
|
155
|
+
if (typeof susbcriptionKeyboardDidShow?.remove === 'function') {
|
|
156
|
+
susbcriptionKeyboardDidShow.remove();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (typeof susbcriptionKeyboardDidHide?.remove === 'function') {
|
|
160
|
+
susbcriptionKeyboardDidHide.remove();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}, [onKeyboardDidHide, onKeyboardDidShow]);
|
|
164
|
+
|
|
165
|
+
const getValue = useCallback(() => {
|
|
166
|
+
if (selectionType === 'multi') {
|
|
167
|
+
if (!valueField) return;
|
|
168
|
+
const v = data?.filter(i => value?.includes(i[valueField] as any));
|
|
169
|
+
setCurrentValue(v);
|
|
170
|
+
return;
|
|
171
|
+
} else {
|
|
172
|
+
const defaultValue =
|
|
173
|
+
typeof value === 'object' ? _.get(value, valueField) : value;
|
|
174
|
+
|
|
175
|
+
const getItem = data.filter(e =>
|
|
176
|
+
_.isEqual(defaultValue, _.get(e, valueField)),
|
|
177
|
+
);
|
|
178
|
+
if (getItem.length > 0) {
|
|
179
|
+
setCurrentValue(getItem[0]);
|
|
180
|
+
} else {
|
|
181
|
+
setCurrentValue(null);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}, [data, value, valueField, selectionType]);
|
|
185
|
+
|
|
186
|
+
useEffect(() => getValue(), [value, data, getValue]);
|
|
187
|
+
|
|
188
|
+
const scrollIndex = useCallback(() => {
|
|
189
|
+
if (autoScroll && data.length > 0 && listData.length === data.length) {
|
|
190
|
+
setTimeout(() => {
|
|
191
|
+
if (refList && refList?.current) {
|
|
192
|
+
const defaultValue =
|
|
193
|
+
typeof value === 'object' ? _.get(value, valueField) : value;
|
|
194
|
+
|
|
195
|
+
const index = _.findIndex(listData, (e: any) =>
|
|
196
|
+
_.isEqual(defaultValue, _.get(e, valueField)),
|
|
197
|
+
);
|
|
198
|
+
if (index > -1 && index <= listData.length - 1) {
|
|
199
|
+
refList?.current?.scrollToIndex({
|
|
200
|
+
index: index,
|
|
201
|
+
animated: false,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}, 200);
|
|
206
|
+
}
|
|
207
|
+
}, [autoScroll, data.length, listData, value, valueField]);
|
|
208
|
+
|
|
209
|
+
const showOrClose = useCallback(() => {
|
|
210
|
+
if (!disable) {
|
|
211
|
+
if (keyboardHeight > 0 && visible) {
|
|
212
|
+
return Keyboard.dismiss();
|
|
213
|
+
}
|
|
214
|
+
onMeasure();
|
|
215
|
+
setVisible(!visible);
|
|
216
|
+
setListData(data);
|
|
217
|
+
|
|
218
|
+
if (!visible) {
|
|
219
|
+
if (onFocus) {
|
|
220
|
+
onFocus();
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
if (onBlur) {
|
|
224
|
+
onBlur();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (searchText?.length > 0) {
|
|
228
|
+
onSearch(searchText);
|
|
229
|
+
}
|
|
230
|
+
scrollIndex();
|
|
231
|
+
}
|
|
232
|
+
}, [
|
|
233
|
+
data,
|
|
234
|
+
onBlur,
|
|
235
|
+
visible,
|
|
236
|
+
disable,
|
|
237
|
+
onFocus,
|
|
238
|
+
onMeasure,
|
|
239
|
+
searchText,
|
|
240
|
+
scrollIndex,
|
|
241
|
+
keyboardHeight,
|
|
242
|
+
]);
|
|
243
|
+
|
|
244
|
+
const onSearch = useCallback(
|
|
245
|
+
(text: string) => {
|
|
246
|
+
if (text.length > 0) {
|
|
247
|
+
const defaultFilterFunction = (e: any) => {
|
|
248
|
+
const item = _.get(e, searchField || labelField)
|
|
249
|
+
?.toLowerCase()
|
|
250
|
+
.replace(' ', '')
|
|
251
|
+
.normalize('NFD')
|
|
252
|
+
.replace(/[\u0300-\u036f]/g, '');
|
|
253
|
+
const key = text
|
|
254
|
+
.toLowerCase()
|
|
255
|
+
.replace(' ', '')
|
|
256
|
+
.normalize('NFD')
|
|
257
|
+
.replace(/[\u0300-\u036f]/g, '');
|
|
258
|
+
|
|
259
|
+
return item.indexOf(key) >= 0;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const propSearchFunction = (e: any) => {
|
|
263
|
+
const labelText = _.get(e, searchField || labelField);
|
|
264
|
+
|
|
265
|
+
return searchQuery?.(text, labelText);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const dataSearch = data.filter(
|
|
269
|
+
searchQuery ? propSearchFunction : defaultFilterFunction,
|
|
270
|
+
);
|
|
271
|
+
setListData(dataSearch);
|
|
272
|
+
} else {
|
|
273
|
+
setListData(data);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
[data, searchField, labelField, searchQuery],
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const onSelect = useCallback(
|
|
280
|
+
(item: any) => {
|
|
281
|
+
if (confirmSelectItem && onConfirmSelectItem) {
|
|
282
|
+
return onConfirmSelectItem(item);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (onChangeText) {
|
|
286
|
+
setSearchText('');
|
|
287
|
+
onChangeText('');
|
|
288
|
+
}
|
|
289
|
+
onSearch('');
|
|
290
|
+
setCurrentValue(item);
|
|
291
|
+
onChange?.(item[valueField]);
|
|
292
|
+
eventClose();
|
|
293
|
+
},
|
|
294
|
+
[
|
|
295
|
+
onChange,
|
|
296
|
+
onSearch,
|
|
297
|
+
eventClose,
|
|
298
|
+
onChangeText,
|
|
299
|
+
confirmSelectItem,
|
|
300
|
+
onConfirmSelectItem,
|
|
301
|
+
],
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const onCheckPress = useCallback(
|
|
305
|
+
(item: any) => {
|
|
306
|
+
setCurrentValue?.((prev: T[]) => {
|
|
307
|
+
const exists = prev?.some?.(
|
|
308
|
+
(i: any) => i[valueField] === item[valueField],
|
|
309
|
+
);
|
|
310
|
+
const va: T[] = exists
|
|
311
|
+
? _.filter(prev, i => i?.[valueField] !== item?.[valueField])
|
|
312
|
+
: [...prev, item];
|
|
313
|
+
const v = va?.map(i => i[valueField]);
|
|
314
|
+
onChange?.(
|
|
315
|
+
item[valueField],
|
|
316
|
+
selectionType === 'multi' ? v : item[valueField],
|
|
317
|
+
);
|
|
318
|
+
return va;
|
|
319
|
+
});
|
|
320
|
+
},
|
|
321
|
+
[setCurrentValue, valueField, onChange, currentValue],
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const onClearPress = useCallback(
|
|
325
|
+
(item: T) => {
|
|
326
|
+
const clone = _.clone(currentValue);
|
|
327
|
+
const rem = _.remove(clone, i => i?.[valueField] !== item[valueField]);
|
|
328
|
+
const val = rem?.map(i => i?.[valueField]);
|
|
329
|
+
setCurrentValue(rem);
|
|
330
|
+
onChange?.(item[valueField] as keyof T, val);
|
|
331
|
+
},
|
|
332
|
+
[onChange],
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
ref,
|
|
337
|
+
font,
|
|
338
|
+
refList,
|
|
339
|
+
visible,
|
|
340
|
+
position,
|
|
341
|
+
onSelect,
|
|
342
|
+
onSearch,
|
|
343
|
+
listData,
|
|
344
|
+
onMeasure,
|
|
345
|
+
searchText,
|
|
346
|
+
showOrClose,
|
|
347
|
+
scrollIndex,
|
|
348
|
+
currentValue,
|
|
349
|
+
onCheckPress,
|
|
350
|
+
onClearPress,
|
|
351
|
+
setSearchText,
|
|
352
|
+
keyboardHeight,
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export default useDropdown;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Dimensions, ScaledSize } from 'react-native';
|
|
3
|
+
|
|
4
|
+
const isOrientationPortrait = ({ width, height }: ScaledSize) =>
|
|
5
|
+
height >= width;
|
|
6
|
+
const isOrientationLandscape = ({ width, height }: ScaledSize) =>
|
|
7
|
+
width >= height;
|
|
8
|
+
|
|
9
|
+
export function useDeviceOrientation() {
|
|
10
|
+
const screen = Dimensions.get('screen');
|
|
11
|
+
const initialState = {
|
|
12
|
+
portrait: isOrientationPortrait(screen),
|
|
13
|
+
landscape: isOrientationLandscape(screen),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const [orientation, setOrientation] = useState(initialState);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const onChange = ({ screen: screens }: { screen: ScaledSize }) => {
|
|
20
|
+
setOrientation({
|
|
21
|
+
portrait: isOrientationPortrait(screens),
|
|
22
|
+
landscape: isOrientationLandscape(screens),
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const subscription = Dimensions.addEventListener('change', onChange);
|
|
27
|
+
|
|
28
|
+
return () => {
|
|
29
|
+
if (typeof subscription?.remove === 'function') {
|
|
30
|
+
subscription.remove();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
return orientation.portrait ? 'PORTRAIT' : 'LANDSCAPE';
|
|
36
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
StyleProp,
|
|
4
|
+
TextStyle,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
TextProps,
|
|
7
|
+
ImageStyle,
|
|
8
|
+
FlatListProps,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { ThemeColors } from '../../../interface/colors.interface';
|
|
11
|
+
|
|
12
|
+
export type IDropdownRef = {
|
|
13
|
+
open: () => void;
|
|
14
|
+
close: () => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type SelectionType = 'single' | 'multi';
|
|
18
|
+
|
|
19
|
+
export type DropdownProps<S, T extends SelectionType> = {
|
|
20
|
+
data: S[];
|
|
21
|
+
testID?: string;
|
|
22
|
+
search?: boolean;
|
|
23
|
+
disable?: boolean;
|
|
24
|
+
selectionType?: T;
|
|
25
|
+
maxHeight?: number;
|
|
26
|
+
iconColor?: string;
|
|
27
|
+
minHeight?: number;
|
|
28
|
+
inverted?: boolean;
|
|
29
|
+
fontFamily?: string;
|
|
30
|
+
labelField: keyof S;
|
|
31
|
+
valueField: keyof S;
|
|
32
|
+
onBlur?: () => void;
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
onFocus?: () => void;
|
|
35
|
+
autoScroll?: boolean;
|
|
36
|
+
searchField?: keyof S;
|
|
37
|
+
value?: S[] | undefined;
|
|
38
|
+
itemTestIDField?: string;
|
|
39
|
+
backgroundColor?: string;
|
|
40
|
+
keyboardAvoiding?: boolean;
|
|
41
|
+
searchPlaceholder?: string;
|
|
42
|
+
label?: string | undefined;
|
|
43
|
+
confirmSelectItem?: boolean;
|
|
44
|
+
accessibilityLabel?: string;
|
|
45
|
+
style?: StyleProp<ViewStyle>;
|
|
46
|
+
subfixIcon?: React.JSX.Element;
|
|
47
|
+
onClear?: (id?: number) => void;
|
|
48
|
+
multiSelectIcon?:React.JSX.Element;
|
|
49
|
+
checkIconColor?: keyof ThemeColors;
|
|
50
|
+
radioIconColor?: keyof ThemeColors;
|
|
51
|
+
onChange?: (
|
|
52
|
+
selecteValue?: keyof S,
|
|
53
|
+
selectedList?: SelectionType extends 'single' | 'multi' ? S[] : S,
|
|
54
|
+
) => void;
|
|
55
|
+
selectedTextProps?: TextProps;
|
|
56
|
+
activeColor?: keyof ThemeColors;
|
|
57
|
+
iconStyle?: StyleProp<ImageStyle>;
|
|
58
|
+
mode?: 'default' | 'modal' | 'auto';
|
|
59
|
+
itemTextStyle?: StyleProp<TextStyle>;
|
|
60
|
+
itemAccessibilityLabelField?: string;
|
|
61
|
+
labelContainer?: StyleProp<ViewStyle>;
|
|
62
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
63
|
+
labelTextStyle?: StyleProp<TextStyle>;
|
|
64
|
+
showsVerticalScrollIndicator?: boolean;
|
|
65
|
+
placeholderStyle?: StyleProp<TextStyle>;
|
|
66
|
+
inputSearchStyle?: StyleProp<TextStyle>;
|
|
67
|
+
onChangeText?: (search: string) => void;
|
|
68
|
+
onConfirmSelectItem?: (item: T) => void;
|
|
69
|
+
selectedTextStyle?: StyleProp<TextStyle>;
|
|
70
|
+
itemContainerStyle?: StyleProp<ViewStyle>;
|
|
71
|
+
dropdownPosition?: 'auto' | 'top' | 'bottom';
|
|
72
|
+
ref?: React.RefObject<IDropdownRef> | null | undefined;
|
|
73
|
+
searchQuery?: (keyword: string, labelValue: string) => boolean;
|
|
74
|
+
flatListProps?: Omit<FlatListProps<any>, 'renderItem' | 'data'>;
|
|
75
|
+
renderRightIcon?: (visible?: boolean) => React.JSX.Element | null | undefined;
|
|
76
|
+
renderLeftIcon?: (visible?: boolean) => React.JSX.Element | null | undefined;
|
|
77
|
+
renderItem?: (
|
|
78
|
+
item: S,
|
|
79
|
+
selected?: boolean,
|
|
80
|
+
) => React.JSX.Element | null | undefined;
|
|
81
|
+
renderInputSearch?: (
|
|
82
|
+
onSearch: (text: string) => void,
|
|
83
|
+
) => React.JSX.Element | null | undefined;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export interface IUseDetectDevice {
|
|
87
|
+
isAndroid: boolean;
|
|
88
|
+
isIOS: boolean;
|
|
89
|
+
isTablet: boolean;
|
|
90
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { StyleProp, ViewStyle, TextInputProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
interface Props extends TextInputProps {
|
|
5
|
+
style?: StyleProp<ViewStyle>;
|
|
6
|
+
searchIcon?: React.JSX.Element;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type CTextInput = React.FC<Props>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSvgButtonStyle } from './SvgButtonStyle';
|
|
3
|
+
import { Pressable, StyleProp, ViewStyle, PressableProps } from 'react-native';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
isFab?: boolean;
|
|
7
|
+
onPress?: () => void;
|
|
8
|
+
icon?: React.JSX.Element;
|
|
9
|
+
style?: StyleProp<ViewStyle>;
|
|
10
|
+
pressableProps?: PressableProps;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const SvgButton = React.memo(
|
|
14
|
+
({
|
|
15
|
+
icon,
|
|
16
|
+
style,
|
|
17
|
+
onPress,
|
|
18
|
+
isFab = false,
|
|
19
|
+
pressableProps,
|
|
20
|
+
}: Props) => {
|
|
21
|
+
const { styles } = useSvgButtonStyle();
|
|
22
|
+
const styleProp = isFab ? [styles?.favIcon, style] : style;
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Pressable
|
|
26
|
+
hitSlop={10}
|
|
27
|
+
style={styleProp}
|
|
28
|
+
onPress={onPress}
|
|
29
|
+
{...pressableProps}
|
|
30
|
+
>
|
|
31
|
+
{icon && icon}
|
|
32
|
+
</Pressable>
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export default SvgButton;
|