@teamnhz/rn-ui-toolkit 1.0.7 → 1.0.9
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.
|
@@ -8,20 +8,16 @@ interface DateTimePickerProps {
|
|
|
8
8
|
intlType?: string;
|
|
9
9
|
mode?: "date" | "time" | "datetime";
|
|
10
10
|
disabled?: boolean;
|
|
11
|
-
/** raw DatePicker props */
|
|
12
11
|
minimumDate?: Date;
|
|
13
12
|
maximumDate?: Date;
|
|
14
|
-
modal?: boolean;
|
|
15
13
|
confirmText?: string;
|
|
16
14
|
cancelText?: string;
|
|
17
|
-
/** style overrides */
|
|
18
15
|
containerStyle?: StyleProp<ViewStyle>;
|
|
19
16
|
pickerContainerStyle?: StyleProp<ViewStyle>;
|
|
20
17
|
labelStyle?: StyleProp<TextStyle>;
|
|
21
18
|
textStyle?: StyleProp<TextStyle>;
|
|
22
19
|
leftImageStyle?: StyleProp<ImageStyle>;
|
|
23
20
|
rightImageStyle?: StyleProp<ImageStyle>;
|
|
24
|
-
/** icons */
|
|
25
21
|
leftIcon?: ImageSourcePropType;
|
|
26
22
|
rightIcon?: ImageSourcePropType;
|
|
27
23
|
leftIconShow?: boolean;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
2
|
import { View, TouchableOpacity, Text, StyleSheet, Image, } from "react-native";
|
|
3
|
-
import
|
|
3
|
+
import DateTimePickerModal from "react-native-modal-datetime-picker";
|
|
4
4
|
import { useTranslation } from "react-i18next";
|
|
5
5
|
import { Colors, Scale, Typography, Images } from "../../styles";
|
|
6
|
-
const DateTimePicker = ({ value, onChange, label, placeholder, intlType, mode = "date", disabled = false, minimumDate, maximumDate,
|
|
6
|
+
const DateTimePicker = ({ value, onChange, label, placeholder, intlType, mode = "date", disabled = false, minimumDate, maximumDate, confirmText = "Confirm", cancelText = "Cancel", containerStyle, pickerContainerStyle, labelStyle, textStyle, leftImageStyle, rightImageStyle, leftIcon, rightIcon, leftIconShow, onCancel, error, errorTextStyle, }) => {
|
|
7
7
|
const { t } = useTranslation(["common", "validation", "address", "sell"]);
|
|
8
|
-
const [
|
|
9
|
-
|
|
10
|
-
const defaultLeftIcon = mode === "time"
|
|
11
|
-
? Images.ic_time // ⏰ your clock asset
|
|
12
|
-
: Images.ic_calendar; // 📅 your calendar asset
|
|
8
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
9
|
+
const defaultLeftIcon = mode === "time" ? Images.ic_time : Images.ic_calendar;
|
|
13
10
|
const getTranslatedLabel = () => {
|
|
14
11
|
if (intlType) {
|
|
15
12
|
const translated = t(label, { ns: intlType });
|
|
@@ -18,33 +15,32 @@ const DateTimePicker = ({ value, onChange, label, placeholder, intlType, mode =
|
|
|
18
15
|
}
|
|
19
16
|
return label;
|
|
20
17
|
};
|
|
18
|
+
const handleConfirm = (date) => {
|
|
19
|
+
setIsVisible(false);
|
|
20
|
+
onChange(date);
|
|
21
|
+
};
|
|
22
|
+
const handleCancel = () => {
|
|
23
|
+
setIsVisible(false);
|
|
24
|
+
onCancel?.();
|
|
25
|
+
};
|
|
21
26
|
return (React.createElement(View, { style: containerStyle },
|
|
22
27
|
label ? (React.createElement(Text, { style: [styles.label, labelStyle] }, getTranslatedLabel())) : null,
|
|
23
28
|
React.createElement(TouchableOpacity, { style: [
|
|
24
29
|
styles.button,
|
|
25
30
|
pickerContainerStyle,
|
|
26
31
|
disabled && { backgroundColor: Colors.disabledGrey, borderWidth: 0 },
|
|
27
|
-
],
|
|
32
|
+
], onPress: () => !disabled && setIsVisible(true), disabled: disabled },
|
|
28
33
|
leftIconShow && (React.createElement(Image, { source: leftIcon || defaultLeftIcon, style: [styles.icon, leftImageStyle] })),
|
|
29
34
|
React.createElement(Text, { style: [styles.text, textStyle, !value && { color: Colors.textGrey }], numberOfLines: 1 }, value ? formatValue(value, mode) : placeholder || "Select"),
|
|
30
35
|
rightIcon && (React.createElement(Image, { source: rightIcon, style: [styles.icon, rightImageStyle] }))),
|
|
31
36
|
typeof error === "string" && error.length > 0 && (React.createElement(Text, { style: [styles.errorText, errorTextStyle] }, error)),
|
|
32
|
-
React.createElement(
|
|
33
|
-
setOpen(false);
|
|
34
|
-
onChange(val);
|
|
35
|
-
}, onCancel: () => {
|
|
36
|
-
setOpen(false);
|
|
37
|
-
onCancel && onCancel();
|
|
38
|
-
} })));
|
|
37
|
+
React.createElement(DateTimePickerModal, { isVisible: isVisible, mode: mode, date: value || new Date(), minimumDate: minimumDate, maximumDate: maximumDate, onConfirm: handleConfirm, onCancel: handleCancel, confirmTextIOS: confirmText, cancelTextIOS: cancelText, is24Hour: true })));
|
|
39
38
|
};
|
|
40
39
|
const formatValue = (date, mode) => {
|
|
41
40
|
try {
|
|
42
41
|
switch (mode) {
|
|
43
42
|
case "time":
|
|
44
|
-
return date.toLocaleTimeString([], {
|
|
45
|
-
hour: "2-digit",
|
|
46
|
-
minute: "2-digit",
|
|
47
|
-
});
|
|
43
|
+
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
48
44
|
case "datetime":
|
|
49
45
|
return date.toLocaleString();
|
|
50
46
|
default:
|
|
@@ -88,189 +84,3 @@ const styles = StyleSheet.create({
|
|
|
88
84
|
},
|
|
89
85
|
});
|
|
90
86
|
export default DateTimePicker;
|
|
91
|
-
// import React, { useState } from 'react';
|
|
92
|
-
// import {
|
|
93
|
-
// View,
|
|
94
|
-
// TouchableOpacity,
|
|
95
|
-
// Text,
|
|
96
|
-
// StyleSheet,
|
|
97
|
-
// Image,
|
|
98
|
-
// ImageSourcePropType,
|
|
99
|
-
// StyleProp,
|
|
100
|
-
// TextStyle,
|
|
101
|
-
// ViewStyle,
|
|
102
|
-
// ImageStyle,
|
|
103
|
-
// } from 'react-native';
|
|
104
|
-
// import DatePicker from 'react-native-date-picker';
|
|
105
|
-
// import { useTranslation } from 'react-i18next';
|
|
106
|
-
// import { Colors, Scale, Typography, Images } from '../../styles';
|
|
107
|
-
// interface DateTimePickerProps {
|
|
108
|
-
// value: Date | null;
|
|
109
|
-
// onChange: (date: Date) => void;
|
|
110
|
-
// label?: string;
|
|
111
|
-
// placeholder?: string;
|
|
112
|
-
// intlType?: string;
|
|
113
|
-
// mode?: 'date' | 'time' | 'datetime';
|
|
114
|
-
// disabled?: boolean;
|
|
115
|
-
// /** raw DatePicker props */
|
|
116
|
-
// minimumDate?: Date;
|
|
117
|
-
// maximumDate?: Date;
|
|
118
|
-
// modal?: boolean;
|
|
119
|
-
// confirmText?: string;
|
|
120
|
-
// cancelText?: string;
|
|
121
|
-
// /** style overrides */
|
|
122
|
-
// containerStyle?: StyleProp<ViewStyle>;
|
|
123
|
-
// pickerContainerStyle?: StyleProp<ViewStyle>;
|
|
124
|
-
// labelStyle?: StyleProp<TextStyle>;
|
|
125
|
-
// textStyle?: StyleProp<TextStyle>;
|
|
126
|
-
// leftImageStyle?: StyleProp<ImageStyle>;
|
|
127
|
-
// rightImageStyle?: StyleProp<ImageStyle>;
|
|
128
|
-
// /** icons */
|
|
129
|
-
// leftIcon?: ImageSourcePropType;
|
|
130
|
-
// rightIcon?: ImageSourcePropType;
|
|
131
|
-
// leftIconShow?: boolean;
|
|
132
|
-
// onCancel?: () => void;
|
|
133
|
-
// }
|
|
134
|
-
// const DateTimePicker: React.FC<DateTimePickerProps> = ({
|
|
135
|
-
// value,
|
|
136
|
-
// onChange,
|
|
137
|
-
// label,
|
|
138
|
-
// placeholder,
|
|
139
|
-
// intlType,
|
|
140
|
-
// mode = 'date',
|
|
141
|
-
// disabled = false,
|
|
142
|
-
// minimumDate,
|
|
143
|
-
// maximumDate,
|
|
144
|
-
// modal = true,
|
|
145
|
-
// confirmText,
|
|
146
|
-
// cancelText,
|
|
147
|
-
// containerStyle,
|
|
148
|
-
// pickerContainerStyle,
|
|
149
|
-
// labelStyle,
|
|
150
|
-
// textStyle,
|
|
151
|
-
// leftImageStyle,
|
|
152
|
-
// rightImageStyle,
|
|
153
|
-
// leftIcon,
|
|
154
|
-
// rightIcon,
|
|
155
|
-
// leftIconShow,
|
|
156
|
-
// onCancel,
|
|
157
|
-
// }) => {
|
|
158
|
-
// const { t } = useTranslation(['common', 'validation', 'address', 'sell']);
|
|
159
|
-
// const [open, setOpen] = useState(false);
|
|
160
|
-
// /** default icons based on mode */
|
|
161
|
-
// const defaultLeftIcon =
|
|
162
|
-
// mode === 'time'
|
|
163
|
-
// ? Images.ic_time // ⏰ your clock asset
|
|
164
|
-
// : Images.ic_calendar; // 📅 your calendar asset
|
|
165
|
-
// const getTranslatedLabel = () => {
|
|
166
|
-
// if (intlType) {
|
|
167
|
-
// const translated = t(label, { ns: intlType });
|
|
168
|
-
// if (translated !== label) return translated;
|
|
169
|
-
// }
|
|
170
|
-
// return label;
|
|
171
|
-
// };
|
|
172
|
-
// return (
|
|
173
|
-
// <View style={[styles.container, containerStyle]}>
|
|
174
|
-
// {/* Top label */}
|
|
175
|
-
// {label ? (
|
|
176
|
-
// <Text style={[styles.label, labelStyle]}>{getTranslatedLabel()}</Text>
|
|
177
|
-
// ) : null}
|
|
178
|
-
// <TouchableOpacity
|
|
179
|
-
// style={[
|
|
180
|
-
// styles.button,
|
|
181
|
-
// pickerContainerStyle,
|
|
182
|
-
// disabled && { backgroundColor: Colors.disabledGrey, borderWidth: 0 },
|
|
183
|
-
// ]}
|
|
184
|
-
// disabled={disabled}
|
|
185
|
-
// onPress={() => setOpen(true)}
|
|
186
|
-
// >
|
|
187
|
-
// {/* Left icon */}
|
|
188
|
-
// {leftIconShow &&
|
|
189
|
-
// <Image
|
|
190
|
-
// source={leftIcon || defaultLeftIcon}
|
|
191
|
-
// style={[styles.icon, leftImageStyle]}
|
|
192
|
-
// />}
|
|
193
|
-
// {/* Text / Placeholder */}
|
|
194
|
-
// <Text
|
|
195
|
-
// style={[
|
|
196
|
-
// styles.text,
|
|
197
|
-
// textStyle,
|
|
198
|
-
// !value && { color: Colors.textGrey },
|
|
199
|
-
// ]}
|
|
200
|
-
// numberOfLines={1}
|
|
201
|
-
// >
|
|
202
|
-
// {value ? formatValue(value, mode) : placeholder || 'Select'}
|
|
203
|
-
// </Text>
|
|
204
|
-
// {/* Right icon (mandatory) */}
|
|
205
|
-
// {rightIcon &&
|
|
206
|
-
// <Image
|
|
207
|
-
// source={rightIcon}
|
|
208
|
-
// style={[styles.icon, rightImageStyle]}
|
|
209
|
-
// />}
|
|
210
|
-
// </TouchableOpacity>
|
|
211
|
-
// <DatePicker
|
|
212
|
-
// modal={modal}
|
|
213
|
-
// open={open}
|
|
214
|
-
// date={value || new Date()}
|
|
215
|
-
// mode={mode}
|
|
216
|
-
// minimumDate={minimumDate}
|
|
217
|
-
// maximumDate={maximumDate}
|
|
218
|
-
// confirmText={confirmText}
|
|
219
|
-
// cancelText={cancelText}
|
|
220
|
-
// onConfirm={(val) => {
|
|
221
|
-
// setOpen(false);
|
|
222
|
-
// onChange(val);
|
|
223
|
-
// }}
|
|
224
|
-
// onCancel={() => {
|
|
225
|
-
// setOpen(false);
|
|
226
|
-
// onCancel && onCancel();
|
|
227
|
-
// }}
|
|
228
|
-
// />
|
|
229
|
-
// </View>
|
|
230
|
-
// );
|
|
231
|
-
// };
|
|
232
|
-
// const formatValue = (date: Date, mode: 'date' | 'time' | 'datetime') => {
|
|
233
|
-
// try {
|
|
234
|
-
// switch (mode) {
|
|
235
|
-
// case 'time':
|
|
236
|
-
// return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
237
|
-
// case 'datetime':
|
|
238
|
-
// return date.toLocaleString();
|
|
239
|
-
// default:
|
|
240
|
-
// return date.toLocaleDateString();
|
|
241
|
-
// }
|
|
242
|
-
// } catch {
|
|
243
|
-
// return '';
|
|
244
|
-
// }
|
|
245
|
-
// };
|
|
246
|
-
// const styles = StyleSheet.create({
|
|
247
|
-
// container: {
|
|
248
|
-
// marginVertical: Scale.moderateScale(8),
|
|
249
|
-
// },
|
|
250
|
-
// label: {
|
|
251
|
-
// ...Typography.style.standardU(),
|
|
252
|
-
// color: Colors.textColor,
|
|
253
|
-
// marginBottom: Scale.moderateScale(8),
|
|
254
|
-
// },
|
|
255
|
-
// button: {
|
|
256
|
-
// borderWidth: 1,
|
|
257
|
-
// borderColor: Colors.primaryColor,
|
|
258
|
-
// borderRadius: Scale.moderateScale(6),
|
|
259
|
-
// paddingVertical: Scale.moderateScale(12),
|
|
260
|
-
// paddingHorizontal: Scale.moderateScale(10),
|
|
261
|
-
// flexDirection: 'row',
|
|
262
|
-
// alignItems: 'center',
|
|
263
|
-
// },
|
|
264
|
-
// text: {
|
|
265
|
-
// flex: 1,
|
|
266
|
-
// ...Typography.style.standardU(),
|
|
267
|
-
// color: Colors.textColor,
|
|
268
|
-
// textTransform: "none",
|
|
269
|
-
// },
|
|
270
|
-
// icon: {
|
|
271
|
-
// width: Scale.moderateScale(20),
|
|
272
|
-
// height: Scale.moderateScale(20),
|
|
273
|
-
// resizeMode: 'contain',
|
|
274
|
-
// },
|
|
275
|
-
// });
|
|
276
|
-
// export default DateTimePicker;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnhz/rn-ui-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"react": ">=19.0.0",
|
|
18
18
|
"react-i18next": "^15.7.2",
|
|
19
19
|
"react-native": ">=0.77.2",
|
|
20
|
-
"react-native-date-picker": "^5.0.13",
|
|
21
20
|
"react-native-element-dropdown": "^2.12.4",
|
|
22
21
|
"react-native-elements": "^3.4.3",
|
|
23
22
|
"react-native-fast-image": "^8.6.3",
|
|
@@ -38,5 +37,9 @@
|
|
|
38
37
|
"cpx": "^1.5.0",
|
|
39
38
|
"react-native-keyboard-aware-scroll-view": "^0.9.5",
|
|
40
39
|
"typescript": "^5.9.2"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@react-native-community/datetimepicker": "^8.5.0",
|
|
43
|
+
"react-native-modal-datetime-picker": "^18.0.0"
|
|
41
44
|
}
|
|
42
45
|
}
|