@izonnet-web-solution/react-native-date-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 (271) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +5 -0
  3. package/README.md +942 -2
  4. package/assets/screenshots/calendar-picker-blue.jpg +0 -0
  5. package/assets/screenshots/calendar-picker.jpg +0 -0
  6. package/assets/screenshots/datetime-picker-date.jpg +0 -0
  7. package/assets/screenshots/datetime-picker-time-blue.jpg +0 -0
  8. package/assets/screenshots/input-modal-picker.jpg +0 -0
  9. package/assets/screenshots/manual-entry-single.jpg +0 -0
  10. package/assets/screenshots/manual-entry-split.jpg +0 -0
  11. package/assets/screenshots/month-year-selector-modal.jpg +0 -0
  12. package/assets/screenshots/range-picker.jpg +0 -0
  13. package/assets/screenshots/time-12h-wheel.jpg +0 -0
  14. package/assets/screenshots/time-24h-military-blue.jpg +0 -0
  15. package/assets/screenshots/wheel-date-picker.jpg +0 -0
  16. package/lib/components/Calendar/Calendar.d.ts +35 -0
  17. package/lib/components/Calendar/Calendar.d.ts.map +1 -0
  18. package/lib/components/Calendar/Calendar.js +126 -0
  19. package/lib/components/Calendar/Calendar.js.map +1 -0
  20. package/lib/components/Calendar/CalendarGrid.d.ts +11 -0
  21. package/lib/components/Calendar/CalendarGrid.d.ts.map +1 -0
  22. package/lib/components/Calendar/CalendarGrid.js +22 -0
  23. package/lib/components/Calendar/CalendarGrid.js.map +1 -0
  24. package/lib/components/Calendar/CalendarHeader.d.ts +23 -0
  25. package/lib/components/Calendar/CalendarHeader.d.ts.map +1 -0
  26. package/lib/components/Calendar/CalendarHeader.js +62 -0
  27. package/lib/components/Calendar/CalendarHeader.js.map +1 -0
  28. package/lib/components/Calendar/DateCell.d.ts +11 -0
  29. package/lib/components/Calendar/DateCell.d.ts.map +1 -0
  30. package/lib/components/Calendar/DateCell.js +71 -0
  31. package/lib/components/Calendar/DateCell.js.map +1 -0
  32. package/lib/components/Calendar/MonthYearSelectorModal.d.ts +17 -0
  33. package/lib/components/Calendar/MonthYearSelectorModal.d.ts.map +1 -0
  34. package/lib/components/Calendar/MonthYearSelectorModal.js +253 -0
  35. package/lib/components/Calendar/MonthYearSelectorModal.js.map +1 -0
  36. package/lib/components/Calendar/WeekDays.d.ts +13 -0
  37. package/lib/components/Calendar/WeekDays.d.ts.map +1 -0
  38. package/lib/components/Calendar/WeekDays.js +34 -0
  39. package/lib/components/Calendar/WeekDays.js.map +1 -0
  40. package/lib/components/Calendar/index.d.ts +7 -0
  41. package/lib/components/Calendar/index.d.ts.map +1 -0
  42. package/lib/components/Calendar/index.js +23 -0
  43. package/lib/components/Calendar/index.js.map +1 -0
  44. package/lib/components/DatePicker.d.ts +4 -0
  45. package/lib/components/DatePicker.d.ts.map +1 -0
  46. package/lib/components/DatePicker.js +498 -0
  47. package/lib/components/DatePicker.js.map +1 -0
  48. package/lib/components/Input/CalendarPopup.d.ts +26 -0
  49. package/lib/components/Input/CalendarPopup.d.ts.map +1 -0
  50. package/lib/components/Input/CalendarPopup.js +60 -0
  51. package/lib/components/Input/CalendarPopup.js.map +1 -0
  52. package/lib/components/Input/DateInput.d.ts +29 -0
  53. package/lib/components/Input/DateInput.d.ts.map +1 -0
  54. package/lib/components/Input/DateInput.js +110 -0
  55. package/lib/components/Input/DateInput.js.map +1 -0
  56. package/lib/components/Input/index.d.ts +3 -0
  57. package/lib/components/Input/index.d.ts.map +1 -0
  58. package/lib/components/Input/index.js +19 -0
  59. package/lib/components/Input/index.js.map +1 -0
  60. package/lib/components/ManualDateInput/DateInputField.d.ts +19 -0
  61. package/lib/components/ManualDateInput/DateInputField.d.ts.map +1 -0
  62. package/lib/components/ManualDateInput/DateInputField.js +345 -0
  63. package/lib/components/ManualDateInput/DateInputField.js.map +1 -0
  64. package/lib/components/ManualDateInput/DateValidationMessage.d.ts +8 -0
  65. package/lib/components/ManualDateInput/DateValidationMessage.d.ts.map +1 -0
  66. package/lib/components/ManualDateInput/DateValidationMessage.js +45 -0
  67. package/lib/components/ManualDateInput/DateValidationMessage.js.map +1 -0
  68. package/lib/components/ManualDateInput/ManualDateInput.d.ts +19 -0
  69. package/lib/components/ManualDateInput/ManualDateInput.d.ts.map +1 -0
  70. package/lib/components/ManualDateInput/ManualDateInput.js +18 -0
  71. package/lib/components/ManualDateInput/ManualDateInput.js.map +1 -0
  72. package/lib/components/ManualDateInput/index.d.ts +4 -0
  73. package/lib/components/ManualDateInput/index.d.ts.map +1 -0
  74. package/lib/components/ManualDateInput/index.js +20 -0
  75. package/lib/components/ManualDateInput/index.js.map +1 -0
  76. package/lib/components/Range/RangeDateCell.d.ts +11 -0
  77. package/lib/components/Range/RangeDateCell.d.ts.map +1 -0
  78. package/lib/components/Range/RangeDateCell.js +107 -0
  79. package/lib/components/Range/RangeDateCell.js.map +1 -0
  80. package/lib/components/Range/RangePicker.d.ts +29 -0
  81. package/lib/components/Range/RangePicker.d.ts.map +1 -0
  82. package/lib/components/Range/RangePicker.js +261 -0
  83. package/lib/components/Range/RangePicker.js.map +1 -0
  84. package/lib/components/Range/index.d.ts +3 -0
  85. package/lib/components/Range/index.d.ts.map +1 -0
  86. package/lib/components/Range/index.js +19 -0
  87. package/lib/components/Range/index.js.map +1 -0
  88. package/lib/components/Time/ClockDial.d.ts +15 -0
  89. package/lib/components/Time/ClockDial.d.ts.map +1 -0
  90. package/lib/components/Time/ClockDial.js +347 -0
  91. package/lib/components/Time/ClockDial.js.map +1 -0
  92. package/lib/components/Time/DateTimePicker.d.ts +31 -0
  93. package/lib/components/Time/DateTimePicker.d.ts.map +1 -0
  94. package/lib/components/Time/DateTimePicker.js +197 -0
  95. package/lib/components/Time/DateTimePicker.js.map +1 -0
  96. package/lib/components/Time/TimePicker.d.ts +31 -0
  97. package/lib/components/Time/TimePicker.d.ts.map +1 -0
  98. package/lib/components/Time/TimePicker.js +550 -0
  99. package/lib/components/Time/TimePicker.js.map +1 -0
  100. package/lib/components/Time/WheelTimePicker.d.ts +27 -0
  101. package/lib/components/Time/WheelTimePicker.d.ts.map +1 -0
  102. package/lib/components/Time/WheelTimePicker.js +203 -0
  103. package/lib/components/Time/WheelTimePicker.js.map +1 -0
  104. package/lib/components/Time/index.d.ts +5 -0
  105. package/lib/components/Time/index.d.ts.map +1 -0
  106. package/lib/components/Time/index.js +21 -0
  107. package/lib/components/Time/index.js.map +1 -0
  108. package/lib/components/Wheel/WheelColumn.d.ts +17 -0
  109. package/lib/components/Wheel/WheelColumn.d.ts.map +1 -0
  110. package/lib/components/Wheel/WheelColumn.js +192 -0
  111. package/lib/components/Wheel/WheelColumn.js.map +1 -0
  112. package/lib/components/Wheel/WheelPicker.d.ts +26 -0
  113. package/lib/components/Wheel/WheelPicker.d.ts.map +1 -0
  114. package/lib/components/Wheel/WheelPicker.js +123 -0
  115. package/lib/components/Wheel/WheelPicker.js.map +1 -0
  116. package/lib/components/Wheel/index.d.ts +3 -0
  117. package/lib/components/Wheel/index.d.ts.map +1 -0
  118. package/lib/components/Wheel/index.js +19 -0
  119. package/lib/components/Wheel/index.js.map +1 -0
  120. package/lib/components/common/Button.d.ts +17 -0
  121. package/lib/components/common/Button.d.ts.map +1 -0
  122. package/lib/components/common/Button.js +77 -0
  123. package/lib/components/common/Button.js.map +1 -0
  124. package/lib/components/common/IconButton.d.ts +14 -0
  125. package/lib/components/common/IconButton.d.ts.map +1 -0
  126. package/lib/components/common/IconButton.js +150 -0
  127. package/lib/components/common/IconButton.js.map +1 -0
  128. package/lib/components/common/Modal.d.ts +13 -0
  129. package/lib/components/common/Modal.d.ts.map +1 -0
  130. package/lib/components/common/Modal.js +65 -0
  131. package/lib/components/common/Modal.js.map +1 -0
  132. package/lib/components/common/index.d.ts +4 -0
  133. package/lib/components/common/index.d.ts.map +1 -0
  134. package/lib/components/common/index.js +20 -0
  135. package/lib/components/common/index.js.map +1 -0
  136. package/lib/components/index.d.ts +9 -0
  137. package/lib/components/index.d.ts.map +1 -0
  138. package/lib/components/index.js +25 -0
  139. package/lib/components/index.js.map +1 -0
  140. package/lib/hooks/index.d.ts +4 -0
  141. package/lib/hooks/index.d.ts.map +1 -0
  142. package/lib/hooks/index.js +20 -0
  143. package/lib/hooks/index.js.map +1 -0
  144. package/lib/hooks/useCalendar.d.ts +34 -0
  145. package/lib/hooks/useCalendar.d.ts.map +1 -0
  146. package/lib/hooks/useCalendar.js +93 -0
  147. package/lib/hooks/useCalendar.js.map +1 -0
  148. package/lib/hooks/useDatePicker.d.ts +28 -0
  149. package/lib/hooks/useDatePicker.d.ts.map +1 -0
  150. package/lib/hooks/useDatePicker.js +150 -0
  151. package/lib/hooks/useDatePicker.js.map +1 -0
  152. package/lib/hooks/useDateRange.d.ts +23 -0
  153. package/lib/hooks/useDateRange.d.ts.map +1 -0
  154. package/lib/hooks/useDateRange.js +82 -0
  155. package/lib/hooks/useDateRange.js.map +1 -0
  156. package/lib/index.d.ts +7 -0
  157. package/lib/index.d.ts.map +1 -0
  158. package/lib/index.js +29 -0
  159. package/lib/index.js.map +1 -0
  160. package/lib/localization/en.d.ts +3 -0
  161. package/lib/localization/en.d.ts.map +1 -0
  162. package/lib/localization/en.js +80 -0
  163. package/lib/localization/en.js.map +1 -0
  164. package/lib/localization/gu.d.ts +3 -0
  165. package/lib/localization/gu.d.ts.map +1 -0
  166. package/lib/localization/gu.js +80 -0
  167. package/lib/localization/gu.js.map +1 -0
  168. package/lib/localization/hi.d.ts +3 -0
  169. package/lib/localization/hi.d.ts.map +1 -0
  170. package/lib/localization/hi.js +80 -0
  171. package/lib/localization/hi.js.map +1 -0
  172. package/lib/localization/index.d.ts +8 -0
  173. package/lib/localization/index.d.ts.map +1 -0
  174. package/lib/localization/index.js +32 -0
  175. package/lib/localization/index.js.map +1 -0
  176. package/lib/themes/dark.d.ts +3 -0
  177. package/lib/themes/dark.d.ts.map +1 -0
  178. package/lib/themes/dark.js +30 -0
  179. package/lib/themes/dark.js.map +1 -0
  180. package/lib/themes/index.d.ts +16 -0
  181. package/lib/themes/index.d.ts.map +1 -0
  182. package/lib/themes/index.js +56 -0
  183. package/lib/themes/index.js.map +1 -0
  184. package/lib/themes/light.d.ts +3 -0
  185. package/lib/themes/light.d.ts.map +1 -0
  186. package/lib/themes/light.js +30 -0
  187. package/lib/themes/light.js.map +1 -0
  188. package/lib/types/index.d.ts +344 -0
  189. package/lib/types/index.d.ts.map +1 -0
  190. package/lib/types/index.js +3 -0
  191. package/lib/types/index.js.map +1 -0
  192. package/lib/utils/calendarUtils.d.ts +27 -0
  193. package/lib/utils/calendarUtils.d.ts.map +1 -0
  194. package/lib/utils/calendarUtils.js +108 -0
  195. package/lib/utils/calendarUtils.js.map +1 -0
  196. package/lib/utils/dateFormatting.d.ts +29 -0
  197. package/lib/utils/dateFormatting.d.ts.map +1 -0
  198. package/lib/utils/dateFormatting.js +114 -0
  199. package/lib/utils/dateFormatting.js.map +1 -0
  200. package/lib/utils/dateParsing.d.ts +23 -0
  201. package/lib/utils/dateParsing.d.ts.map +1 -0
  202. package/lib/utils/dateParsing.js +289 -0
  203. package/lib/utils/dateParsing.js.map +1 -0
  204. package/lib/utils/dateUtils.d.ts +20 -0
  205. package/lib/utils/dateUtils.d.ts.map +1 -0
  206. package/lib/utils/dateUtils.js +115 -0
  207. package/lib/utils/dateUtils.js.map +1 -0
  208. package/lib/utils/dateValidation.d.ts +36 -0
  209. package/lib/utils/dateValidation.d.ts.map +1 -0
  210. package/lib/utils/dateValidation.js +196 -0
  211. package/lib/utils/dateValidation.js.map +1 -0
  212. package/lib/utils/index.d.ts +7 -0
  213. package/lib/utils/index.d.ts.map +1 -0
  214. package/lib/utils/index.js +23 -0
  215. package/lib/utils/index.js.map +1 -0
  216. package/lib/utils/timeUtils.d.ts +78 -0
  217. package/lib/utils/timeUtils.d.ts.map +1 -0
  218. package/lib/utils/timeUtils.js +335 -0
  219. package/lib/utils/timeUtils.js.map +1 -0
  220. package/package.json +92 -3
  221. package/src/components/Calendar/Calendar.tsx +314 -0
  222. package/src/components/Calendar/CalendarGrid.tsx +47 -0
  223. package/src/components/Calendar/CalendarHeader.tsx +176 -0
  224. package/src/components/Calendar/DateCell.tsx +118 -0
  225. package/src/components/Calendar/MonthYearSelectorModal.tsx +407 -0
  226. package/src/components/Calendar/WeekDays.tsx +49 -0
  227. package/src/components/Calendar/index.ts +6 -0
  228. package/src/components/DatePicker.tsx +834 -0
  229. package/src/components/Input/CalendarPopup.tsx +168 -0
  230. package/src/components/Input/DateInput.tsx +259 -0
  231. package/src/components/Input/index.ts +2 -0
  232. package/src/components/ManualDateInput/DateInputField.tsx +493 -0
  233. package/src/components/ManualDateInput/DateValidationMessage.tsx +65 -0
  234. package/src/components/ManualDateInput/ManualDateInput.tsx +66 -0
  235. package/src/components/ManualDateInput/index.ts +3 -0
  236. package/src/components/Range/RangeDateCell.tsx +174 -0
  237. package/src/components/Range/RangePicker.tsx +484 -0
  238. package/src/components/Range/index.ts +2 -0
  239. package/src/components/Time/ClockDial.tsx +450 -0
  240. package/src/components/Time/DateTimePicker.tsx +395 -0
  241. package/src/components/Time/TimePicker.tsx +899 -0
  242. package/src/components/Time/WheelTimePicker.tsx +356 -0
  243. package/src/components/Time/index.ts +4 -0
  244. package/src/components/Wheel/WheelColumn.tsx +300 -0
  245. package/src/components/Wheel/WheelPicker.tsx +265 -0
  246. package/src/components/Wheel/index.ts +2 -0
  247. package/src/components/common/Button.tsx +125 -0
  248. package/src/components/common/IconButton.tsx +237 -0
  249. package/src/components/common/Modal.tsx +137 -0
  250. package/src/components/common/index.ts +3 -0
  251. package/src/components/index.ts +8 -0
  252. package/src/hooks/index.ts +3 -0
  253. package/src/hooks/useCalendar.ts +153 -0
  254. package/src/hooks/useDatePicker.ts +216 -0
  255. package/src/hooks/useDateRange.ts +135 -0
  256. package/src/index.ts +17 -0
  257. package/src/localization/en.ts +78 -0
  258. package/src/localization/gu.ts +78 -0
  259. package/src/localization/hi.ts +78 -0
  260. package/src/localization/index.ts +31 -0
  261. package/src/themes/dark.ts +28 -0
  262. package/src/themes/index.ts +73 -0
  263. package/src/themes/light.ts +28 -0
  264. package/src/types/index.ts +452 -0
  265. package/src/utils/calendarUtils.ts +152 -0
  266. package/src/utils/dateFormatting.ts +125 -0
  267. package/src/utils/dateParsing.ts +335 -0
  268. package/src/utils/dateUtils.ts +117 -0
  269. package/src/utils/dateValidation.ts +276 -0
  270. package/src/utils/index.ts +6 -0
  271. package/src/utils/timeUtils.ts +416 -0
@@ -0,0 +1,834 @@
1
+ import React, { useState, useEffect, useCallback } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ TouchableOpacity,
6
+ ScrollView,
7
+ StyleSheet,
8
+ StyleProp,
9
+ ViewStyle,
10
+ } from 'react-native';
11
+ import type {
12
+ DateFormat,
13
+ DatePickerProps,
14
+ SingleDatePickerProps,
15
+ RangeDatePickerProps,
16
+ InputDatePickerProps,
17
+ WheelDatePickerProps,
18
+ TimePickerComponentProps,
19
+ DateTimePickerProps,
20
+ ValidationResult,
21
+ } from '../types';
22
+ import { resolveTheme } from '../themes';
23
+ import { getLocale } from '../localization';
24
+ import { useDatePicker } from '../hooks/useDatePicker';
25
+ import { formatDate } from '../utils/dateFormatting';
26
+ import { parseDateStrict, formatMaskedInput } from '../utils/dateParsing';
27
+ import { validateDate } from '../utils/dateValidation';
28
+ import { Calendar } from './Calendar/Calendar';
29
+ import { WheelPicker } from './Wheel/WheelPicker';
30
+ import { RangePicker } from './Range/RangePicker';
31
+ import { DateInput } from './Input/DateInput';
32
+ import { DateInputField } from './ManualDateInput/DateInputField';
33
+ import { TimePicker } from './Time/TimePicker';
34
+ import { DateTimePicker } from './Time/DateTimePicker';
35
+ import { Modal } from './common/Modal';
36
+ import { MonthYearSelectorModal } from './Calendar/MonthYearSelectorModal';
37
+
38
+ export const DatePicker: React.FC<DatePickerProps> = (props) => {
39
+ const {
40
+ mode = 'calendar',
41
+ theme: themeProp = 'light',
42
+ locale: localeProp = 'en',
43
+ accentColor,
44
+ textColor,
45
+ backgroundColor,
46
+ cardColor,
47
+ modalBackgroundColor,
48
+ modalContentStyle,
49
+ borderRadius,
50
+ minimumDate,
51
+ maximumDate,
52
+ disabledDates,
53
+ disabledWeekdays,
54
+ firstDayOfWeek = 0,
55
+ format,
56
+ showFormatSelector = false,
57
+ supportedFormats,
58
+ onFormatChange,
59
+ is24Hour,
60
+ minuteInterval = 1,
61
+ minimumTime,
62
+ maximumTime,
63
+ showSeconds = false,
64
+ timePickerLayout = 'wheel',
65
+ modal = false,
66
+ open = false,
67
+ autoCloseOnSelect = false,
68
+ onClose,
69
+ allowManualEntry = false,
70
+ defaultManualMode = false,
71
+ manualEntryType = 'single',
72
+ showActionButtons = true,
73
+ showTodayButton = true,
74
+ showClearButton = true,
75
+ onConfirm,
76
+ onCancel,
77
+ onClear,
78
+ style,
79
+ testID,
80
+ } = props;
81
+
82
+ const theme = resolveTheme(themeProp, {
83
+ accentColor,
84
+ textColor,
85
+ backgroundColor,
86
+ cardColor,
87
+ modalBackgroundColor,
88
+ borderRadius,
89
+ });
90
+
91
+ const locale = getLocale(localeProp);
92
+
93
+ // Single date picker hook for calendar mode
94
+ const singleProps = props as SingleDatePickerProps;
95
+ const defaultFormat = mode === 'time'
96
+ ? (is24Hour ? 'HH:mm' : 'hh:mm A')
97
+ : (mode === 'datetime'
98
+ ? (is24Hour ? 'DD/MM/YYYY HH:mm' : 'DD/MM/YYYY hh:mm A')
99
+ : 'DD/MM/YYYY');
100
+
101
+ const [activeFormat, setActiveFormat] = useState<DateFormat>(() => format || defaultFormat);
102
+
103
+ useEffect(() => {
104
+ if (format) {
105
+ setActiveFormat(format);
106
+ }
107
+ }, [format]);
108
+
109
+ const {
110
+ selectedDate,
111
+ manualText,
112
+ isManualMode,
113
+ validationResult,
114
+ selectDate,
115
+ handleManualInputChange,
116
+ toggleManualMode,
117
+ clear,
118
+ } = useDatePicker({
119
+ value: singleProps.value,
120
+ defaultValue: singleProps.defaultValue,
121
+ onChange: singleProps.onChange,
122
+ format: activeFormat,
123
+ locale,
124
+ minimumDate,
125
+ maximumDate,
126
+ disabledDates,
127
+ disabledWeekdays,
128
+ allowManualEntry,
129
+ defaultManualMode,
130
+ });
131
+
132
+ // Check if component is in modal presentation mode
133
+ const hasModalProp = 'modal' in props && props.modal !== undefined;
134
+ const isModalMode = hasModalProp
135
+ ? (open !== undefined ? Boolean(modal) : true)
136
+ : (Boolean(modal) || open !== undefined);
137
+ const isVisible = open !== undefined ? Boolean(open) : Boolean(modal);
138
+
139
+ // Draft value while modal is open, so changes are only committed when Confirm button is pressed
140
+ const [draftValue, setDraftValue] = useState<any>(() => {
141
+ if (mode === 'range') {
142
+ const rp = props as RangeDatePickerProps;
143
+ return {
144
+ startDate: rp.startDate ?? rp.defaultStartDate ?? null,
145
+ endDate: rp.endDate ?? rp.defaultEndDate ?? null,
146
+ };
147
+ }
148
+ return singleProps.value ?? singleProps.defaultValue ?? null;
149
+ });
150
+
151
+ const [draftDateText, setDraftDateText] = useState<string>(() => {
152
+ const initial = singleProps.value ?? singleProps.defaultValue ?? null;
153
+ return initial ? formatDate(initial, activeFormat, locale) : '';
154
+ });
155
+
156
+ const [draftValidation, setDraftValidation] = useState<ValidationResult>({ isValid: true });
157
+
158
+ // Track month & year selector modal state for seamless modal-to-modal handoff
159
+ const [isMonthYearSelectorOpen, setIsMonthYearSelectorOpen] = useState(false);
160
+ const [modalViewYear, setModalViewYear] = useState<number>(() => {
161
+ const initial = singleProps.value ?? singleProps.defaultValue ?? new Date();
162
+ return (initial instanceof Date && !isNaN(initial.getTime()))
163
+ ? initial.getFullYear()
164
+ : new Date().getFullYear();
165
+ });
166
+ const [modalViewMonth, setModalViewMonth] = useState<number>(() => {
167
+ const initial = singleProps.value ?? singleProps.defaultValue ?? new Date();
168
+ return (initial instanceof Date && !isNaN(initial.getTime()))
169
+ ? initial.getMonth()
170
+ : new Date().getMonth();
171
+ });
172
+
173
+ // Track modal open transition so draft value is only initialized when modal initially opens
174
+ const prevIsVisibleRef = React.useRef(false);
175
+
176
+ // Re-sync draft value and draft text whenever modal opens or external value changes
177
+ useEffect(() => {
178
+ const justOpened = isVisible && !prevIsVisibleRef.current;
179
+ prevIsVisibleRef.current = isVisible;
180
+
181
+ if (justOpened) {
182
+ setIsMonthYearSelectorOpen(false);
183
+ if (mode === 'range') {
184
+ const rp = props as RangeDatePickerProps;
185
+ const start = rp.startDate ?? rp.defaultStartDate ?? null;
186
+ const end = rp.endDate ?? rp.defaultEndDate ?? null;
187
+ setDraftValue({
188
+ startDate: start,
189
+ endDate: end,
190
+ });
191
+ const target = start || new Date();
192
+ setModalViewYear(target.getFullYear());
193
+ setModalViewMonth(target.getMonth());
194
+ } else {
195
+ const initialDate = singleProps.value ?? singleProps.defaultValue ?? null;
196
+ setDraftValue(initialDate);
197
+ setDraftDateText(initialDate ? formatDate(initialDate, activeFormat, locale) : '');
198
+ setDraftValidation({ isValid: true });
199
+ const target = initialDate || new Date();
200
+ setModalViewYear(target.getFullYear());
201
+ setModalViewMonth(target.getMonth());
202
+ }
203
+ }
204
+ }, [isVisible, mode, singleProps.value, singleProps.defaultValue, activeFormat, locale]);
205
+
206
+ // Synchronize draft text if active format changes while a date is selected
207
+ useEffect(() => {
208
+ if (draftValue instanceof Date && !isNaN(draftValue.getTime())) {
209
+ setDraftDateText(formatDate(draftValue, activeFormat, locale));
210
+ }
211
+ }, [activeFormat, locale]);
212
+
213
+ // Stable callback for calendar month/year view changes
214
+ const handleViewYearMonthChange = useCallback((y: number, m: number) => {
215
+ setModalViewYear((prevY) => (prevY !== y ? y : prevY));
216
+ setModalViewMonth((prevM) => (prevM !== m ? m : prevM));
217
+ }, []);
218
+
219
+ // Commit selected Month and Year from MonthYearSelectorModal to draftValue
220
+ const handleMonthYearConfirm = useCallback(
221
+ (newYear: number, newMonth: number) => {
222
+ setModalViewYear(newYear);
223
+ setModalViewMonth(newMonth);
224
+
225
+ if (draftValue instanceof Date && !isNaN(draftValue.getTime())) {
226
+ const currentDay = draftValue.getDate();
227
+ const maxDaysInNewMonth = new Date(newYear, newMonth + 1, 0).getDate();
228
+ const clampedDay = Math.min(currentDay, maxDaysInNewMonth);
229
+ const updated = new Date(
230
+ newYear,
231
+ newMonth,
232
+ clampedDay,
233
+ draftValue.getHours(),
234
+ draftValue.getMinutes(),
235
+ draftValue.getSeconds()
236
+ );
237
+ setDraftValue(updated);
238
+ setDraftDateText(formatDate(updated, activeFormat, locale));
239
+ setDraftValidation({ isValid: true });
240
+ }
241
+
242
+ setIsMonthYearSelectorOpen(false);
243
+ },
244
+ [draftValue, activeFormat, locale]
245
+ );
246
+
247
+ // Modal close handlers
248
+ const handleModalClose = useCallback(() => {
249
+ onClose?.();
250
+ onCancel?.();
251
+ }, [onClose, onCancel]);
252
+
253
+ const handleConfirmAndClose = useCallback(
254
+ (confirmedValue: any) => {
255
+ if (mode === 'range') {
256
+ const rp = props as RangeDatePickerProps;
257
+ rp.onRangeChange?.(confirmedValue);
258
+ } else {
259
+ singleProps.onChange?.(confirmedValue);
260
+ }
261
+ (onConfirm as ((v: any) => void) | undefined)?.(confirmedValue);
262
+ onClose?.();
263
+ },
264
+ [mode, singleProps, onConfirm, onClose]
265
+ );
266
+
267
+ // Synchronized date selection inside modal dialog (calendar cell click or Today button tap)
268
+ const handleModalDateSelect = useCallback(
269
+ (newDate: Date | null) => {
270
+ setDraftValue(newDate);
271
+ if (newDate) {
272
+ const validation = validateDate(newDate, {
273
+ minimumDate,
274
+ maximumDate,
275
+ disabledDates,
276
+ disabledWeekdays,
277
+ locale,
278
+ });
279
+ setDraftValidation(validation);
280
+ setDraftDateText(formatDate(newDate, activeFormat, locale));
281
+ } else {
282
+ setDraftDateText('');
283
+ setDraftValidation({ isValid: true });
284
+ }
285
+ if (autoCloseOnSelect && newDate) {
286
+ handleConfirmAndClose(newDate);
287
+ }
288
+ },
289
+ [
290
+ activeFormat,
291
+ locale,
292
+ minimumDate,
293
+ maximumDate,
294
+ disabledDates,
295
+ disabledWeekdays,
296
+ autoCloseOnSelect,
297
+ handleConfirmAndClose,
298
+ ]
299
+ );
300
+
301
+ // Synchronized text input change inside modal dialog (typing into DateInputField)
302
+ const handleModalTextInputChange = useCallback(
303
+ (text: string) => {
304
+ const masked = manualEntryType === 'split' ? text : formatMaskedInput(text, activeFormat);
305
+ setDraftDateText(masked);
306
+
307
+ if (!masked.trim()) {
308
+ setDraftValidation({ isValid: true });
309
+ setDraftValue(null);
310
+ return;
311
+ }
312
+
313
+ const isCompleteLength = masked.length >= 10;
314
+ if (isCompleteLength) {
315
+ const parsed = parseDateStrict(masked, activeFormat, locale);
316
+ if (!parsed.validation.isValid || !parsed.date) {
317
+ setDraftValidation(parsed.validation);
318
+ return;
319
+ }
320
+
321
+ const constraintValidation = validateDate(parsed.date, {
322
+ minimumDate,
323
+ maximumDate,
324
+ disabledDates,
325
+ disabledWeekdays,
326
+ locale,
327
+ });
328
+
329
+ setDraftValidation(constraintValidation);
330
+ if (constraintValidation.isValid) {
331
+ setDraftValue(parsed.date);
332
+ }
333
+ } else {
334
+ setDraftValidation({ isValid: true });
335
+ }
336
+ },
337
+ [
338
+ manualEntryType,
339
+ activeFormat,
340
+ locale,
341
+ minimumDate,
342
+ maximumDate,
343
+ disabledDates,
344
+ disabledWeekdays,
345
+ ]
346
+ );
347
+
348
+ // Seamless styling inside modal dialog: strip nested border and background
349
+ const pickerStyle: StyleProp<ViewStyle> = isModalMode
350
+ ? [
351
+ {
352
+ borderWidth: 0,
353
+ backgroundColor: 'transparent',
354
+ shadowOpacity: 0,
355
+ elevation: 0,
356
+ padding: 0,
357
+ flex: 1,
358
+ justifyContent: 'space-between',
359
+ },
360
+ style,
361
+ ]
362
+ : style;
363
+
364
+ const renderContent = () => {
365
+ // 1. Dedicated Time Picker Mode
366
+ if (mode === 'time') {
367
+ const timeProps = props as TimePickerComponentProps;
368
+ return (
369
+ <TimePicker
370
+ value={
371
+ isModalMode
372
+ ? (draftValue !== undefined ? draftValue : selectedDate)
373
+ : (timeProps.value !== undefined ? timeProps.value : selectedDate)
374
+ }
375
+ defaultValue={timeProps.defaultValue}
376
+ onChange={(d) => {
377
+ if (isModalMode) {
378
+ setDraftValue(d);
379
+ } else {
380
+ selectDate(d);
381
+ timeProps.onChange?.(d);
382
+ }
383
+ }}
384
+ is24Hour={is24Hour}
385
+ minuteInterval={minuteInterval}
386
+ minimumTime={minimumTime}
387
+ maximumTime={maximumTime}
388
+ selectedDate={isModalMode ? (draftValue ?? selectedDate) : selectedDate}
389
+ minimumDate={minimumDate}
390
+ maximumDate={maximumDate}
391
+ showSeconds={showSeconds}
392
+ timePickerLayout={timePickerLayout}
393
+ format={activeFormat}
394
+ theme={theme}
395
+ locale={locale}
396
+ showActionButtons={showActionButtons}
397
+ showNowButton={showTodayButton}
398
+ showClearButton={showClearButton}
399
+ onConfirm={(d) => {
400
+ handleConfirmAndClose(d ?? draftValue);
401
+ }}
402
+ onCancel={handleModalClose}
403
+ onClear={() => {
404
+ if (isModalMode) setDraftValue(null);
405
+ clear();
406
+ onClear?.();
407
+ }}
408
+ autoCloseOnSelect={isModalMode && autoCloseOnSelect}
409
+ onClose={handleModalClose}
410
+ style={pickerStyle}
411
+ />
412
+ );
413
+ }
414
+
415
+ // 2. Combined DateTime Picker Mode
416
+ if (mode === 'datetime') {
417
+ const dateTimeProps = props as DateTimePickerProps;
418
+ return (
419
+ <DateTimePicker
420
+ value={
421
+ isModalMode
422
+ ? (draftValue !== undefined ? draftValue : selectedDate)
423
+ : (dateTimeProps.value !== undefined ? dateTimeProps.value : selectedDate)
424
+ }
425
+ defaultValue={dateTimeProps.defaultValue}
426
+ onChange={(d) => {
427
+ if (isModalMode) {
428
+ setDraftValue(d);
429
+ } else {
430
+ selectDate(d);
431
+ dateTimeProps.onChange?.(d);
432
+ }
433
+ }}
434
+ format={activeFormat}
435
+ is24Hour={is24Hour}
436
+ minuteInterval={minuteInterval}
437
+ minimumTime={minimumTime}
438
+ maximumTime={maximumTime}
439
+ minimumDate={minimumDate}
440
+ maximumDate={maximumDate}
441
+ disabledDates={disabledDates}
442
+ disabledWeekdays={disabledWeekdays}
443
+ firstDayOfWeek={firstDayOfWeek}
444
+ showSeconds={showSeconds}
445
+ timePickerLayout={timePickerLayout}
446
+ allowManualEntry={allowManualEntry}
447
+ theme={theme}
448
+ locale={locale}
449
+ initialTab={dateTimeProps.initialTab}
450
+ showActionButtons={showActionButtons}
451
+ onConfirm={(d) => {
452
+ handleConfirmAndClose(d ?? draftValue);
453
+ }}
454
+ onCancel={handleModalClose}
455
+ onClear={() => {
456
+ if (isModalMode) setDraftValue(null);
457
+ clear();
458
+ onClear?.();
459
+ }}
460
+ style={pickerStyle}
461
+ />
462
+ );
463
+ }
464
+
465
+ // 3. Wheel Picker Mode
466
+ if (mode === 'wheel') {
467
+ const wheelProps = props as WheelDatePickerProps;
468
+ return (
469
+ <WheelPicker
470
+ value={isModalMode ? (draftValue ?? wheelProps.value ?? selectedDate) : (wheelProps.value ?? selectedDate)}
471
+ onChange={(d) => {
472
+ if (isModalMode) {
473
+ setDraftValue(d);
474
+ } else {
475
+ selectDate(d);
476
+ wheelProps.onChange?.(d);
477
+ }
478
+ }}
479
+ theme={theme}
480
+ locale={locale}
481
+ minimumDate={minimumDate}
482
+ maximumDate={maximumDate}
483
+ disabledDates={disabledDates}
484
+ disabledWeekdays={disabledWeekdays}
485
+ minYear={wheelProps.minYear}
486
+ maxYear={wheelProps.maxYear}
487
+ itemHeight={wheelProps.itemHeight}
488
+ visibleItems={wheelProps.visibleItems}
489
+ showActionButtons={showActionButtons}
490
+ showTodayButton={showTodayButton}
491
+ showClearButton={showClearButton}
492
+ onConfirm={(d) => {
493
+ handleConfirmAndClose(d ?? draftValue);
494
+ }}
495
+ onCancel={handleModalClose}
496
+ onClear={() => {
497
+ if (isModalMode) setDraftValue(null);
498
+ onClear?.();
499
+ }}
500
+ style={pickerStyle}
501
+ />
502
+ );
503
+ }
504
+
505
+ // 4. Date Range Mode
506
+ if (mode === 'range') {
507
+ const rangeProps = props as RangeDatePickerProps;
508
+ return (
509
+ <RangePicker
510
+ startDate={isModalMode ? draftValue?.startDate : rangeProps.startDate}
511
+ endDate={isModalMode ? draftValue?.endDate : rangeProps.endDate}
512
+ defaultStartDate={rangeProps.defaultStartDate}
513
+ defaultEndDate={rangeProps.defaultEndDate}
514
+ onRangeChange={(range) => {
515
+ if (isModalMode) {
516
+ setDraftValue(range);
517
+ } else {
518
+ rangeProps.onRangeChange?.(range);
519
+ }
520
+ }}
521
+ maxRangeDays={rangeProps.maxRangeDays}
522
+ format={activeFormat}
523
+ theme={theme}
524
+ locale={locale}
525
+ firstDayOfWeek={firstDayOfWeek}
526
+ minimumDate={minimumDate}
527
+ maximumDate={maximumDate}
528
+ disabledDates={disabledDates}
529
+ disabledWeekdays={disabledWeekdays}
530
+ showActionButtons={showActionButtons}
531
+ onConfirm={(range) => {
532
+ handleConfirmAndClose(range ?? draftValue);
533
+ }}
534
+ onCancel={handleModalClose}
535
+ style={pickerStyle}
536
+ viewYear={isModalMode ? modalViewYear : undefined}
537
+ viewMonth={isModalMode ? modalViewMonth : undefined}
538
+ onViewYearMonthChange={isModalMode ? handleViewYearMonthChange : undefined}
539
+ onOpenMonthYearSelector={isModalMode ? () => setIsMonthYearSelectorOpen(true) : undefined}
540
+ />
541
+ );
542
+ }
543
+
544
+ // 5. Input Mode
545
+ if (mode === 'input') {
546
+ const inputProps = props as InputDatePickerProps;
547
+
548
+ // When presented in modal dialog mode (<DatePicker modal open={...} mode="input" />)
549
+ if (isModalMode) {
550
+ return (
551
+ <View style={styles.modalInputWrapper}>
552
+ <View style={styles.modalInputTopSection}>
553
+ <DateInputField
554
+ value={draftDateText}
555
+ onChangeText={handleModalTextInputChange}
556
+ format={activeFormat}
557
+ theme={theme}
558
+ locale={locale}
559
+ type={manualEntryType}
560
+ placeholder={inputProps.placeholder}
561
+ label={inputProps.label}
562
+ isError={!draftValidation.isValid}
563
+ editable={inputProps.editable !== false}
564
+ />
565
+ </View>
566
+
567
+ <Calendar
568
+ selectedDate={draftValue !== undefined ? draftValue : selectedDate}
569
+ onSelectDate={handleModalDateSelect}
570
+ theme={theme}
571
+ locale={locale}
572
+ format={activeFormat}
573
+ firstDayOfWeek={firstDayOfWeek}
574
+ minimumDate={minimumDate}
575
+ maximumDate={maximumDate}
576
+ disabledDates={disabledDates}
577
+ disabledWeekdays={disabledWeekdays}
578
+ showActionButtons={showActionButtons}
579
+ showTodayButton={showTodayButton}
580
+ showClearButton={showClearButton}
581
+ onConfirm={(d) => {
582
+ if (!draftValidation.isValid) return;
583
+ handleConfirmAndClose(d ?? draftValue ?? selectedDate);
584
+ }}
585
+ onCancel={handleModalClose}
586
+ onClear={() => {
587
+ handleModalDateSelect(null);
588
+ clear();
589
+ onClear?.();
590
+ }}
591
+ style={pickerStyle}
592
+ viewYear={modalViewYear}
593
+ viewMonth={modalViewMonth}
594
+ onViewYearMonthChange={handleViewYearMonthChange}
595
+ onOpenMonthYearSelector={() => setIsMonthYearSelectorOpen(true)}
596
+ />
597
+ </View>
598
+ );
599
+ }
600
+
601
+ // Inline mode: renders the interactive text input that triggers the popup modal
602
+ return (
603
+ <DateInput
604
+ value={inputProps.value !== undefined ? inputProps.value : selectedDate}
605
+ defaultValue={inputProps.defaultValue}
606
+ onChange={(d) => {
607
+ selectDate(d);
608
+ inputProps.onChange?.(d);
609
+ }}
610
+ onConfirm={(d) => {
611
+ selectDate(d);
612
+ inputProps.onChange?.(d);
613
+ inputProps.onConfirm?.(d);
614
+ }}
615
+ onCancel={handleModalClose}
616
+ onClear={() => {
617
+ clear();
618
+ onClear?.();
619
+ }}
620
+ format={activeFormat}
621
+ theme={theme}
622
+ locale={locale}
623
+ minimumDate={minimumDate}
624
+ maximumDate={maximumDate}
625
+ disabledDates={disabledDates}
626
+ disabledWeekdays={disabledWeekdays}
627
+ firstDayOfWeek={firstDayOfWeek}
628
+ allowManualEntry={allowManualEntry}
629
+ manualEntryType={manualEntryType}
630
+ placeholder={inputProps.placeholder}
631
+ label={inputProps.label}
632
+ editable={inputProps.editable}
633
+ style={pickerStyle}
634
+ inputStyle={inputProps.inputStyle}
635
+ inputContainerStyle={inputProps.inputContainerStyle}
636
+ />
637
+ );
638
+ }
639
+
640
+ // 6. Default mode: 'calendar'
641
+ return (
642
+ <Calendar
643
+ selectedDate={isModalMode ? (draftValue !== undefined ? draftValue : selectedDate) : selectedDate}
644
+ onSelectDate={isModalMode ? handleModalDateSelect : selectDate}
645
+ theme={theme}
646
+ locale={locale}
647
+ format={activeFormat}
648
+ firstDayOfWeek={firstDayOfWeek}
649
+ minimumDate={minimumDate}
650
+ maximumDate={maximumDate}
651
+ disabledDates={disabledDates}
652
+ disabledWeekdays={disabledWeekdays}
653
+ allowManualEntry={allowManualEntry}
654
+ manualEntryType={manualEntryType}
655
+ manualText={isModalMode ? draftDateText : manualText}
656
+ isManualMode={isManualMode}
657
+ validationResult={isModalMode ? draftValidation : validationResult}
658
+ onManualTextChange={isModalMode ? handleModalTextInputChange : handleManualInputChange}
659
+ onToggleManualMode={toggleManualMode}
660
+ showActionButtons={showActionButtons}
661
+ showTodayButton={showTodayButton}
662
+ showClearButton={showClearButton}
663
+ onConfirm={(d) => {
664
+ if (isModalMode && !draftValidation.isValid) return;
665
+ handleConfirmAndClose(d ?? draftValue ?? selectedDate);
666
+ }}
667
+ onCancel={handleModalClose}
668
+ onClear={() => {
669
+ if (isModalMode) handleModalDateSelect(null);
670
+ clear();
671
+ onClear?.();
672
+ }}
673
+ style={pickerStyle}
674
+ viewYear={isModalMode ? modalViewYear : undefined}
675
+ viewMonth={isModalMode ? modalViewMonth : undefined}
676
+ onViewYearMonthChange={isModalMode ? handleViewYearMonthChange : undefined}
677
+ onOpenMonthYearSelector={isModalMode ? () => setIsMonthYearSelectorOpen(true) : undefined}
678
+ />
679
+ );
680
+ };
681
+
682
+ const renderFormatSelector = () => {
683
+ if (!showFormatSelector) return null;
684
+
685
+ const availableFormats = supportedFormats || [
686
+ 'DD/MM/YYYY',
687
+ 'MM/DD/YYYY',
688
+ 'YYYY/DD/MM',
689
+ 'YYYY/MM/DD',
690
+ ];
691
+
692
+ return (
693
+ <View
694
+ style={[
695
+ styles.formatSelectorContainer,
696
+ {
697
+ borderColor: theme.borderColor,
698
+ backgroundColor: `${theme.primaryColor}06`,
699
+ },
700
+ ]}
701
+ >
702
+ <Text style={[styles.formatSelectorTitle, { color: theme.secondaryTextColor }]}>
703
+ FORMAT:
704
+ </Text>
705
+ <ScrollView
706
+ horizontal
707
+ showsHorizontalScrollIndicator={false}
708
+ contentContainerStyle={styles.formatPillsRow}
709
+ >
710
+ {availableFormats.map((fmt) => {
711
+ const isSelected = activeFormat === fmt;
712
+ return (
713
+ <TouchableOpacity
714
+ key={fmt}
715
+ activeOpacity={0.75}
716
+ onPress={() => {
717
+ setActiveFormat(fmt);
718
+ onFormatChange?.(fmt);
719
+ }}
720
+ style={[
721
+ styles.formatPill,
722
+ {
723
+ backgroundColor: isSelected ? theme.primaryColor : `${theme.primaryColor}12`,
724
+ borderColor: isSelected ? theme.primaryColor : `${theme.primaryColor}24`,
725
+ },
726
+ ]}
727
+ >
728
+ <Text
729
+ style={[
730
+ styles.formatPillText,
731
+ {
732
+ color: isSelected ? '#FFFFFF' : theme.primaryColor,
733
+ fontWeight: isSelected ? '800' : '600',
734
+ },
735
+ ]}
736
+ >
737
+ {fmt}
738
+ </Text>
739
+ </TouchableOpacity>
740
+ );
741
+ })}
742
+ </ScrollView>
743
+ </View>
744
+ );
745
+ };
746
+
747
+ const content = (
748
+ <View testID={testID} style={[styles.container, isModalMode && styles.modalContainer]}>
749
+ {renderFormatSelector()}
750
+ {renderContent()}
751
+ </View>
752
+ );
753
+
754
+ if (isModalMode) {
755
+ const isManualModal = isManualMode && mode === 'calendar';
756
+ return (
757
+ <>
758
+ {/* Main Picker Modal - Automatically closes when Month & Year selector opens */}
759
+ <Modal
760
+ visible={isVisible && !isMonthYearSelectorOpen}
761
+ onClose={handleModalClose}
762
+ theme={theme}
763
+ contentStyle={[isManualModal ? styles.manualModalCard : undefined, modalContentStyle]}
764
+ >
765
+ {content}
766
+ </Modal>
767
+
768
+ {/* Month & Year Selection Modal - Re-opens the main modal upon Close or Confirm */}
769
+ <MonthYearSelectorModal
770
+ visible={isVisible && isMonthYearSelectorOpen}
771
+ onClose={() => setIsMonthYearSelectorOpen(false)}
772
+ currentYear={modalViewYear}
773
+ currentMonth={modalViewMonth}
774
+ theme={theme}
775
+ locale={locale}
776
+ onConfirm={handleMonthYearConfirm}
777
+ />
778
+ </>
779
+ );
780
+ }
781
+
782
+ return content;
783
+ };
784
+
785
+ const styles = StyleSheet.create({
786
+ container: {
787
+ width: '100%',
788
+ },
789
+ modalContainer: {
790
+ flex: 1,
791
+ justifyContent: 'space-between',
792
+ width: '100%',
793
+ },
794
+ manualModalCard: {
795
+ minHeight: 270,
796
+ maxHeight: 340,
797
+ },
798
+ formatSelectorContainer: {
799
+ flexDirection: 'row',
800
+ alignItems: 'center',
801
+ paddingVertical: 9,
802
+ paddingHorizontal: 12,
803
+ borderRadius: 14,
804
+ borderWidth: 1,
805
+ marginBottom: 12,
806
+ },
807
+ formatSelectorTitle: {
808
+ fontSize: 10,
809
+ fontWeight: '800',
810
+ letterSpacing: 0.6,
811
+ marginRight: 8,
812
+ },
813
+ formatPillsRow: {
814
+ flexDirection: 'row',
815
+ gap: 6,
816
+ },
817
+ formatPill: {
818
+ paddingVertical: 5,
819
+ paddingHorizontal: 10,
820
+ borderRadius: 8,
821
+ borderWidth: 1,
822
+ },
823
+ formatPillText: {
824
+ fontSize: 11,
825
+ },
826
+ modalInputWrapper: {
827
+ width: '100%',
828
+ flex: 1,
829
+ justifyContent: 'space-between',
830
+ },
831
+ modalInputTopSection: {
832
+ marginBottom: 4,
833
+ },
834
+ });