@izonnet-web-solution/react-native-date-time-picker-kit 0.0.0-stage → 1.0.1

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 +652 -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 +419 -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 +181 -0
  21. package/lib/module/components/DatePicker.js.map +1 -0
  22. package/lib/module/components/DateRangePicker.js +158 -0
  23. package/lib/module/components/DateRangePicker.js.map +1 -0
  24. package/lib/module/components/DateTimePicker.js +674 -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 +142 -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 +159 -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 +136 -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 +176 -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 +81 -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 +224 -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 +51 -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 +44 -0
  103. package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
  104. package/lib/typescript/src/components/DateRangePicker.d.ts +56 -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 +31 -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 +11 -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 +76 -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 +26 -0
  163. package/lib/typescript/src/types/presentation.d.ts.map +1 -0
  164. package/lib/typescript/src/types/props.d.ts +221 -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 +46 -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 +191 -4
  177. package/src/NativeDateTimePickerKit.ts +19 -0
  178. package/src/components/CalendarPicker.tsx +623 -0
  179. package/src/components/ClockPicker.tsx +403 -0
  180. package/src/components/DatePicker.tsx +276 -0
  181. package/src/components/DateRangePicker.tsx +251 -0
  182. package/src/components/DateTimePicker.tsx +1028 -0
  183. package/src/components/MonthPicker.tsx +216 -0
  184. package/src/components/TimePicker.tsx +203 -0
  185. package/src/components/TimeSlotPicker.tsx +163 -0
  186. package/src/components/WheelPicker.tsx +229 -0
  187. package/src/components/YearPicker.tsx +228 -0
  188. package/src/components/common/ModalWrapper.tsx +192 -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 +197 -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 +82 -0
  206. package/src/theme/useTheme.ts +98 -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 +28 -0
  211. package/src/types/props.ts +291 -0
  212. package/src/utils/constants.ts +15 -0
  213. package/src/utils/dateConversion.ts +273 -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,623 @@
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 { LocaleData, PartialLocaleData } from '../localization/types';
5
+ import { useTheme } from '../theme';
6
+ import type { ResolvedTheme, ThemeConfig, ThemeMode } from '../theme/types';
7
+ import { parseDate } from '../utils/dateConversion';
8
+ import { isDateDisabled } from '../utils/dateValidation';
9
+
10
+ export interface MarkedDateConfig {
11
+ marked?: boolean;
12
+ dotColor?: string;
13
+ badge?: string;
14
+ selected?: boolean;
15
+ disabled?: boolean;
16
+ }
17
+
18
+ export type MarkedDatesMap = Record<string, MarkedDateConfig>;
19
+
20
+ export interface CalendarPickerProps {
21
+ value?: Date | string | number | null;
22
+ /**
23
+ * Alias for `value`.
24
+ */
25
+ selectedDate?: Date | string | number | null;
26
+ defaultValue?: Date | string | number | null;
27
+ onChange?: (date: Date) => void;
28
+ /**
29
+ * Alias for `onChange`.
30
+ */
31
+ onDateSelect?: (date: Date) => void;
32
+ minimumDate?: Date | string | number;
33
+ /**
34
+ * Alias for `minimumDate`.
35
+ */
36
+ minDate?: Date | string | number;
37
+ maximumDate?: Date | string | number;
38
+ /**
39
+ * Alias for `maximumDate`.
40
+ */
41
+ maxDate?: Date | string | number;
42
+ disabledDates?: (Date | string)[];
43
+ disabledWeekdays?: number[];
44
+ markedDates?: MarkedDatesMap;
45
+ firstDayOfWeek?: number; // 0 = Sunday, 1 = Monday, 6 = Saturday
46
+ locale?: string | PartialLocaleData;
47
+ theme?: ThemeMode | ThemeConfig;
48
+ // Range selection mode support
49
+ rangeMode?: boolean;
50
+ startDate?: Date | null;
51
+ endDate?: Date | null;
52
+ onRangeChange?: (range: {
53
+ startDate: Date | null;
54
+ endDate: Date | null;
55
+ }) => void;
56
+ onMonthChange?: (year: number, month: number) => void;
57
+ testID?: string;
58
+ }
59
+
60
+ interface CalendarDay {
61
+ day: number;
62
+ date: Date;
63
+ dateString: string; // YYYY-MM-DD
64
+ isCurrentMonth: boolean;
65
+ isToday: boolean;
66
+ isSelected: boolean;
67
+ isRangeStart: boolean;
68
+ isRangeEnd: boolean;
69
+ isInRange: boolean;
70
+ isDisabled: boolean;
71
+ markedConfig?: MarkedDateConfig;
72
+ }
73
+
74
+ export const CalendarPicker: React.FC<CalendarPickerProps> = ({
75
+ value,
76
+ defaultValue,
77
+ onChange,
78
+ minimumDate,
79
+ maximumDate,
80
+ disabledDates,
81
+ disabledWeekdays,
82
+ markedDates,
83
+ firstDayOfWeek: propFirstDayOfWeek,
84
+ locale: propLocale,
85
+ theme: propTheme,
86
+ rangeMode = false,
87
+ startDate: propStartDate,
88
+ endDate: propEndDate,
89
+ onRangeChange,
90
+ onMonthChange,
91
+ testID,
92
+ ...restProps
93
+ }) => {
94
+ const effectiveMin = minimumDate ?? restProps.minDate;
95
+ const effectiveMax = maximumDate ?? restProps.maxDate;
96
+ const effectiveVal = value ?? restProps.selectedDate;
97
+ const effectiveOnChange = onChange ?? restProps.onDateSelect;
98
+
99
+ const resolvedTheme: ResolvedTheme = useTheme(propTheme);
100
+ const localeData: LocaleData = useLocale(propLocale);
101
+
102
+ const firstDay =
103
+ propFirstDayOfWeek !== undefined
104
+ ? propFirstDayOfWeek
105
+ : localeData.firstDayOfWeek;
106
+
107
+ // Selected date state (single mode)
108
+ const initialDate =
109
+ parseDate(effectiveVal) || parseDate(defaultValue) || new Date();
110
+ const selectedDate =
111
+ effectiveVal !== undefined ? parseDate(effectiveVal) : initialDate;
112
+
113
+ // Range dates state (range mode)
114
+ const [rangeStart, setRangeStart] = useState<Date | null>(
115
+ propStartDate ? parseDate(propStartDate) : null
116
+ );
117
+ const [rangeEnd, setRangeEnd] = useState<Date | null>(
118
+ propEndDate ? parseDate(propEndDate) : null
119
+ );
120
+
121
+ const activeStartDate =
122
+ propStartDate !== undefined ? parseDate(propStartDate) : rangeStart;
123
+ const activeEndDate =
124
+ propEndDate !== undefined ? parseDate(propEndDate) : rangeEnd;
125
+
126
+ // Visible view month & year
127
+ const [viewDate, setViewDate] = useState<Date>(() => {
128
+ return selectedDate || activeStartDate || new Date();
129
+ });
130
+
131
+ const viewYear = viewDate.getFullYear();
132
+ const viewMonth = viewDate.getMonth(); // 0-11
133
+
134
+ const minDateObj = useMemo(
135
+ () => (effectiveMin ? parseDate(effectiveMin) : null),
136
+ [effectiveMin]
137
+ );
138
+ const maxDateObj = useMemo(
139
+ () => (effectiveMax ? parseDate(effectiveMax) : null),
140
+ [effectiveMax]
141
+ );
142
+
143
+ // Month navigation
144
+ const goToPrevMonth = useCallback(() => {
145
+ setViewDate((prev) => {
146
+ const prevM = new Date(prev.getFullYear(), prev.getMonth() - 1, 1);
147
+ onMonthChange?.(prevM.getFullYear(), prevM.getMonth());
148
+ return prevM;
149
+ });
150
+ }, [onMonthChange]);
151
+
152
+ const goToNextMonth = useCallback(() => {
153
+ setViewDate((prev) => {
154
+ const nextM = new Date(prev.getFullYear(), prev.getMonth() + 1, 1);
155
+ onMonthChange?.(nextM.getFullYear(), nextM.getMonth());
156
+ return nextM;
157
+ });
158
+ }, [onMonthChange]);
159
+
160
+ // Weekday headers sorted according to firstDayOfWeek
161
+ const weekdayNames = useMemo(() => {
162
+ const list = [...localeData.weekdaysMin];
163
+ if (firstDay === 0) {
164
+ return list;
165
+ }
166
+ const rotated = [...list.slice(firstDay), ...list.slice(0, firstDay)];
167
+ return rotated;
168
+ }, [localeData.weekdaysMin, firstDay]);
169
+
170
+ // Generate calendar grid (6 rows of 7 days = 42 slots)
171
+ const daysGrid: CalendarDay[] = useMemo(() => {
172
+ const today = new Date();
173
+ const todayStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;
174
+
175
+ const firstDayOfMonth = new Date(viewYear, viewMonth, 1).getDay(); // 0 (Sun) - 6 (Sat)
176
+ let leadOffset = firstDayOfMonth - firstDay;
177
+ if (leadOffset < 0) {
178
+ leadOffset += 7;
179
+ }
180
+
181
+ const daysInCurrentMonth = new Date(viewYear, viewMonth + 1, 0).getDate();
182
+ const daysInPrevMonth = new Date(viewYear, viewMonth, 0).getDate();
183
+
184
+ const grid: CalendarDay[] = [];
185
+
186
+ // Leading days from previous month
187
+ for (let i = leadOffset - 1; i >= 0; i--) {
188
+ const dayNum = daysInPrevMonth - i;
189
+ const d = new Date(viewYear, viewMonth - 1, dayNum);
190
+ const str = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(dayNum).padStart(2, '0')}`;
191
+ grid.push({
192
+ day: dayNum,
193
+ date: d,
194
+ dateString: str,
195
+ isCurrentMonth: false,
196
+ isToday: str === todayStr,
197
+ isSelected: false,
198
+ isRangeStart: false,
199
+ isRangeEnd: false,
200
+ isInRange: false,
201
+ isDisabled: true,
202
+ });
203
+ }
204
+
205
+ // Precompute boundaries outside day loop for optimal performance
206
+ const minDayStart = minDateObj
207
+ ? new Date(
208
+ minDateObj.getFullYear(),
209
+ minDateObj.getMonth(),
210
+ minDateObj.getDate()
211
+ ).getTime()
212
+ : null;
213
+ const maxDayEnd = maxDateObj
214
+ ? new Date(
215
+ maxDateObj.getFullYear(),
216
+ maxDateObj.getMonth(),
217
+ maxDateObj.getDate(),
218
+ 23,
219
+ 59,
220
+ 59,
221
+ 999
222
+ ).getTime()
223
+ : null;
224
+
225
+ // Days in current month
226
+ for (let dayNum = 1; dayNum <= daysInCurrentMonth; dayNum++) {
227
+ const d = new Date(viewYear, viewMonth, dayNum);
228
+ const str = `${viewYear}-${String(viewMonth + 1).padStart(2, '0')}-${String(dayNum).padStart(2, '0')}`;
229
+ const isToday = str === todayStr;
230
+
231
+ // Check min/max restriction
232
+ let disabled = false;
233
+ if (minDayStart !== null && d.getTime() < minDayStart) {
234
+ disabled = true;
235
+ }
236
+ if (maxDayEnd !== null && d.getTime() > maxDayEnd) {
237
+ disabled = true;
238
+ }
239
+ if (isDateDisabled(d, disabledDates, disabledWeekdays)) {
240
+ disabled = true;
241
+ }
242
+
243
+ // Selection logic
244
+ let isSelected = false;
245
+ let isRangeStart = false;
246
+ let isRangeEnd = false;
247
+ let isInRange = false;
248
+
249
+ if (rangeMode) {
250
+ if (
251
+ activeStartDate &&
252
+ d.toDateString() === activeStartDate.toDateString()
253
+ ) {
254
+ isRangeStart = true;
255
+ isSelected = true;
256
+ }
257
+ if (
258
+ activeEndDate &&
259
+ d.toDateString() === activeEndDate.toDateString()
260
+ ) {
261
+ isRangeEnd = true;
262
+ isSelected = true;
263
+ }
264
+ if (
265
+ activeStartDate &&
266
+ activeEndDate &&
267
+ d > activeStartDate &&
268
+ d < activeEndDate
269
+ ) {
270
+ isInRange = true;
271
+ }
272
+ } else if (
273
+ selectedDate &&
274
+ d.toDateString() === selectedDate.toDateString()
275
+ ) {
276
+ isSelected = true;
277
+ }
278
+
279
+ const mark = markedDates?.[str];
280
+ if (mark?.disabled) {
281
+ disabled = true;
282
+ }
283
+
284
+ grid.push({
285
+ day: dayNum,
286
+ date: d,
287
+ dateString: str,
288
+ isCurrentMonth: true,
289
+ isToday,
290
+ isSelected,
291
+ isRangeStart,
292
+ isRangeEnd,
293
+ isInRange,
294
+ isDisabled: disabled,
295
+ markedConfig: mark,
296
+ });
297
+ }
298
+
299
+ // Trailing days from next month to complete rows (up to 35 or 42)
300
+ const totalSlots = grid.length > 35 ? 42 : 35;
301
+ const remaining = totalSlots - grid.length;
302
+ for (let dayNum = 1; dayNum <= remaining; dayNum++) {
303
+ const d = new Date(viewYear, viewMonth + 1, dayNum);
304
+ const str = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(dayNum).padStart(2, '0')}`;
305
+ grid.push({
306
+ day: dayNum,
307
+ date: d,
308
+ dateString: str,
309
+ isCurrentMonth: false,
310
+ isToday: str === todayStr,
311
+ isSelected: false,
312
+ isRangeStart: false,
313
+ isRangeEnd: false,
314
+ isInRange: false,
315
+ isDisabled: true,
316
+ });
317
+ }
318
+
319
+ return grid;
320
+ }, [
321
+ viewYear,
322
+ viewMonth,
323
+ firstDay,
324
+ selectedDate,
325
+ rangeMode,
326
+ activeStartDate,
327
+ activeEndDate,
328
+ minDateObj,
329
+ maxDateObj,
330
+ disabledDates,
331
+ disabledWeekdays,
332
+ markedDates,
333
+ ]);
334
+
335
+ // Handle day click
336
+ const handleDayPress = useCallback(
337
+ (item: CalendarDay) => {
338
+ if (item.isDisabled || !item.isCurrentMonth) {
339
+ return;
340
+ }
341
+
342
+ if (rangeMode) {
343
+ if (!activeStartDate || (activeStartDate && activeEndDate)) {
344
+ // Starting a new range
345
+ setRangeStart(item.date);
346
+ setRangeEnd(null);
347
+ onRangeChange?.({ startDate: item.date, endDate: null });
348
+ } else if (activeStartDate && !activeEndDate) {
349
+ // Selecting the second date of range
350
+ if (item.date < activeStartDate) {
351
+ // Clicked date is earlier, make it start
352
+ setRangeStart(item.date);
353
+ setRangeEnd(activeStartDate);
354
+ onRangeChange?.({ startDate: item.date, endDate: activeStartDate });
355
+ } else {
356
+ setRangeEnd(item.date);
357
+ onRangeChange?.({ startDate: activeStartDate, endDate: item.date });
358
+ }
359
+ }
360
+ } else {
361
+ effectiveOnChange?.(item.date);
362
+ }
363
+ },
364
+ [
365
+ rangeMode,
366
+ activeStartDate,
367
+ activeEndDate,
368
+ onRangeChange,
369
+ effectiveOnChange,
370
+ ]
371
+ );
372
+
373
+ const monthLabel = `${localeData.months[viewMonth]} ${viewYear}`;
374
+
375
+ return (
376
+ <View
377
+ testID={testID}
378
+ style={[
379
+ styles.container,
380
+ { backgroundColor: resolvedTheme.colors.background },
381
+ ]}
382
+ >
383
+ {/* Month Navigation Header */}
384
+ <View
385
+ style={[
386
+ styles.headerRow,
387
+ { flexDirection: localeData.isRTL ? 'row-reverse' : 'row' },
388
+ ]}
389
+ >
390
+ <TouchableOpacity
391
+ accessibilityRole="button"
392
+ accessibilityLabel="Previous Month"
393
+ onPress={goToPrevMonth}
394
+ style={styles.navButton}
395
+ >
396
+ <Text
397
+ style={[styles.navArrow, { color: resolvedTheme.colors.primary }]}
398
+ >
399
+ {localeData.isRTL ? '›' : '‹'}
400
+ </Text>
401
+ </TouchableOpacity>
402
+
403
+ <Text
404
+ style={[
405
+ styles.monthTitle,
406
+ {
407
+ color: resolvedTheme.colors.text,
408
+ fontSize: resolvedTheme.typography.fontSizeLarge,
409
+ fontWeight: resolvedTheme.typography.fontWeightBold,
410
+ },
411
+ ]}
412
+ >
413
+ {monthLabel}
414
+ </Text>
415
+
416
+ <TouchableOpacity
417
+ accessibilityRole="button"
418
+ accessibilityLabel="Next Month"
419
+ onPress={goToNextMonth}
420
+ style={styles.navButton}
421
+ >
422
+ <Text
423
+ style={[styles.navArrow, { color: resolvedTheme.colors.primary }]}
424
+ >
425
+ {localeData.isRTL ? '‹' : '›'}
426
+ </Text>
427
+ </TouchableOpacity>
428
+ </View>
429
+
430
+ {/* Weekday Row */}
431
+ <View
432
+ style={[
433
+ styles.weekdaysRow,
434
+ { flexDirection: localeData.isRTL ? 'row-reverse' : 'row' },
435
+ ]}
436
+ >
437
+ {weekdayNames.map((wk, idx) => (
438
+ <View key={`wk-${idx}`} style={styles.weekdayCell}>
439
+ <Text
440
+ style={[
441
+ styles.weekdayText,
442
+ {
443
+ color: resolvedTheme.colors.textMuted,
444
+ fontSize: resolvedTheme.typography.fontSizeSmall,
445
+ fontWeight: resolvedTheme.typography.fontWeightMedium,
446
+ },
447
+ ]}
448
+ >
449
+ {wk}
450
+ </Text>
451
+ </View>
452
+ ))}
453
+ </View>
454
+
455
+ {/* Days Grid */}
456
+ <View
457
+ style={[
458
+ styles.daysGrid,
459
+ { flexDirection: localeData.isRTL ? 'row-reverse' : 'row' },
460
+ ]}
461
+ >
462
+ {daysGrid.map((item, index) => {
463
+ const isSelected = item.isSelected;
464
+ const isInRange = item.isInRange;
465
+ const isToday = item.isToday;
466
+ const isDisabled = item.isDisabled;
467
+ const notCurrent = !item.isCurrentMonth;
468
+
469
+ let dayBg = 'transparent';
470
+ let textColor = resolvedTheme.colors.text;
471
+
472
+ if (notCurrent) {
473
+ textColor = resolvedTheme.colors.disabledText;
474
+ } else if (isDisabled) {
475
+ textColor = resolvedTheme.colors.disabledText;
476
+ } else if (isSelected) {
477
+ dayBg = resolvedTheme.colors.selected;
478
+ textColor = resolvedTheme.colors.selectedText;
479
+ } else if (isInRange) {
480
+ dayBg = resolvedTheme.colors.rangeHighlight;
481
+ textColor = resolvedTheme.colors.rangeHighlightText;
482
+ } else if (isToday) {
483
+ textColor = resolvedTheme.colors.primary;
484
+ }
485
+
486
+ return (
487
+ <TouchableOpacity
488
+ key={`${item.dateString}-${index}`}
489
+ accessibilityRole="button"
490
+ accessibilityLabel={`${item.day} ${localeData.months[viewMonth]} ${viewYear}`}
491
+ accessibilityState={{
492
+ selected: isSelected,
493
+ disabled: isDisabled || notCurrent,
494
+ }}
495
+ disabled={isDisabled || notCurrent}
496
+ onPress={() => handleDayPress(item)}
497
+ style={[
498
+ styles.dayCell,
499
+ isInRange && {
500
+ backgroundColor: resolvedTheme.colors.rangeHighlight,
501
+ borderRadius: 0,
502
+ },
503
+ ]}
504
+ >
505
+ <View
506
+ style={[
507
+ styles.dayBadge,
508
+ isSelected && {
509
+ backgroundColor: dayBg,
510
+ borderRadius: resolvedTheme.borderRadius.full,
511
+ },
512
+ isToday &&
513
+ !isSelected && {
514
+ borderWidth: 1,
515
+ borderColor: resolvedTheme.colors.primary,
516
+ borderRadius: resolvedTheme.borderRadius.full,
517
+ },
518
+ ]}
519
+ >
520
+ <Text
521
+ style={[
522
+ styles.dayText,
523
+ {
524
+ color: textColor,
525
+ fontSize: resolvedTheme.typography.fontSizeMedium,
526
+ fontWeight:
527
+ isSelected || isToday
528
+ ? resolvedTheme.typography.fontWeightBold
529
+ : resolvedTheme.typography.fontWeightRegular,
530
+ },
531
+ ]}
532
+ >
533
+ {item.day}
534
+ </Text>
535
+
536
+ {/* Dot Marker */}
537
+ {item.markedConfig?.marked && (
538
+ <View
539
+ style={[
540
+ styles.dotMarker,
541
+ {
542
+ backgroundColor:
543
+ item.markedConfig.dotColor ||
544
+ (isSelected
545
+ ? resolvedTheme.colors.selectedText
546
+ : resolvedTheme.colors.primary),
547
+ },
548
+ ]}
549
+ />
550
+ )}
551
+ </View>
552
+ </TouchableOpacity>
553
+ );
554
+ })}
555
+ </View>
556
+ </View>
557
+ );
558
+ };
559
+
560
+ const styles = StyleSheet.create({
561
+ container: {
562
+ padding: 12,
563
+ },
564
+ headerRow: {
565
+ alignItems: 'center',
566
+ justifyContent: 'space-between',
567
+ marginBottom: 12,
568
+ paddingHorizontal: 8,
569
+ },
570
+ monthTitle: {
571
+ textAlign: 'center',
572
+ },
573
+ navButton: {
574
+ width: 38,
575
+ height: 38,
576
+ justifyContent: 'center',
577
+ alignItems: 'center',
578
+ },
579
+ navArrow: {
580
+ fontSize: 26,
581
+ lineHeight: 28,
582
+ },
583
+ weekdaysRow: {
584
+ justifyContent: 'space-around',
585
+ marginBottom: 8,
586
+ borderBottomWidth: StyleSheet.hairlineWidth,
587
+ borderBottomColor: '#E2E8F0',
588
+ paddingBottom: 6,
589
+ },
590
+ weekdayCell: {
591
+ flex: 1,
592
+ alignItems: 'center',
593
+ },
594
+ weekdayText: {
595
+ textAlign: 'center',
596
+ },
597
+ daysGrid: {
598
+ flexWrap: 'wrap',
599
+ justifyContent: 'flex-start',
600
+ },
601
+ dayCell: {
602
+ width: `${100 / 7}%`,
603
+ height: 44,
604
+ justifyContent: 'center',
605
+ alignItems: 'center',
606
+ },
607
+ dayBadge: {
608
+ width: 36,
609
+ height: 36,
610
+ justifyContent: 'center',
611
+ alignItems: 'center',
612
+ },
613
+ dayText: {
614
+ textAlign: 'center',
615
+ },
616
+ dotMarker: {
617
+ width: 4,
618
+ height: 4,
619
+ borderRadius: 2,
620
+ position: 'absolute',
621
+ bottom: 3,
622
+ },
623
+ });