rn-vs-lb 1.0.9 → 1.0.11
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/package.json +2 -3
- package/src/form/AutoComplete.tsx +0 -137
- package/src/form/DatePicker.tsx +0 -145
- package/src/form/ImageUploader.tsx +0 -157
- package/src/form/MultiSelect.tsx +0 -123
- package/src/form/PasswordInput.tsx +0 -63
- package/src/form/Select.tsx +0 -93
- package/src/form/TextArea.tsx +0 -77
- package/src/form/TextInput.tsx +0 -88
- package/src/form/commonFormStyles.ts +0 -28
- package/src/form/index.ts +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-vs-lb",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/types/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"files": [
|
|
19
|
-
"dist"
|
|
20
|
-
"src/form"
|
|
19
|
+
"dist"
|
|
21
20
|
],
|
|
22
21
|
"exports": {
|
|
23
22
|
".": {
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import React, { useState, useRef } from 'react';
|
|
2
|
-
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
|
3
|
-
import axios from 'axios';
|
|
4
|
-
import Autocomplete from 'react-native-autocomplete-input';
|
|
5
|
-
import { debounce } from 'lodash';
|
|
6
|
-
import { Controller } from 'react-hook-form';
|
|
7
|
-
|
|
8
|
-
import { commonStyles } from './commonFormStyles';
|
|
9
|
-
|
|
10
|
-
export type AddressFieldProps = {
|
|
11
|
-
name: string;
|
|
12
|
-
control: any;
|
|
13
|
-
label?: string;
|
|
14
|
-
placeholder?: string;
|
|
15
|
-
rules?: object;
|
|
16
|
-
defaultValue?: string;
|
|
17
|
-
setMarkerFromAddress?: (coords: [number, number]) => void;
|
|
18
|
-
required?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
interface AddressResult {
|
|
22
|
-
display_name: string;
|
|
23
|
-
lat?: string;
|
|
24
|
-
lon?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const AddressField: React.FC<AddressFieldProps> = ({
|
|
28
|
-
name,
|
|
29
|
-
control,
|
|
30
|
-
label,
|
|
31
|
-
placeholder = "Search for an address",
|
|
32
|
-
rules = {},
|
|
33
|
-
defaultValue = "",
|
|
34
|
-
setMarkerFromAddress,
|
|
35
|
-
required,
|
|
36
|
-
}) => {
|
|
37
|
-
const [addresses, setAddresses] = useState<AddressResult[]>([]);
|
|
38
|
-
const [query, setQuery] = useState<string>(defaultValue);
|
|
39
|
-
|
|
40
|
-
const searchAddresses = useRef(
|
|
41
|
-
debounce(async (value: string) => {
|
|
42
|
-
if (value.trim() === "") {
|
|
43
|
-
setAddresses([]);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const response = await axios.get(
|
|
48
|
-
`https://nominatim.openstreetmap.org/search?format=json&q=${value}`
|
|
49
|
-
);
|
|
50
|
-
if (response.data.length > 0) {
|
|
51
|
-
setAddresses(response.data);
|
|
52
|
-
} else {
|
|
53
|
-
setAddresses([{ display_name: value }]); // Если адрес не найден, сохраняем введенное значение
|
|
54
|
-
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error("Error fetching addresses:", error);
|
|
57
|
-
}
|
|
58
|
-
}, 2000)
|
|
59
|
-
).current;
|
|
60
|
-
|
|
61
|
-
const handleSearch = (value: string) => {
|
|
62
|
-
setQuery(value);
|
|
63
|
-
searchAddresses(value);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const handleSelectAddress = (address: AddressResult, onChange: any) => {
|
|
67
|
-
// Устанавливаем введенный адрес в поле
|
|
68
|
-
setQuery(address.display_name);
|
|
69
|
-
setAddresses([]);
|
|
70
|
-
onChange(address.display_name);
|
|
71
|
-
|
|
72
|
-
if (address.lat && address.lon && setMarkerFromAddress) {
|
|
73
|
-
setMarkerFromAddress([Number(address.lat), Number(address.lon)]);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<View style={styles.container}>
|
|
79
|
-
{label && <Text style={commonStyles.label}>
|
|
80
|
-
{required && <Text style={commonStyles.required}>* </Text>}
|
|
81
|
-
{label}
|
|
82
|
-
</Text>}
|
|
83
|
-
<Controller
|
|
84
|
-
control={control}
|
|
85
|
-
name={name}
|
|
86
|
-
rules={rules}
|
|
87
|
-
defaultValue={defaultValue}
|
|
88
|
-
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
|
89
|
-
<>
|
|
90
|
-
<Autocomplete
|
|
91
|
-
data={addresses}
|
|
92
|
-
value={query} // Привязываем значение поля к состоянию query
|
|
93
|
-
onChangeText={handleSearch}
|
|
94
|
-
placeholder={placeholder}
|
|
95
|
-
flatListProps={{
|
|
96
|
-
keyExtractor: (item) => item.display_name,
|
|
97
|
-
renderItem: ({ item }) => (
|
|
98
|
-
<TouchableOpacity onPress={() => handleSelectAddress(item, onChange)}>
|
|
99
|
-
<Text style={styles.itemText}>{item.display_name}</Text>
|
|
100
|
-
</TouchableOpacity>
|
|
101
|
-
),
|
|
102
|
-
}}
|
|
103
|
-
inputContainerStyle={[commonStyles.inputBorder, commonStyles.inputContainer]}
|
|
104
|
-
listContainerStyle={styles.listContainer}
|
|
105
|
-
// listStyle={styles.list}
|
|
106
|
-
/>
|
|
107
|
-
{error && <Text style={commonStyles.errorText}>{error.message}</Text>}
|
|
108
|
-
</>
|
|
109
|
-
)}
|
|
110
|
-
/>
|
|
111
|
-
</View>
|
|
112
|
-
);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const styles = StyleSheet.create({
|
|
116
|
-
container: {
|
|
117
|
-
margin: 0,
|
|
118
|
-
zIndex: 1, // ensures the container stays above other elements
|
|
119
|
-
},
|
|
120
|
-
listContainer: {
|
|
121
|
-
borderWidth: 0,
|
|
122
|
-
borderColor: '#ccc',
|
|
123
|
-
borderRadius: 5,
|
|
124
|
-
backgroundColor: '#fff',
|
|
125
|
-
maxHeight: 200,
|
|
126
|
-
zIndex: 10,
|
|
127
|
-
},
|
|
128
|
-
list: {
|
|
129
|
-
borderWidth: 0,
|
|
130
|
-
},
|
|
131
|
-
itemText: {
|
|
132
|
-
padding: 10,
|
|
133
|
-
fontSize: 16,
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
export default AddressField;
|
package/src/form/DatePicker.tsx
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View, Text, TouchableOpacity, StyleSheet, Platform } from 'react-native';
|
|
3
|
-
import { Controller } from 'react-hook-form';
|
|
4
|
-
import DateTimePicker from '@react-native-community/datetimepicker';
|
|
5
|
-
|
|
6
|
-
import { commonStyles } from './commonFormStyles';
|
|
7
|
-
|
|
8
|
-
export interface DatePickerProps {
|
|
9
|
-
name: string;
|
|
10
|
-
control: any;
|
|
11
|
-
label?: string;
|
|
12
|
-
style?: object;
|
|
13
|
-
containerStyle?: object;
|
|
14
|
-
rules?: object;
|
|
15
|
-
defaultValue?: Date;
|
|
16
|
-
errorTextStyle?: object;
|
|
17
|
-
required?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const DatePicker: React.FC<DatePickerProps> = ({
|
|
21
|
-
name,
|
|
22
|
-
control,
|
|
23
|
-
label,
|
|
24
|
-
style,
|
|
25
|
-
containerStyle,
|
|
26
|
-
rules = {},
|
|
27
|
-
defaultValue = new Date(), // Значение по умолчанию - текущая дата
|
|
28
|
-
errorTextStyle,
|
|
29
|
-
required,
|
|
30
|
-
}) => {
|
|
31
|
-
const [showDatePicker, setShowDatePicker] = React.useState(false);
|
|
32
|
-
const [showTimePicker, setShowTimePicker] = React.useState(false);
|
|
33
|
-
|
|
34
|
-
const handleDateChange = (event: any, selectedDate: Date | undefined, onChange: any, currentValue: Date) => {
|
|
35
|
-
const currentDate = selectedDate || currentValue || defaultValue;
|
|
36
|
-
|
|
37
|
-
// Сохраняем выбранное время при изменении даты
|
|
38
|
-
if (currentValue) {
|
|
39
|
-
currentDate.setHours(currentValue.getHours());
|
|
40
|
-
currentDate.setMinutes(currentValue.getMinutes());
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setShowDatePicker(false);
|
|
44
|
-
onChange(currentDate); // Обновляем значение в форме
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const handleTimeChange = (event: any, selectedTime: Date | undefined, onChange: any, currentValue: Date) => {
|
|
48
|
-
setShowTimePicker(false);
|
|
49
|
-
|
|
50
|
-
if (selectedTime) {
|
|
51
|
-
const currentDate = currentValue || defaultValue;
|
|
52
|
-
|
|
53
|
-
// Сохраняем выбранную дату при изменении времени
|
|
54
|
-
currentDate.setHours(selectedTime.getHours());
|
|
55
|
-
currentDate.setMinutes(selectedTime.getMinutes());
|
|
56
|
-
|
|
57
|
-
onChange(currentDate); // Обновляем значение в форме
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<View style={[styles.container, containerStyle]}>
|
|
63
|
-
{label && <Text style={commonStyles.label}>
|
|
64
|
-
{required && <Text style={commonStyles.required}>* </Text>}
|
|
65
|
-
{label}
|
|
66
|
-
</Text>}
|
|
67
|
-
<Controller
|
|
68
|
-
control={control}
|
|
69
|
-
name={name}
|
|
70
|
-
rules={rules}
|
|
71
|
-
defaultValue={defaultValue}
|
|
72
|
-
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
|
73
|
-
<>
|
|
74
|
-
<View style={[commonStyles.inputBorder, commonStyles.inputContainer, styles.row]}>
|
|
75
|
-
<TouchableOpacity
|
|
76
|
-
style={[styles.buttonContainer, styles.dateButtonContainer]}
|
|
77
|
-
onPress={() => setShowDatePicker(true)}
|
|
78
|
-
>
|
|
79
|
-
<Text style={styles.buttonText}>
|
|
80
|
-
{value ? value.toDateString() : 'Select a date'}
|
|
81
|
-
</Text>
|
|
82
|
-
</TouchableOpacity>
|
|
83
|
-
<TouchableOpacity
|
|
84
|
-
style={[styles.buttonContainer, styles.timeButtonContainer]}
|
|
85
|
-
onPress={() => setShowTimePicker(true)}
|
|
86
|
-
>
|
|
87
|
-
<Text style={styles.buttonText}>
|
|
88
|
-
{value ? value.toTimeString().slice(0, 5) : 'Select time'}
|
|
89
|
-
</Text>
|
|
90
|
-
</TouchableOpacity>
|
|
91
|
-
</View>
|
|
92
|
-
{showDatePicker && (
|
|
93
|
-
<DateTimePicker
|
|
94
|
-
value={value || defaultValue}
|
|
95
|
-
mode="date"
|
|
96
|
-
display="default"
|
|
97
|
-
onChange={(event, selectedDate) =>
|
|
98
|
-
handleDateChange(event, selectedDate, onChange, value)
|
|
99
|
-
}
|
|
100
|
-
/>
|
|
101
|
-
)}
|
|
102
|
-
{showTimePicker && (
|
|
103
|
-
<DateTimePicker
|
|
104
|
-
value={value || defaultValue}
|
|
105
|
-
mode="time"
|
|
106
|
-
display="default"
|
|
107
|
-
onChange={(event, selectedTime) =>
|
|
108
|
-
handleTimeChange(event, selectedTime, onChange, value)
|
|
109
|
-
}
|
|
110
|
-
/>
|
|
111
|
-
)}
|
|
112
|
-
{error && <Text style={[commonStyles.errorText, errorTextStyle]}>{error.message}</Text>}
|
|
113
|
-
</>
|
|
114
|
-
)}
|
|
115
|
-
/>
|
|
116
|
-
</View>
|
|
117
|
-
);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const styles = StyleSheet.create({
|
|
121
|
-
container: {
|
|
122
|
-
margin: 0,
|
|
123
|
-
},
|
|
124
|
-
row: {
|
|
125
|
-
flexDirection: 'row',
|
|
126
|
-
justifyContent: 'space-between',
|
|
127
|
-
},
|
|
128
|
-
buttonContainer: {
|
|
129
|
-
justifyContent: 'center',
|
|
130
|
-
backgroundColor: '#fff',
|
|
131
|
-
},
|
|
132
|
-
buttonText: {
|
|
133
|
-
color: 'black',
|
|
134
|
-
fontSize: 16,
|
|
135
|
-
},
|
|
136
|
-
dateButtonContainer: {
|
|
137
|
-
flex: 0.6, // 60% ширины
|
|
138
|
-
},
|
|
139
|
-
timeButtonContainer: {
|
|
140
|
-
flex: 0.4, // 40% ширины
|
|
141
|
-
alignItems: "center",
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
export default DatePicker;
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { View, Text, StyleSheet, Image, TouchableOpacity } from 'react-native';
|
|
3
|
-
import { Controller } from 'react-hook-form';
|
|
4
|
-
import * as ImagePicker from 'expo-image-picker';
|
|
5
|
-
|
|
6
|
-
import { commonStyles } from './commonFormStyles';
|
|
7
|
-
|
|
8
|
-
export interface ImageUploaderProps {
|
|
9
|
-
name: string;
|
|
10
|
-
control: any;
|
|
11
|
-
label?: string;
|
|
12
|
-
style?: object;
|
|
13
|
-
containerStyle?: object;
|
|
14
|
-
rules?: object;
|
|
15
|
-
defaultValue?: string[];
|
|
16
|
-
errorTextStyle?: object;
|
|
17
|
-
required?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const ImageUploader: React.FC<ImageUploaderProps> = ({
|
|
21
|
-
name,
|
|
22
|
-
control,
|
|
23
|
-
label,
|
|
24
|
-
style,
|
|
25
|
-
containerStyle,
|
|
26
|
-
rules = {},
|
|
27
|
-
defaultValue = [],
|
|
28
|
-
errorTextStyle,
|
|
29
|
-
required,
|
|
30
|
-
}) => {
|
|
31
|
-
const [imageUris, setImageUris] = useState<string[]>(defaultValue);
|
|
32
|
-
|
|
33
|
-
const handleImagePick = async (onChange: any) => {
|
|
34
|
-
if (imageUris.length >= 3) {
|
|
35
|
-
alert('You can upload a maximum of 3 images');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Запрашиваем разрешение на доступ к медиатеке
|
|
40
|
-
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
|
|
41
|
-
if (status !== 'granted') {
|
|
42
|
-
alert('Sorry, we need camera roll permissions to make this work!');
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let result = await ImagePicker.launchImageLibraryAsync({
|
|
47
|
-
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
|
48
|
-
allowsEditing: true,
|
|
49
|
-
aspect: [4, 3],
|
|
50
|
-
quality: 1,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
if (!result.canceled && result.assets.length > 0) {
|
|
54
|
-
const selectedImageUri = result.assets[0].uri;
|
|
55
|
-
const updatedUris = [...imageUris, selectedImageUri];
|
|
56
|
-
setImageUris(updatedUris);
|
|
57
|
-
onChange(updatedUris);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const handleRemoveImage = (uri: string, onChange: any) => {
|
|
62
|
-
const updatedUris = imageUris.filter(imageUri => imageUri !== uri);
|
|
63
|
-
setImageUris(updatedUris);
|
|
64
|
-
onChange(updatedUris);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<View style={[styles.container, containerStyle]}>
|
|
69
|
-
{label && <Text style={commonStyles.label}>
|
|
70
|
-
{required && <Text style={commonStyles.required}>* </Text>}
|
|
71
|
-
{label}
|
|
72
|
-
</Text>}
|
|
73
|
-
<Controller
|
|
74
|
-
control={control}
|
|
75
|
-
name={name}
|
|
76
|
-
rules={rules}
|
|
77
|
-
defaultValue={defaultValue}
|
|
78
|
-
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
|
79
|
-
<>
|
|
80
|
-
<TouchableOpacity
|
|
81
|
-
style={[commonStyles.inputBorder, styles.uploadButton, style]}
|
|
82
|
-
onPress={() => handleImagePick(onChange)}
|
|
83
|
-
>
|
|
84
|
-
<Text style={styles.uploadButtonText}>
|
|
85
|
-
{imageUris.length < 3 ? 'Upload Image' : 'Maximum 3 images'}
|
|
86
|
-
</Text>
|
|
87
|
-
</TouchableOpacity>
|
|
88
|
-
<View style={styles.imageContainer}>
|
|
89
|
-
{imageUris.map((uri) => (
|
|
90
|
-
<View key={uri} style={styles.imageWrapper}>
|
|
91
|
-
<Image source={{ uri: uri }} style={styles.imagePreview} />
|
|
92
|
-
<TouchableOpacity
|
|
93
|
-
style={styles.removeButton}
|
|
94
|
-
onPress={() => handleRemoveImage(uri, onChange)}
|
|
95
|
-
>
|
|
96
|
-
<Text style={styles.removeButtonText}>X</Text>
|
|
97
|
-
</TouchableOpacity>
|
|
98
|
-
</View>
|
|
99
|
-
))}
|
|
100
|
-
</View>
|
|
101
|
-
{error && <Text style={[commonStyles.errorText, errorTextStyle]}>{error.message}</Text>}
|
|
102
|
-
</>
|
|
103
|
-
)}
|
|
104
|
-
/>
|
|
105
|
-
</View>
|
|
106
|
-
);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const styles = StyleSheet.create({
|
|
110
|
-
container: {
|
|
111
|
-
margin: 10,
|
|
112
|
-
},
|
|
113
|
-
uploadButton: {
|
|
114
|
-
backgroundColor: '#fff',
|
|
115
|
-
padding: 10,
|
|
116
|
-
justifyContent: 'center',
|
|
117
|
-
alignItems: 'center',
|
|
118
|
-
},
|
|
119
|
-
uploadButtonText: {
|
|
120
|
-
color: 'black',
|
|
121
|
-
fontSize: 16,
|
|
122
|
-
},
|
|
123
|
-
imageContainer: {
|
|
124
|
-
flexDirection: 'row',
|
|
125
|
-
flexWrap: 'wrap',
|
|
126
|
-
marginTop: 10,
|
|
127
|
-
},
|
|
128
|
-
imageWrapper: {
|
|
129
|
-
position: 'relative',
|
|
130
|
-
marginRight: 10,
|
|
131
|
-
marginBottom: 10,
|
|
132
|
-
},
|
|
133
|
-
imagePreview: {
|
|
134
|
-
width: 100,
|
|
135
|
-
height: 100,
|
|
136
|
-
borderColor: '#ccc',
|
|
137
|
-
borderWidth: 1,
|
|
138
|
-
borderRadius: 5,
|
|
139
|
-
},
|
|
140
|
-
removeButton: {
|
|
141
|
-
position: 'absolute',
|
|
142
|
-
top: 2,
|
|
143
|
-
right: 2,
|
|
144
|
-
backgroundColor: '#ccc',
|
|
145
|
-
borderRadius: 15,
|
|
146
|
-
width: 25,
|
|
147
|
-
height: 25,
|
|
148
|
-
justifyContent: 'center',
|
|
149
|
-
alignItems: 'center',
|
|
150
|
-
},
|
|
151
|
-
removeButtonText: {
|
|
152
|
-
color: 'white',
|
|
153
|
-
fontSize: 14,
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
export default ImageUploader;
|
package/src/form/MultiSelect.tsx
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
|
3
|
-
import { Controller } from 'react-hook-form';
|
|
4
|
-
import { Picker } from '@react-native-picker/picker';
|
|
5
|
-
import { Ionicons } from '@expo/vector-icons';
|
|
6
|
-
|
|
7
|
-
import { commonStyles } from './commonFormStyles';
|
|
8
|
-
|
|
9
|
-
export interface MultiSelectProps {
|
|
10
|
-
name: string;
|
|
11
|
-
control: any;
|
|
12
|
-
options: { label: string; value: string }[];
|
|
13
|
-
label?: string;
|
|
14
|
-
style?: object;
|
|
15
|
-
containerStyle?: object;
|
|
16
|
-
rules?: object;
|
|
17
|
-
placeholder?: string;
|
|
18
|
-
errorTextStyle?: object;
|
|
19
|
-
required?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const MultiSelect: React.FC<MultiSelectProps> = ({
|
|
23
|
-
name,
|
|
24
|
-
control,
|
|
25
|
-
options,
|
|
26
|
-
label,
|
|
27
|
-
style,
|
|
28
|
-
containerStyle,
|
|
29
|
-
rules = {},
|
|
30
|
-
placeholder = "Select...",
|
|
31
|
-
errorTextStyle,
|
|
32
|
-
required
|
|
33
|
-
}) => {
|
|
34
|
-
return (
|
|
35
|
-
<View style={[styles.container, containerStyle]}>
|
|
36
|
-
{label && <Text style={commonStyles.label}>
|
|
37
|
-
{required && <Text style={commonStyles.required}>* </Text>}
|
|
38
|
-
{label}
|
|
39
|
-
</Text>}
|
|
40
|
-
<View style={[style]}>
|
|
41
|
-
<Controller
|
|
42
|
-
control={control}
|
|
43
|
-
name={name}
|
|
44
|
-
rules={rules}
|
|
45
|
-
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
|
46
|
-
<>
|
|
47
|
-
<View style={[commonStyles.inputBorder, commonStyles.inputContainer, styles.inputContainer]}>
|
|
48
|
-
<Picker
|
|
49
|
-
selectedValue=""
|
|
50
|
-
onValueChange={(itemValue) => {
|
|
51
|
-
if (itemValue && !value.includes(itemValue)) {
|
|
52
|
-
onChange([...value, itemValue]);
|
|
53
|
-
}
|
|
54
|
-
}}
|
|
55
|
-
style={[pickerStyles.picker]}
|
|
56
|
-
>
|
|
57
|
-
<Picker.Item label={placeholder} value="" />
|
|
58
|
-
{options.map(option => (
|
|
59
|
-
<Picker.Item label={option.label} value={option.value} key={option.value} />
|
|
60
|
-
))}
|
|
61
|
-
</Picker>
|
|
62
|
-
</View>
|
|
63
|
-
|
|
64
|
-
<View style={styles.selectedContainer}>
|
|
65
|
-
{value?.map((item: string) => (
|
|
66
|
-
<View key={item} style={styles.selectedItem}>
|
|
67
|
-
<Text style={styles.selectedItemText}>{item}</Text>
|
|
68
|
-
<TouchableOpacity
|
|
69
|
-
onPress={() => onChange(value.filter((selectedItem: string) => selectedItem !== item))}
|
|
70
|
-
>
|
|
71
|
-
<Ionicons name="close" size={18} color="black" />
|
|
72
|
-
</TouchableOpacity>
|
|
73
|
-
</View>
|
|
74
|
-
))}
|
|
75
|
-
</View>
|
|
76
|
-
|
|
77
|
-
{error && <Text style={[commonStyles.errorText, errorTextStyle]}>{error.message}</Text>}
|
|
78
|
-
</>
|
|
79
|
-
)}
|
|
80
|
-
defaultValue={[]}
|
|
81
|
-
/>
|
|
82
|
-
</View>
|
|
83
|
-
</View>
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const styles = StyleSheet.create({
|
|
88
|
-
container: {
|
|
89
|
-
margin: 0,
|
|
90
|
-
},
|
|
91
|
-
inputContainer: {
|
|
92
|
-
overflow: 'hidden',
|
|
93
|
-
justifyContent: 'center',
|
|
94
|
-
paddingHorizontal: 0,
|
|
95
|
-
},
|
|
96
|
-
selectedContainer: {
|
|
97
|
-
flexDirection: 'row',
|
|
98
|
-
flexWrap: 'wrap',
|
|
99
|
-
marginTop: 10,
|
|
100
|
-
},
|
|
101
|
-
selectedItem: {
|
|
102
|
-
flexDirection: 'row',
|
|
103
|
-
alignItems: 'center',
|
|
104
|
-
backgroundColor: '#e0e0e0',
|
|
105
|
-
borderRadius: 15,
|
|
106
|
-
paddingVertical: 5,
|
|
107
|
-
paddingHorizontal: 10,
|
|
108
|
-
marginRight: 5,
|
|
109
|
-
marginBottom: 5,
|
|
110
|
-
},
|
|
111
|
-
selectedItemText: {
|
|
112
|
-
marginRight: 5,
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const pickerStyles = StyleSheet.create({
|
|
117
|
-
picker: {
|
|
118
|
-
height: "100%",
|
|
119
|
-
borderWidth: 0,
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
export default MultiSelect;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { View, TextInput, StyleSheet, TouchableOpacity } from 'react-native';
|
|
3
|
-
import Icon from 'react-native-vector-icons/Ionicons';
|
|
4
|
-
|
|
5
|
-
import { commonStyles } from './commonFormStyles';
|
|
6
|
-
|
|
7
|
-
interface PasswordInputProps {
|
|
8
|
-
value: string;
|
|
9
|
-
onChange: (text: string) => void;
|
|
10
|
-
onBlur?: () => void;
|
|
11
|
-
placeholder?: string;
|
|
12
|
-
error?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const PasswordInput: React.FC<PasswordInputProps> = ({ value, onChange, onBlur, placeholder, error }) => {
|
|
16
|
-
const [isPasswordVisible, setIsPasswordVisible] = useState<boolean>(false);
|
|
17
|
-
|
|
18
|
-
const togglePasswordVisibility = () => {
|
|
19
|
-
setIsPasswordVisible(!isPasswordVisible);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<View style={[styles.inputContainer, commonStyles.inputBorder, commonStyles.inputContainer]}>
|
|
24
|
-
<TextInput
|
|
25
|
-
style={[styles.input, error && styles.inputError]}
|
|
26
|
-
onBlur={onBlur}
|
|
27
|
-
onChangeText={onChange}
|
|
28
|
-
value={value}
|
|
29
|
-
placeholder={placeholder}
|
|
30
|
-
placeholderTextColor="#ccc"
|
|
31
|
-
secureTextEntry={!isPasswordVisible}
|
|
32
|
-
/>
|
|
33
|
-
<TouchableOpacity style={styles.icon} onPress={togglePasswordVisibility}>
|
|
34
|
-
<Icon
|
|
35
|
-
name={isPasswordVisible ? "eye-off" : "eye"}
|
|
36
|
-
size={24}
|
|
37
|
-
color="gray"
|
|
38
|
-
/>
|
|
39
|
-
</TouchableOpacity>
|
|
40
|
-
</View>
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const styles = StyleSheet.create({
|
|
45
|
-
inputContainer: {
|
|
46
|
-
position: 'relative',
|
|
47
|
-
display: "flex",
|
|
48
|
-
flexDirection: 'row',
|
|
49
|
-
justifyContent: "space-between",
|
|
50
|
-
alignItems: "center",
|
|
51
|
-
},
|
|
52
|
-
input: {
|
|
53
|
-
flex: 1,
|
|
54
|
-
paddingRight: 50, // Место для иконки
|
|
55
|
-
},
|
|
56
|
-
icon: {
|
|
57
|
-
},
|
|
58
|
-
inputError: {
|
|
59
|
-
borderColor: 'red',
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
export default PasswordInput;
|
package/src/form/Select.tsx
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View, Text, StyleSheet } from 'react-native';
|
|
3
|
-
import { Controller } from 'react-hook-form';
|
|
4
|
-
import { Picker } from '@react-native-picker/picker';
|
|
5
|
-
|
|
6
|
-
import { commonStyles } from './commonFormStyles';
|
|
7
|
-
|
|
8
|
-
export interface SelectProps {
|
|
9
|
-
name: string;
|
|
10
|
-
control: any;
|
|
11
|
-
label?: string;
|
|
12
|
-
options: { label: string; value: string | number }[];
|
|
13
|
-
placeholder?: string;
|
|
14
|
-
style?: object;
|
|
15
|
-
containerStyle?: object;
|
|
16
|
-
rules?: object;
|
|
17
|
-
defaultValue?: string | number;
|
|
18
|
-
required?: boolean;
|
|
19
|
-
errorTextStyle?: object;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const Select: React.FC<SelectProps> = ({
|
|
23
|
-
name,
|
|
24
|
-
control,
|
|
25
|
-
label,
|
|
26
|
-
options,
|
|
27
|
-
placeholder = 'Select an option...',
|
|
28
|
-
style,
|
|
29
|
-
containerStyle,
|
|
30
|
-
rules = {},
|
|
31
|
-
required,
|
|
32
|
-
defaultValue = '',
|
|
33
|
-
errorTextStyle,
|
|
34
|
-
}) => {
|
|
35
|
-
return (
|
|
36
|
-
<View style={[styles.container, containerStyle]}>
|
|
37
|
-
{label && <Text style={commonStyles.label}>
|
|
38
|
-
{required && <Text style={commonStyles.required}>* </Text>}
|
|
39
|
-
{label}
|
|
40
|
-
</Text>}
|
|
41
|
-
<View style={[style]}>
|
|
42
|
-
<Controller
|
|
43
|
-
control={control}
|
|
44
|
-
name={name}
|
|
45
|
-
rules={rules}
|
|
46
|
-
defaultValue={defaultValue}
|
|
47
|
-
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
|
48
|
-
<>
|
|
49
|
-
<View style={[commonStyles.inputBorder, commonStyles.inputContainer, styles.inputContainer]}>
|
|
50
|
-
<Picker
|
|
51
|
-
selectedValue={value}
|
|
52
|
-
onValueChange={(itemValue) => onChange(itemValue)}
|
|
53
|
-
style={styles.picker}
|
|
54
|
-
>
|
|
55
|
-
{placeholder && (
|
|
56
|
-
<Picker.Item label={placeholder} value="" />
|
|
57
|
-
)}
|
|
58
|
-
{options.map((option) => (
|
|
59
|
-
<Picker.Item
|
|
60
|
-
key={option.value}
|
|
61
|
-
label={option.label}
|
|
62
|
-
value={option.value}
|
|
63
|
-
/>
|
|
64
|
-
))}
|
|
65
|
-
</Picker>
|
|
66
|
-
</View>
|
|
67
|
-
{error && <Text style={[commonStyles.errorText, errorTextStyle]}>{error.message}</Text>}
|
|
68
|
-
</>
|
|
69
|
-
)}
|
|
70
|
-
/>
|
|
71
|
-
</View>
|
|
72
|
-
</View>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const styles = StyleSheet.create({
|
|
77
|
-
container: {
|
|
78
|
-
margin: 0,
|
|
79
|
-
},
|
|
80
|
-
inputContainer: {
|
|
81
|
-
overflow: 'hidden',
|
|
82
|
-
justifyContent: 'center',
|
|
83
|
-
paddingHorizontal: 0,
|
|
84
|
-
},
|
|
85
|
-
picker: {
|
|
86
|
-
height: "100%",
|
|
87
|
-
borderWidth: 0,
|
|
88
|
-
paddingHorizontal: 0,
|
|
89
|
-
padding: 0,
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
export default Select;
|
package/src/form/TextArea.tsx
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { TextInput, StyleSheet, View, Text, TextInputProps } from 'react-native';
|
|
3
|
-
import { Controller } from 'react-hook-form';
|
|
4
|
-
|
|
5
|
-
import { commonStyles } from './commonFormStyles';
|
|
6
|
-
|
|
7
|
-
export interface TextAreaProps extends TextInputProps {
|
|
8
|
-
name: string;
|
|
9
|
-
control: any;
|
|
10
|
-
label?: string;
|
|
11
|
-
placeholder?: string;
|
|
12
|
-
numberOfLines?: number;
|
|
13
|
-
style?: object;
|
|
14
|
-
containerStyle?: object;
|
|
15
|
-
rules?: object;
|
|
16
|
-
defaultValue?: string;
|
|
17
|
-
required?: boolean;
|
|
18
|
-
errorTextStyle?: object;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const TextArea: React.FC<TextAreaProps> = ({
|
|
22
|
-
name,
|
|
23
|
-
control,
|
|
24
|
-
label,
|
|
25
|
-
placeholder = 'Enter text...',
|
|
26
|
-
numberOfLines = 4,
|
|
27
|
-
style,
|
|
28
|
-
containerStyle,
|
|
29
|
-
rules = {},
|
|
30
|
-
defaultValue = '',
|
|
31
|
-
required,
|
|
32
|
-
errorTextStyle,
|
|
33
|
-
...rest
|
|
34
|
-
}) => {
|
|
35
|
-
return (
|
|
36
|
-
<View style={[styles.container, containerStyle]}>
|
|
37
|
-
{label && <Text style={commonStyles.label}>
|
|
38
|
-
{required && <Text style={commonStyles.required}>* </Text>}
|
|
39
|
-
{label}
|
|
40
|
-
</Text>}
|
|
41
|
-
<Controller
|
|
42
|
-
control={control}
|
|
43
|
-
name={name}
|
|
44
|
-
rules={rules}
|
|
45
|
-
defaultValue={defaultValue}
|
|
46
|
-
render={({ field: { onChange, onBlur, value }, fieldState: { error } }) => (
|
|
47
|
-
<>
|
|
48
|
-
<TextInput
|
|
49
|
-
style={[commonStyles.inputBorder, commonStyles.inputContainer, styles.textArea, style]}
|
|
50
|
-
value={value}
|
|
51
|
-
onChangeText={onChange}
|
|
52
|
-
onBlur={onBlur}
|
|
53
|
-
placeholder={placeholder}
|
|
54
|
-
multiline={true}
|
|
55
|
-
numberOfLines={numberOfLines}
|
|
56
|
-
{...rest}
|
|
57
|
-
/>
|
|
58
|
-
{error && <Text style={[commonStyles.errorText, errorTextStyle]}>{error.message}</Text>}
|
|
59
|
-
</>
|
|
60
|
-
)}
|
|
61
|
-
/>
|
|
62
|
-
</View>
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const styles = StyleSheet.create({
|
|
67
|
-
container: {
|
|
68
|
-
margin: 0,
|
|
69
|
-
},
|
|
70
|
-
textArea: {
|
|
71
|
-
height: 150,
|
|
72
|
-
padding: 12,
|
|
73
|
-
textAlignVertical: 'top',
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
export default TextArea;
|
package/src/form/TextInput.tsx
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View, Text, TextInput, StyleSheet } from 'react-native';
|
|
3
|
-
import { useForm, Controller } from 'react-hook-form';
|
|
4
|
-
import PasswordInput from './PasswordInput';
|
|
5
|
-
|
|
6
|
-
import { commonStyles } from './commonFormStyles';
|
|
7
|
-
|
|
8
|
-
export interface InputWithValidationProps {
|
|
9
|
-
name: string;
|
|
10
|
-
control: any;
|
|
11
|
-
label?: string;
|
|
12
|
-
placeholder: string;
|
|
13
|
-
keyboardType?: 'default' | 'email-address' | 'phone-pad' | 'numeric' | 'decimal-pad' | 'number-pad' | 'url' | 'web-search';
|
|
14
|
-
secureTextEntry?: boolean;
|
|
15
|
-
required?: boolean;
|
|
16
|
-
rules?: { required?: boolean | string; [key: string]: any };
|
|
17
|
-
defaultValue?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const InputWithValidation: React.FC<InputWithValidationProps> = ({
|
|
21
|
-
name,
|
|
22
|
-
control,
|
|
23
|
-
label = '',
|
|
24
|
-
placeholder,
|
|
25
|
-
keyboardType = 'default',
|
|
26
|
-
secureTextEntry = false,
|
|
27
|
-
required = false,
|
|
28
|
-
rules = {},
|
|
29
|
-
defaultValue = ''
|
|
30
|
-
}) => {
|
|
31
|
-
const { formState: { errors } } = useForm<{ [key: string]: string }>();
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<View style={styles.container}>
|
|
35
|
-
{label && (
|
|
36
|
-
<Text style={commonStyles.label}>
|
|
37
|
-
{required && <Text style={commonStyles.required}>* </Text>}
|
|
38
|
-
{label}
|
|
39
|
-
</Text>
|
|
40
|
-
)}
|
|
41
|
-
<Controller
|
|
42
|
-
control={control}
|
|
43
|
-
rules={rules}
|
|
44
|
-
name={name}
|
|
45
|
-
defaultValue={defaultValue}
|
|
46
|
-
render={({ field: { onChange, onBlur, value }, fieldState: { error } }) => (
|
|
47
|
-
secureTextEntry ? (
|
|
48
|
-
<>
|
|
49
|
-
<PasswordInput
|
|
50
|
-
value={value}
|
|
51
|
-
onChange={onChange}
|
|
52
|
-
onBlur={onBlur}
|
|
53
|
-
placeholder={placeholder}
|
|
54
|
-
error={!!errors[name]}
|
|
55
|
-
/>
|
|
56
|
-
{error && <Text style={[commonStyles.errorText]}>{error.message}</Text>}
|
|
57
|
-
</>
|
|
58
|
-
) : (
|
|
59
|
-
<>
|
|
60
|
-
<TextInput
|
|
61
|
-
style={[commonStyles.inputBorder, commonStyles.inputContainer, errors[name] && styles.inputError]}
|
|
62
|
-
onBlur={onBlur}
|
|
63
|
-
onChangeText={onChange}
|
|
64
|
-
value={value || defaultValue}
|
|
65
|
-
placeholder={placeholder}
|
|
66
|
-
placeholderTextColor="#ccc"
|
|
67
|
-
keyboardType={keyboardType}
|
|
68
|
-
/>
|
|
69
|
-
{error && <Text style={[commonStyles.errorText]}>{error.message}</Text>}
|
|
70
|
-
</>
|
|
71
|
-
)
|
|
72
|
-
)}
|
|
73
|
-
/>
|
|
74
|
-
{errors[name] && <Text style={commonStyles.errorText}>{(errors[name] as any)?.message}</Text>}
|
|
75
|
-
</View>
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const styles = StyleSheet.create({
|
|
80
|
-
container: {
|
|
81
|
-
padding: 0,
|
|
82
|
-
},
|
|
83
|
-
inputError: {
|
|
84
|
-
borderColor: 'red',
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
export default InputWithValidation;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native';
|
|
2
|
-
|
|
3
|
-
export const commonStyles = StyleSheet.create({
|
|
4
|
-
required: {
|
|
5
|
-
color: 'red',
|
|
6
|
-
},
|
|
7
|
-
label: {
|
|
8
|
-
fontSize: 16,
|
|
9
|
-
fontWeight: '300',
|
|
10
|
-
marginBottom: 5,
|
|
11
|
-
},
|
|
12
|
-
inputBorder: {
|
|
13
|
-
borderColor: '#ccc',
|
|
14
|
-
borderWidth: 1,
|
|
15
|
-
borderRadius: 5,
|
|
16
|
-
},
|
|
17
|
-
inputContainer: {
|
|
18
|
-
height: 50,
|
|
19
|
-
paddingHorizontal: 16,
|
|
20
|
-
backgroundColor: '#fff',
|
|
21
|
-
justifyContent: "center",
|
|
22
|
-
},
|
|
23
|
-
errorText: {
|
|
24
|
-
color: 'red',
|
|
25
|
-
marginTop: 5,
|
|
26
|
-
fontSize: 12,
|
|
27
|
-
},
|
|
28
|
-
});
|
package/src/form/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import TextInput from "./TextInput"
|
|
2
|
-
import TextArea, { TextAreaProps } from "./TextArea"
|
|
3
|
-
import Select, { SelectProps } from "./Select"
|
|
4
|
-
import DatePicker, { DatePickerProps } from "./DatePicker"
|
|
5
|
-
import ImageUploader, { ImageUploaderProps } from "./ImageUploader"
|
|
6
|
-
import MultiSelect, { MultiSelectProps } from "./MultiSelect"
|
|
7
|
-
import AutoComplete, { AddressFieldProps as AutoCompleteProps } from "./AutoComplete"
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
TextInput,
|
|
11
|
-
TextArea,
|
|
12
|
-
TextAreaProps,
|
|
13
|
-
Select,
|
|
14
|
-
SelectProps,
|
|
15
|
-
DatePicker,
|
|
16
|
-
DatePickerProps,
|
|
17
|
-
ImageUploader,
|
|
18
|
-
ImageUploaderProps,
|
|
19
|
-
MultiSelect,
|
|
20
|
-
MultiSelectProps,
|
|
21
|
-
AutoComplete,
|
|
22
|
-
AutoCompleteProps
|
|
23
|
-
}
|