@izonnet-web-solution/react-native-date-time-picker-kit 0.0.0-stage → 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.
Files changed (216) hide show
  1. package/DateTimePickerKit.podspec +22 -0
  2. package/LICENSE +20 -0
  3. package/README.md +532 -2
  4. package/android/build.gradle +36 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/datetimepickerkit/DatePickerHelper.kt +185 -0
  7. package/android/src/main/java/com/datetimepickerkit/DateTimePickerHelper.kt +214 -0
  8. package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitModule.kt +258 -0
  9. package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitPackage.kt +30 -0
  10. package/android/src/main/java/com/datetimepickerkit/TimePickerHelper.kt +208 -0
  11. package/ios/DateTimePickerKit.h +11 -0
  12. package/ios/DateTimePickerKit.mm +84 -0
  13. package/ios/DateTimePickerModule.swift +474 -0
  14. package/lib/module/NativeDateTimePickerKit.js +5 -0
  15. package/lib/module/NativeDateTimePickerKit.js.map +1 -0
  16. package/lib/module/components/CalendarPicker.js +414 -0
  17. package/lib/module/components/CalendarPicker.js.map +1 -0
  18. package/lib/module/components/ClockPicker.js +273 -0
  19. package/lib/module/components/ClockPicker.js.map +1 -0
  20. package/lib/module/components/DatePicker.js +174 -0
  21. package/lib/module/components/DatePicker.js.map +1 -0
  22. package/lib/module/components/DateRangePicker.js +154 -0
  23. package/lib/module/components/DateRangePicker.js.map +1 -0
  24. package/lib/module/components/DateTimePicker.js +598 -0
  25. package/lib/module/components/DateTimePicker.js.map +1 -0
  26. package/lib/module/components/MonthPicker.js +145 -0
  27. package/lib/module/components/MonthPicker.js.map +1 -0
  28. package/lib/module/components/TimePicker.js +140 -0
  29. package/lib/module/components/TimePicker.js.map +1 -0
  30. package/lib/module/components/TimeSlotPicker.js +118 -0
  31. package/lib/module/components/TimeSlotPicker.js.map +1 -0
  32. package/lib/module/components/WheelPicker.js +138 -0
  33. package/lib/module/components/WheelPicker.js.map +1 -0
  34. package/lib/module/components/YearPicker.js +151 -0
  35. package/lib/module/components/YearPicker.js.map +1 -0
  36. package/lib/module/components/common/ModalWrapper.js +130 -0
  37. package/lib/module/components/common/ModalWrapper.js.map +1 -0
  38. package/lib/module/components/common/PickerHeader.js +82 -0
  39. package/lib/module/components/common/PickerHeader.js.map +1 -0
  40. package/lib/module/components/common/PresetsBar.js +66 -0
  41. package/lib/module/components/common/PresetsBar.js.map +1 -0
  42. package/lib/module/errors/DateTimePickerError.js +12 -0
  43. package/lib/module/errors/DateTimePickerError.js.map +1 -0
  44. package/lib/module/hooks/useDateTimePicker.js +73 -0
  45. package/lib/module/hooks/useDateTimePicker.js.map +1 -0
  46. package/lib/module/index.js +40 -0
  47. package/lib/module/index.js.map +1 -0
  48. package/lib/module/localization/index.js +6 -0
  49. package/lib/module/localization/index.js.map +1 -0
  50. package/lib/module/localization/locales.js +186 -0
  51. package/lib/module/localization/locales.js.map +1 -0
  52. package/lib/module/localization/types.js +2 -0
  53. package/lib/module/localization/types.js.map +1 -0
  54. package/lib/module/localization/useLocale.js +126 -0
  55. package/lib/module/localization/useLocale.js.map +1 -0
  56. package/lib/module/native/NativeDateTimePicker.js +110 -0
  57. package/lib/module/native/NativeDateTimePicker.js.map +1 -0
  58. package/lib/module/package.json +1 -0
  59. package/lib/module/presets/datePresets.js +75 -0
  60. package/lib/module/presets/datePresets.js.map +1 -0
  61. package/lib/module/presets/index.js +4 -0
  62. package/lib/module/presets/index.js.map +1 -0
  63. package/lib/module/slots/index.js +4 -0
  64. package/lib/module/slots/index.js.map +1 -0
  65. package/lib/module/slots/timeSlots.js +59 -0
  66. package/lib/module/slots/timeSlots.js.map +1 -0
  67. package/lib/module/theme/defaultTheme.js +91 -0
  68. package/lib/module/theme/defaultTheme.js.map +1 -0
  69. package/lib/module/theme/index.js +6 -0
  70. package/lib/module/theme/index.js.map +1 -0
  71. package/lib/module/theme/types.js +2 -0
  72. package/lib/module/theme/types.js.map +1 -0
  73. package/lib/module/theme/useTheme.js +59 -0
  74. package/lib/module/theme/useTheme.js.map +1 -0
  75. package/lib/module/types/events.js +4 -0
  76. package/lib/module/types/events.js.map +1 -0
  77. package/lib/module/types/index.js +7 -0
  78. package/lib/module/types/index.js.map +1 -0
  79. package/lib/module/types/native.js +2 -0
  80. package/lib/module/types/native.js.map +1 -0
  81. package/lib/module/types/presentation.js +2 -0
  82. package/lib/module/types/presentation.js.map +1 -0
  83. package/lib/module/types/props.js +4 -0
  84. package/lib/module/types/props.js.map +1 -0
  85. package/lib/module/utils/constants.js +14 -0
  86. package/lib/module/utils/constants.js.map +1 -0
  87. package/lib/module/utils/dateConversion.js +115 -0
  88. package/lib/module/utils/dateConversion.js.map +1 -0
  89. package/lib/module/utils/dateFormatting.js +102 -0
  90. package/lib/module/utils/dateFormatting.js.map +1 -0
  91. package/lib/module/utils/dateValidation.js +161 -0
  92. package/lib/module/utils/dateValidation.js.map +1 -0
  93. package/lib/module/utils/index.js +7 -0
  94. package/lib/module/utils/index.js.map +1 -0
  95. package/lib/typescript/package.json +1 -0
  96. package/lib/typescript/src/NativeDateTimePickerKit.d.ts +17 -0
  97. package/lib/typescript/src/NativeDateTimePickerKit.d.ts.map +1 -0
  98. package/lib/typescript/src/components/CalendarPicker.d.ts +35 -0
  99. package/lib/typescript/src/components/CalendarPicker.d.ts.map +1 -0
  100. package/lib/typescript/src/components/ClockPicker.d.ts +22 -0
  101. package/lib/typescript/src/components/ClockPicker.d.ts.map +1 -0
  102. package/lib/typescript/src/components/DatePicker.d.ts +32 -0
  103. package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
  104. package/lib/typescript/src/components/DateRangePicker.d.ts +41 -0
  105. package/lib/typescript/src/components/DateRangePicker.d.ts.map +1 -0
  106. package/lib/typescript/src/components/DateTimePicker.d.ts +7 -0
  107. package/lib/typescript/src/components/DateTimePicker.d.ts.map +1 -0
  108. package/lib/typescript/src/components/MonthPicker.d.ts +21 -0
  109. package/lib/typescript/src/components/MonthPicker.d.ts.map +1 -0
  110. package/lib/typescript/src/components/TimePicker.d.ts +25 -0
  111. package/lib/typescript/src/components/TimePicker.d.ts.map +1 -0
  112. package/lib/typescript/src/components/TimeSlotPicker.d.ts +18 -0
  113. package/lib/typescript/src/components/TimeSlotPicker.d.ts.map +1 -0
  114. package/lib/typescript/src/components/WheelPicker.d.ts +17 -0
  115. package/lib/typescript/src/components/WheelPicker.d.ts.map +1 -0
  116. package/lib/typescript/src/components/YearPicker.d.ts +14 -0
  117. package/lib/typescript/src/components/YearPicker.d.ts.map +1 -0
  118. package/lib/typescript/src/components/common/ModalWrapper.d.ts +10 -0
  119. package/lib/typescript/src/components/common/ModalWrapper.d.ts.map +1 -0
  120. package/lib/typescript/src/components/common/PickerHeader.d.ts +13 -0
  121. package/lib/typescript/src/components/common/PickerHeader.d.ts.map +1 -0
  122. package/lib/typescript/src/components/common/PresetsBar.d.ts +12 -0
  123. package/lib/typescript/src/components/common/PresetsBar.d.ts.map +1 -0
  124. package/lib/typescript/src/errors/DateTimePickerError.d.ts +7 -0
  125. package/lib/typescript/src/errors/DateTimePickerError.d.ts.map +1 -0
  126. package/lib/typescript/src/hooks/useDateTimePicker.d.ts +17 -0
  127. package/lib/typescript/src/hooks/useDateTimePicker.d.ts.map +1 -0
  128. package/lib/typescript/src/index.d.ts +23 -0
  129. package/lib/typescript/src/index.d.ts.map +1 -0
  130. package/lib/typescript/src/localization/index.d.ts +4 -0
  131. package/lib/typescript/src/localization/index.d.ts.map +1 -0
  132. package/lib/typescript/src/localization/locales.d.ts +12 -0
  133. package/lib/typescript/src/localization/locales.d.ts.map +1 -0
  134. package/lib/typescript/src/localization/types.d.ts +23 -0
  135. package/lib/typescript/src/localization/types.d.ts.map +1 -0
  136. package/lib/typescript/src/localization/useLocale.d.ts +31 -0
  137. package/lib/typescript/src/localization/useLocale.d.ts.map +1 -0
  138. package/lib/typescript/src/native/NativeDateTimePicker.d.ts +14 -0
  139. package/lib/typescript/src/native/NativeDateTimePicker.d.ts.map +1 -0
  140. package/lib/typescript/src/presets/datePresets.d.ts +8 -0
  141. package/lib/typescript/src/presets/datePresets.d.ts.map +1 -0
  142. package/lib/typescript/src/presets/index.d.ts +2 -0
  143. package/lib/typescript/src/presets/index.d.ts.map +1 -0
  144. package/lib/typescript/src/slots/index.d.ts +2 -0
  145. package/lib/typescript/src/slots/index.d.ts.map +1 -0
  146. package/lib/typescript/src/slots/timeSlots.d.ts +18 -0
  147. package/lib/typescript/src/slots/timeSlots.d.ts.map +1 -0
  148. package/lib/typescript/src/theme/defaultTheme.d.ts +9 -0
  149. package/lib/typescript/src/theme/defaultTheme.d.ts.map +1 -0
  150. package/lib/typescript/src/theme/index.d.ts +4 -0
  151. package/lib/typescript/src/theme/index.d.ts.map +1 -0
  152. package/lib/typescript/src/theme/types.d.ts +65 -0
  153. package/lib/typescript/src/theme/types.d.ts.map +1 -0
  154. package/lib/typescript/src/theme/useTheme.d.ts +4 -0
  155. package/lib/typescript/src/theme/useTheme.d.ts.map +1 -0
  156. package/lib/typescript/src/types/events.d.ts +8 -0
  157. package/lib/typescript/src/types/events.d.ts.map +1 -0
  158. package/lib/typescript/src/types/index.d.ts +5 -0
  159. package/lib/typescript/src/types/index.d.ts.map +1 -0
  160. package/lib/typescript/src/types/native.d.ts +26 -0
  161. package/lib/typescript/src/types/native.d.ts.map +1 -0
  162. package/lib/typescript/src/types/presentation.d.ts +19 -0
  163. package/lib/typescript/src/types/presentation.d.ts.map +1 -0
  164. package/lib/typescript/src/types/props.d.ts +68 -0
  165. package/lib/typescript/src/types/props.d.ts.map +1 -0
  166. package/lib/typescript/src/utils/constants.d.ts +12 -0
  167. package/lib/typescript/src/utils/constants.d.ts.map +1 -0
  168. package/lib/typescript/src/utils/dateConversion.d.ts +27 -0
  169. package/lib/typescript/src/utils/dateConversion.d.ts.map +1 -0
  170. package/lib/typescript/src/utils/dateFormatting.d.ts +8 -0
  171. package/lib/typescript/src/utils/dateFormatting.d.ts.map +1 -0
  172. package/lib/typescript/src/utils/dateValidation.d.ts +46 -0
  173. package/lib/typescript/src/utils/dateValidation.d.ts.map +1 -0
  174. package/lib/typescript/src/utils/index.d.ts +5 -0
  175. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  176. package/package.json +183 -4
  177. package/src/NativeDateTimePickerKit.ts +19 -0
  178. package/src/components/CalendarPicker.tsx +593 -0
  179. package/src/components/ClockPicker.tsx +403 -0
  180. package/src/components/DatePicker.tsx +246 -0
  181. package/src/components/DateRangePicker.tsx +226 -0
  182. package/src/components/DateTimePicker.tsx +862 -0
  183. package/src/components/MonthPicker.tsx +216 -0
  184. package/src/components/TimePicker.tsx +190 -0
  185. package/src/components/TimeSlotPicker.tsx +163 -0
  186. package/src/components/WheelPicker.tsx +199 -0
  187. package/src/components/YearPicker.tsx +228 -0
  188. package/src/components/common/ModalWrapper.tsx +184 -0
  189. package/src/components/common/PickerHeader.tsx +121 -0
  190. package/src/components/common/PresetsBar.tsx +104 -0
  191. package/src/errors/DateTimePickerError.ts +29 -0
  192. package/src/hooks/useDateTimePicker.ts +100 -0
  193. package/src/index.tsx +92 -0
  194. package/src/localization/index.ts +3 -0
  195. package/src/localization/locales.ts +499 -0
  196. package/src/localization/types.ts +21 -0
  197. package/src/localization/useLocale.ts +137 -0
  198. package/src/native/NativeDateTimePicker.ts +154 -0
  199. package/src/presets/datePresets.ts +97 -0
  200. package/src/presets/index.ts +1 -0
  201. package/src/slots/index.ts +1 -0
  202. package/src/slots/timeSlots.ts +89 -0
  203. package/src/theme/defaultTheme.ts +102 -0
  204. package/src/theme/index.ts +3 -0
  205. package/src/theme/types.ts +70 -0
  206. package/src/theme/useTheme.ts +75 -0
  207. package/src/types/events.ts +8 -0
  208. package/src/types/index.ts +4 -0
  209. package/src/types/native.ts +28 -0
  210. package/src/types/presentation.ts +21 -0
  211. package/src/types/props.ts +104 -0
  212. package/src/utils/constants.ts +15 -0
  213. package/src/utils/dateConversion.ts +127 -0
  214. package/src/utils/dateFormatting.ts +166 -0
  215. package/src/utils/dateValidation.ts +178 -0
  216. package/src/utils/index.ts +4 -0
@@ -0,0 +1,403 @@
1
+ import React, { useCallback, useMemo, useState } from 'react';
2
+ import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
3
+ import { useLocale } from '../localization';
4
+ import type { PartialLocaleData } from '../localization/types';
5
+ import { useTheme } from '../theme';
6
+ import type { ThemeConfig, ThemeMode } from '../theme/types';
7
+ import type { MinuteInterval } from '../types';
8
+
9
+ export interface ClockPickerProps {
10
+ value?: Date | { hour: number; minute: number };
11
+ onChange?: (result: { hour: number; minute: number; date: Date }) => void;
12
+ is24Hour?: boolean;
13
+ minuteInterval?: MinuteInterval;
14
+ locale?: string | PartialLocaleData;
15
+ theme?: ThemeMode | ThemeConfig;
16
+ testID?: string;
17
+ }
18
+
19
+ export const ClockPicker: React.FC<ClockPickerProps> = ({
20
+ value,
21
+ onChange,
22
+ is24Hour = false,
23
+ minuteInterval = 1,
24
+ locale: propLocale,
25
+ theme: propTheme,
26
+ testID,
27
+ }) => {
28
+ const theme = useTheme(propTheme);
29
+ const locale = useLocale(propLocale);
30
+
31
+ const initialHour =
32
+ value instanceof Date
33
+ ? value.getHours()
34
+ : value?.hour !== undefined
35
+ ? value.hour
36
+ : new Date().getHours();
37
+ const initialMinute =
38
+ value instanceof Date
39
+ ? value.getMinutes()
40
+ : value?.minute !== undefined
41
+ ? value.minute
42
+ : new Date().getMinutes();
43
+
44
+ const [hour, setHour] = useState<number>(initialHour);
45
+ const [minute, setMinute] = useState<number>(initialMinute);
46
+ const [activeSegment, setActiveSegment] = useState<'hour' | 'minute'>('hour');
47
+
48
+ const isPM = hour >= 12;
49
+ const display12Hour = hour % 12 === 0 ? 12 : hour % 12;
50
+
51
+ const emitChange = useCallback(
52
+ (newHour: number, newMinute: number) => {
53
+ const now = new Date();
54
+ const d = new Date(
55
+ now.getFullYear(),
56
+ now.getMonth(),
57
+ now.getDate(),
58
+ newHour,
59
+ newMinute,
60
+ 0,
61
+ 0
62
+ );
63
+ onChange?.({ hour: newHour, minute: newMinute, date: d });
64
+ },
65
+ [onChange]
66
+ );
67
+
68
+ const toggleAmPm = useCallback(
69
+ (pm: boolean) => {
70
+ let nextHour = hour;
71
+ if (pm && hour < 12) {
72
+ nextHour = hour + 12;
73
+ } else if (!pm && hour >= 12) {
74
+ nextHour = hour - 12;
75
+ }
76
+ setHour(nextHour);
77
+ emitChange(nextHour, minute);
78
+ },
79
+ [hour, minute, emitChange]
80
+ );
81
+
82
+ const handleSelectHour = useCallback(
83
+ (selectedH: number) => {
84
+ let finalH = selectedH;
85
+ if (!is24Hour) {
86
+ if (isPM && selectedH < 12) {
87
+ finalH = selectedH + 12;
88
+ } else if (!isPM && selectedH === 12) {
89
+ finalH = 0;
90
+ }
91
+ }
92
+ setHour(finalH);
93
+ emitChange(finalH, minute);
94
+ setActiveSegment('minute');
95
+ },
96
+ [is24Hour, isPM, minute, emitChange]
97
+ );
98
+
99
+ const handleSelectMinute = useCallback(
100
+ (selectedM: number) => {
101
+ setMinute(selectedM);
102
+ emitChange(hour, selectedM);
103
+ },
104
+ [hour, emitChange]
105
+ );
106
+
107
+ // Hours array to display in selection grid
108
+ const hoursList = useMemo(() => {
109
+ if (is24Hour) {
110
+ return Array.from({ length: 24 }, (_, i) => i);
111
+ }
112
+ return [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
113
+ }, [is24Hour]);
114
+
115
+ // Minutes array to display in selection grid
116
+ const minutesList = useMemo(() => {
117
+ const list: number[] = [];
118
+ for (let m = 0; m < 60; m += minuteInterval) {
119
+ list.push(m);
120
+ }
121
+ return list;
122
+ }, [minuteInterval]);
123
+
124
+ const pad = (n: number) => (n < 10 ? `0${n}` : `${n}`);
125
+
126
+ return (
127
+ <View
128
+ testID={testID}
129
+ style={[styles.container, { backgroundColor: theme.colors.background }]}
130
+ >
131
+ {/* Time Display Header */}
132
+ <View style={styles.displayRow}>
133
+ <View style={styles.timeBox}>
134
+ {/* Hour Segment */}
135
+ <TouchableOpacity
136
+ onPress={() => setActiveSegment('hour')}
137
+ style={[
138
+ styles.segmentBtn,
139
+ activeSegment === 'hour' && {
140
+ backgroundColor: theme.colors.card,
141
+ borderColor: theme.colors.primary,
142
+ },
143
+ ]}
144
+ >
145
+ <Text
146
+ style={[
147
+ styles.segmentText,
148
+ {
149
+ color:
150
+ activeSegment === 'hour'
151
+ ? theme.colors.primary
152
+ : theme.colors.text,
153
+ fontSize: 32,
154
+ fontWeight: theme.typography.fontWeightBold,
155
+ },
156
+ ]}
157
+ >
158
+ {is24Hour ? pad(hour) : pad(display12Hour)}
159
+ </Text>
160
+ </TouchableOpacity>
161
+
162
+ <Text
163
+ style={[
164
+ styles.colonText,
165
+ { color: theme.colors.textMuted, fontSize: 32 },
166
+ ]}
167
+ >
168
+ :
169
+ </Text>
170
+
171
+ {/* Minute Segment */}
172
+ <TouchableOpacity
173
+ onPress={() => setActiveSegment('minute')}
174
+ style={[
175
+ styles.segmentBtn,
176
+ activeSegment === 'minute' && {
177
+ backgroundColor: theme.colors.card,
178
+ borderColor: theme.colors.primary,
179
+ },
180
+ ]}
181
+ >
182
+ <Text
183
+ style={[
184
+ styles.segmentText,
185
+ {
186
+ color:
187
+ activeSegment === 'minute'
188
+ ? theme.colors.primary
189
+ : theme.colors.text,
190
+ fontSize: 32,
191
+ fontWeight: theme.typography.fontWeightBold,
192
+ },
193
+ ]}
194
+ >
195
+ {pad(minute)}
196
+ </Text>
197
+ </TouchableOpacity>
198
+ </View>
199
+
200
+ {/* AM / PM Toggle (for 12-hour mode) */}
201
+ {!is24Hour && (
202
+ <View
203
+ style={[
204
+ styles.ampmContainer,
205
+ {
206
+ borderColor: theme.colors.border,
207
+ backgroundColor: theme.colors.card,
208
+ },
209
+ ]}
210
+ >
211
+ <TouchableOpacity
212
+ onPress={() => toggleAmPm(false)}
213
+ style={[
214
+ styles.ampmBtn,
215
+ !isPM && {
216
+ backgroundColor: theme.colors.primary,
217
+ },
218
+ ]}
219
+ >
220
+ <Text
221
+ style={[
222
+ styles.ampmText,
223
+ {
224
+ color: !isPM
225
+ ? theme.colors.primaryText
226
+ : theme.colors.textSecondary,
227
+ fontWeight: !isPM ? 'bold' : 'normal',
228
+ },
229
+ ]}
230
+ >
231
+ {locale.am}
232
+ </Text>
233
+ </TouchableOpacity>
234
+
235
+ <TouchableOpacity
236
+ onPress={() => toggleAmPm(true)}
237
+ style={[
238
+ styles.ampmBtn,
239
+ isPM && {
240
+ backgroundColor: theme.colors.primary,
241
+ },
242
+ ]}
243
+ >
244
+ <Text
245
+ style={[
246
+ styles.ampmText,
247
+ {
248
+ color: isPM
249
+ ? theme.colors.primaryText
250
+ : theme.colors.textSecondary,
251
+ fontWeight: isPM ? 'bold' : 'normal',
252
+ },
253
+ ]}
254
+ >
255
+ {locale.pm}
256
+ </Text>
257
+ </TouchableOpacity>
258
+ </View>
259
+ )}
260
+ </View>
261
+
262
+ {/* Grid of Choices */}
263
+ <View style={styles.gridContainer}>
264
+ {activeSegment === 'hour' ? (
265
+ <View style={styles.choicesGrid}>
266
+ {hoursList.map((h) => {
267
+ const isSelected = is24Hour ? hour === h : display12Hour === h;
268
+ return (
269
+ <TouchableOpacity
270
+ key={`h-${h}`}
271
+ accessibilityRole="button"
272
+ accessibilityLabel={`${pad(h)} hours`}
273
+ accessibilityState={{ selected: isSelected }}
274
+ onPress={() => handleSelectHour(h)}
275
+ style={[
276
+ styles.choiceCell,
277
+ isSelected && {
278
+ backgroundColor: theme.colors.selected,
279
+ borderRadius: theme.borderRadius.full,
280
+ },
281
+ ]}
282
+ >
283
+ <Text
284
+ style={[
285
+ styles.choiceText,
286
+ {
287
+ color: isSelected
288
+ ? theme.colors.selectedText
289
+ : theme.colors.text,
290
+ fontWeight: isSelected ? 'bold' : 'normal',
291
+ },
292
+ ]}
293
+ >
294
+ {pad(h)}
295
+ </Text>
296
+ </TouchableOpacity>
297
+ );
298
+ })}
299
+ </View>
300
+ ) : (
301
+ <View style={styles.choicesGrid}>
302
+ {minutesList.map((m) => {
303
+ const isSelected = minute === m;
304
+ return (
305
+ <TouchableOpacity
306
+ key={`m-${m}`}
307
+ accessibilityRole="button"
308
+ accessibilityLabel={`${pad(m)} minutes`}
309
+ accessibilityState={{ selected: isSelected }}
310
+ onPress={() => handleSelectMinute(m)}
311
+ style={[
312
+ styles.choiceCell,
313
+ isSelected && {
314
+ backgroundColor: theme.colors.selected,
315
+ borderRadius: theme.borderRadius.full,
316
+ },
317
+ ]}
318
+ >
319
+ <Text
320
+ style={[
321
+ styles.choiceText,
322
+ {
323
+ color: isSelected
324
+ ? theme.colors.selectedText
325
+ : theme.colors.text,
326
+ fontWeight: isSelected ? 'bold' : 'normal',
327
+ },
328
+ ]}
329
+ >
330
+ {pad(m)}
331
+ </Text>
332
+ </TouchableOpacity>
333
+ );
334
+ })}
335
+ </View>
336
+ )}
337
+ </View>
338
+ </View>
339
+ );
340
+ };
341
+
342
+ const styles = StyleSheet.create({
343
+ container: {
344
+ padding: 16,
345
+ alignItems: 'center',
346
+ },
347
+ displayRow: {
348
+ flexDirection: 'row',
349
+ alignItems: 'center',
350
+ justifyContent: 'center',
351
+ marginBottom: 20,
352
+ gap: 16,
353
+ },
354
+ timeBox: {
355
+ flexDirection: 'row',
356
+ alignItems: 'center',
357
+ },
358
+ segmentBtn: {
359
+ paddingHorizontal: 12,
360
+ paddingVertical: 4,
361
+ borderRadius: 8,
362
+ borderWidth: 1,
363
+ borderColor: 'transparent',
364
+ },
365
+ segmentText: {},
366
+ colonText: {
367
+ marginHorizontal: 4,
368
+ },
369
+ ampmContainer: {
370
+ flexDirection: 'column',
371
+ borderRadius: 8,
372
+ borderWidth: 1,
373
+ overflow: 'hidden',
374
+ },
375
+ ampmBtn: {
376
+ paddingHorizontal: 10,
377
+ paddingVertical: 6,
378
+ alignItems: 'center',
379
+ },
380
+ ampmText: {
381
+ fontSize: 12,
382
+ },
383
+ gridContainer: {
384
+ width: '100%',
385
+ minHeight: 180,
386
+ justifyContent: 'center',
387
+ },
388
+ choicesGrid: {
389
+ flexDirection: 'row',
390
+ flexWrap: 'wrap',
391
+ justifyContent: 'center',
392
+ gap: 8,
393
+ },
394
+ choiceCell: {
395
+ width: 44,
396
+ height: 44,
397
+ justifyContent: 'center',
398
+ alignItems: 'center',
399
+ },
400
+ choiceText: {
401
+ fontSize: 16,
402
+ },
403
+ });
@@ -0,0 +1,246 @@
1
+ import { forwardRef, useCallback, useImperativeHandle, useState } from 'react';
2
+ import { StyleSheet, View } from 'react-native';
3
+ import { useLocale } from '../localization';
4
+ import type { PartialLocaleData } from '../localization/types';
5
+ import { NativeDateTimePicker } from '../native/NativeDateTimePicker';
6
+ import { type DatePreset, getStandardSinglePresets } from '../presets';
7
+ import { useTheme } from '../theme';
8
+ import type { ThemeConfig, ThemeMode } from '../theme/types';
9
+ import type { BaseModalProps, PresentationMode } from '../types/presentation';
10
+ import {
11
+ dateToTimestamp,
12
+ parseDate,
13
+ timestampToDate,
14
+ } from '../utils/dateConversion';
15
+ import { CalendarPicker, type MarkedDatesMap } from './CalendarPicker';
16
+ import { ModalWrapper } from './common/ModalWrapper';
17
+ import { PickerHeader } from './common/PickerHeader';
18
+ import { PresetsBar } from './common/PresetsBar';
19
+
20
+ export interface DatePickerRef {
21
+ open: () => Promise<Date | null> | void;
22
+ close: () => Promise<boolean> | void;
23
+ getValue: () => Date | null;
24
+ setValue: (date: Date | string | number) => void;
25
+ reset: () => void;
26
+ }
27
+
28
+ export interface DatePickerProps extends BaseModalProps {
29
+ presentation?: PresentationMode;
30
+ value?: Date | string | number | null;
31
+ defaultValue?: Date | string | number | null;
32
+ onChange?: (date: Date) => void;
33
+ onConfirmDate?: (date: Date) => void;
34
+ minimumDate?: Date | string | number;
35
+ maximumDate?: Date | string | number;
36
+ disabledDates?: (Date | string)[];
37
+ disabledWeekdays?: number[];
38
+ markedDates?: MarkedDatesMap;
39
+ firstDayOfWeek?: number;
40
+ showPresets?: boolean;
41
+ customPresets?: DatePreset[];
42
+ locale?: string | PartialLocaleData;
43
+ theme?: ThemeMode | ThemeConfig;
44
+ testID?: string;
45
+ }
46
+
47
+ export const DatePicker = forwardRef<DatePickerRef, DatePickerProps>(
48
+ (
49
+ {
50
+ presentation = 'bottom-sheet',
51
+ visible: propVisible,
52
+ onClose,
53
+ title,
54
+ confirmText,
55
+ cancelText,
56
+ onConfirmDate,
57
+ onCancel,
58
+ value: propValue,
59
+ defaultValue,
60
+ onChange,
61
+ minimumDate,
62
+ maximumDate,
63
+ disabledDates,
64
+ disabledWeekdays,
65
+ markedDates,
66
+ firstDayOfWeek,
67
+ showPresets = false,
68
+ customPresets,
69
+ locale: propLocale,
70
+ theme: propTheme,
71
+ backdropOpacity,
72
+ animationType,
73
+ showHandle,
74
+ closeOnBackdropPress,
75
+ testID,
76
+ },
77
+ ref
78
+ ) => {
79
+ const theme = useTheme(propTheme);
80
+ const locale = useLocale(propLocale);
81
+
82
+ const initialDate =
83
+ parseDate(propValue) || parseDate(defaultValue) || new Date();
84
+ const [selectedDate, setSelectedDate] = useState<Date>(initialDate);
85
+ const [isVisible, setIsVisible] = useState(false);
86
+ const [activePresetId, setActivePresetId] = useState<string | undefined>();
87
+
88
+ const modalVisible = propVisible !== undefined ? propVisible : isVisible;
89
+
90
+ // Imperative ref implementation
91
+ useImperativeHandle(ref, () => ({
92
+ open: async () => {
93
+ if (presentation === 'native') {
94
+ const res = await NativeDateTimePicker.openDatePicker({
95
+ value: selectedDate.getTime(),
96
+ minimumDate: minimumDate
97
+ ? (dateToTimestamp(minimumDate) ?? undefined)
98
+ : undefined,
99
+ maximumDate: maximumDate
100
+ ? (dateToTimestamp(maximumDate) ?? undefined)
101
+ : undefined,
102
+ title: title || locale.selectDateTitle,
103
+ confirmText: confirmText || locale.confirmText,
104
+ cancelText: cancelText || locale.cancelText,
105
+ });
106
+ if (res.action === 'confirmed') {
107
+ const confirmedDate = timestampToDate(res.timestamp);
108
+ setSelectedDate(confirmedDate);
109
+ onChange?.(confirmedDate);
110
+ onConfirmDate?.(confirmedDate);
111
+ return confirmedDate;
112
+ }
113
+ return null;
114
+ } else {
115
+ setIsVisible(true);
116
+ return null;
117
+ }
118
+ },
119
+ close: async () => {
120
+ if (presentation === 'native') {
121
+ return await NativeDateTimePicker.closePicker();
122
+ } else {
123
+ setIsVisible(false);
124
+ onClose?.();
125
+ return true;
126
+ }
127
+ },
128
+ getValue: () => selectedDate,
129
+ setValue: (newDate: Date | string | number) => {
130
+ const parsed = parseDate(newDate);
131
+ if (parsed) {
132
+ setSelectedDate(parsed);
133
+ }
134
+ },
135
+ reset: () => {
136
+ setSelectedDate(initialDate);
137
+ setActivePresetId(undefined);
138
+ },
139
+ }));
140
+
141
+ const presets = showPresets
142
+ ? customPresets || getStandardSinglePresets()
143
+ : [];
144
+
145
+ const handleSelectPreset = useCallback(
146
+ (preset: DatePreset) => {
147
+ setActivePresetId(preset.id);
148
+ const val = preset.getValue();
149
+ if (val instanceof Date) {
150
+ setSelectedDate(val);
151
+ onChange?.(val);
152
+ }
153
+ },
154
+ [onChange]
155
+ );
156
+
157
+ const handleDayChange = useCallback(
158
+ (date: Date) => {
159
+ setActivePresetId(undefined);
160
+ setSelectedDate(date);
161
+ onChange?.(date);
162
+ },
163
+ [onChange]
164
+ );
165
+
166
+ const handleConfirm = useCallback(() => {
167
+ onConfirmDate?.(selectedDate);
168
+ setIsVisible(false);
169
+ onClose?.();
170
+ }, [selectedDate, onConfirmDate, onClose]);
171
+
172
+ const handleCancel = useCallback(() => {
173
+ onCancel?.();
174
+ setIsVisible(false);
175
+ onClose?.();
176
+ }, [onCancel, onClose]);
177
+
178
+ // If native presentation, render nothing in React DOM (Native dialog handles UI)
179
+ if (presentation === 'native') {
180
+ return null;
181
+ }
182
+
183
+ const content = (
184
+ <View style={styles.innerContent}>
185
+ {presentation !== 'inline' && (
186
+ <PickerHeader
187
+ title={title || locale.selectDateTitle}
188
+ cancelText={cancelText || locale.cancelText}
189
+ confirmText={confirmText || locale.confirmText}
190
+ onCancel={handleCancel}
191
+ onConfirm={handleConfirm}
192
+ theme={theme}
193
+ isRTL={locale.isRTL}
194
+ />
195
+ )}
196
+
197
+ {showPresets && presets.length > 0 && (
198
+ <PresetsBar
199
+ presets={presets}
200
+ activePresetId={activePresetId}
201
+ onSelectPreset={handleSelectPreset}
202
+ theme={theme}
203
+ isRTL={locale.isRTL}
204
+ />
205
+ )}
206
+
207
+ <CalendarPicker
208
+ value={selectedDate}
209
+ onChange={handleDayChange}
210
+ minimumDate={minimumDate}
211
+ maximumDate={maximumDate}
212
+ disabledDates={disabledDates}
213
+ disabledWeekdays={disabledWeekdays}
214
+ markedDates={markedDates}
215
+ firstDayOfWeek={firstDayOfWeek}
216
+ locale={locale}
217
+ theme={theme}
218
+ />
219
+ </View>
220
+ );
221
+
222
+ return (
223
+ <ModalWrapper
224
+ testID={testID}
225
+ presentation={presentation}
226
+ visible={modalVisible}
227
+ onClose={handleCancel}
228
+ theme={theme}
229
+ backdropOpacity={backdropOpacity}
230
+ animationType={animationType}
231
+ showHandle={showHandle}
232
+ closeOnBackdropPress={closeOnBackdropPress}
233
+ >
234
+ {content}
235
+ </ModalWrapper>
236
+ );
237
+ }
238
+ );
239
+
240
+ DatePicker.displayName = 'DatePicker';
241
+
242
+ const styles = StyleSheet.create({
243
+ innerContent: {
244
+ width: '100%',
245
+ },
246
+ });