@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,137 @@
1
+ import React from 'react';
2
+ import {
3
+ Modal as RNModal,
4
+ View,
5
+ ScrollView,
6
+ StyleSheet,
7
+ StyleProp,
8
+ ViewStyle,
9
+ TouchableWithoutFeedback,
10
+ KeyboardAvoidingView,
11
+ Platform,
12
+ } from 'react-native';
13
+ import type { DatePickerTheme } from '../../types';
14
+
15
+ export interface ModalProps {
16
+ visible: boolean;
17
+ onClose: () => void;
18
+ children: React.ReactNode;
19
+ theme: DatePickerTheme;
20
+ contentStyle?: StyleProp<ViewStyle>;
21
+ backdropOpacity?: number;
22
+ }
23
+
24
+ export const Modal: React.FC<ModalProps> = ({
25
+ visible,
26
+ onClose,
27
+ children,
28
+ theme,
29
+ contentStyle,
30
+ backdropOpacity = 0.5,
31
+ }) => {
32
+ return (
33
+ <RNModal
34
+ visible={visible}
35
+ transparent
36
+ animationType="fade"
37
+ onRequestClose={onClose}
38
+ statusBarTranslucent
39
+ >
40
+ <View style={styles.backdrop}>
41
+ {/* Backdrop touchable overlay to close when tapped outside */}
42
+ <TouchableWithoutFeedback
43
+ onPress={onClose}
44
+ accessibilityRole="button"
45
+ accessibilityLabel="Close modal"
46
+ >
47
+ <View
48
+ style={[
49
+ StyleSheet.absoluteFillObject,
50
+ { backgroundColor: `rgba(0, 0, 0, ${backdropOpacity})` },
51
+ ]}
52
+ />
53
+ </TouchableWithoutFeedback>
54
+
55
+ {/* Modal content dialog */}
56
+ <KeyboardAvoidingView
57
+ behavior={Platform.OS === 'ios' ? 'padding' : undefined}
58
+ style={styles.keyboardAvoid}
59
+ pointerEvents="box-none"
60
+ >
61
+ <View
62
+ style={[
63
+ styles.card,
64
+ {
65
+ backgroundColor: theme.cardColor || theme.backgroundColor,
66
+ borderRadius: Math.max(theme.borderRadius ?? 20, 24),
67
+ borderColor: theme.borderColor,
68
+ },
69
+ contentStyle,
70
+ ]}
71
+ >
72
+ {/* Top Drag / Sheet Handle Indicator */}
73
+ <View
74
+ style={[
75
+ styles.handleIndicator,
76
+ { backgroundColor: theme.borderColor },
77
+ ]}
78
+ />
79
+
80
+ {/* Scrollable Container to prevent overflow on small screens */}
81
+ <ScrollView
82
+ bounces={false}
83
+ showsVerticalScrollIndicator={false}
84
+ nestedScrollEnabled={true}
85
+ keyboardShouldPersistTaps="handled"
86
+ contentContainerStyle={styles.scrollContent}
87
+ >
88
+ {children}
89
+ </ScrollView>
90
+ </View>
91
+ </KeyboardAvoidingView>
92
+ </View>
93
+ </RNModal>
94
+ );
95
+ };
96
+
97
+ const styles = StyleSheet.create({
98
+ backdrop: {
99
+ flex: 1,
100
+ justifyContent: 'center',
101
+ alignItems: 'center',
102
+ padding: 12,
103
+ },
104
+ keyboardAvoid: {
105
+ width: '100%',
106
+ alignItems: 'center',
107
+ justifyContent: 'center',
108
+ },
109
+ card: {
110
+ width: '95%',
111
+ maxWidth: 440,
112
+ minHeight: 450,
113
+ maxHeight: '94%',
114
+ borderWidth: 1,
115
+ shadowColor: '#000',
116
+ shadowOffset: { width: 0, height: 10 },
117
+ shadowOpacity: 0.2,
118
+ shadowRadius: 20,
119
+ elevation: 16,
120
+ overflow: 'hidden',
121
+ },
122
+ handleIndicator: {
123
+ width: 42,
124
+ height: 4.5,
125
+ borderRadius: 3,
126
+ alignSelf: 'center',
127
+ marginTop: 10,
128
+ marginBottom: 8,
129
+ opacity: 0.5,
130
+ },
131
+ scrollContent: {
132
+ flexGrow: 1,
133
+ paddingHorizontal: 12,
134
+ paddingBottom: 14,
135
+ justifyContent: 'space-between',
136
+ },
137
+ });
@@ -0,0 +1,3 @@
1
+ export * from './Button';
2
+ export * from './IconButton';
3
+ export * from './Modal';
@@ -0,0 +1,8 @@
1
+ export * from './common';
2
+ export * from './Calendar';
3
+ export * from './Wheel';
4
+ export * from './Range';
5
+ export * from './Input';
6
+ export * from './ManualDateInput';
7
+ export * from './Time';
8
+ export * from './DatePicker';
@@ -0,0 +1,3 @@
1
+ export * from './useCalendar';
2
+ export * from './useDateRange';
3
+ export * from './useDatePicker';
@@ -0,0 +1,153 @@
1
+ import { useState, useMemo, useCallback } from 'react';
2
+ import type {
3
+ CalendarDayCell,
4
+ DatePickerLocale,
5
+ DisabledDateCheck,
6
+ DateRange,
7
+ } from '../types';
8
+ import {
9
+ buildCalendarGrid,
10
+ getOrderedWeekdays,
11
+ } from '../utils/calendarUtils';
12
+ import {
13
+ addMonths,
14
+ getStartOfMonth,
15
+ getEndOfMonth,
16
+ stripTime,
17
+ } from '../utils/dateUtils';
18
+
19
+ export interface UseCalendarProps {
20
+ initialDate?: Date | null;
21
+ selectedDate?: Date | null;
22
+ range?: DateRange;
23
+ firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
24
+ minimumDate?: Date;
25
+ maximumDate?: Date;
26
+ disabledDates?: (Date | string)[] | DisabledDateCheck;
27
+ disabledWeekdays?: number[];
28
+ locale: DatePickerLocale;
29
+ }
30
+
31
+ export interface UseCalendarReturn {
32
+ currentYear: number;
33
+ currentMonth: number;
34
+ currentMonthName: string;
35
+ days: CalendarDayCell[];
36
+ weekdays: { index: number; name: string; short: string; min: string }[];
37
+ canGoPrevMonth: boolean;
38
+ canGoNextMonth: boolean;
39
+ goToPrevMonth: () => void;
40
+ goToNextMonth: () => void;
41
+ goToToday: () => void;
42
+ setMonth: (monthIndex: number) => void;
43
+ setYear: (year: number) => void;
44
+ jumpToDate: (date: Date) => void;
45
+ }
46
+
47
+ export const useCalendar = ({
48
+ initialDate,
49
+ selectedDate,
50
+ range,
51
+ firstDayOfWeek = 0,
52
+ minimumDate,
53
+ maximumDate,
54
+ disabledDates,
55
+ disabledWeekdays,
56
+ locale,
57
+ }: UseCalendarProps): UseCalendarReturn => {
58
+ const baseDate = initialDate || selectedDate || range?.startDate || new Date();
59
+
60
+ const [viewDate, setViewDate] = useState<Date>(() => getStartOfMonth(baseDate));
61
+
62
+ const currentYear = viewDate.getFullYear();
63
+ const currentMonth = viewDate.getMonth();
64
+
65
+ const currentMonthName = useMemo(() => {
66
+ return locale.months[currentMonth] || '';
67
+ }, [locale.months, currentMonth]);
68
+
69
+ const canGoPrevMonth = useMemo(() => {
70
+ if (!minimumDate) return true;
71
+ const startOfPrevMonth = getEndOfMonth(addMonths(viewDate, -1));
72
+ return stripTime(startOfPrevMonth).getTime() >= stripTime(minimumDate).getTime();
73
+ }, [minimumDate, viewDate]);
74
+
75
+ const canGoNextMonth = useMemo(() => {
76
+ if (!maximumDate) return true;
77
+ const startOfNextMonth = getStartOfMonth(addMonths(viewDate, 1));
78
+ return stripTime(startOfNextMonth).getTime() <= stripTime(maximumDate).getTime();
79
+ }, [maximumDate, viewDate]);
80
+
81
+ const goToPrevMonth = useCallback(() => {
82
+ if (canGoPrevMonth) {
83
+ setViewDate((prev) => addMonths(prev, -1));
84
+ }
85
+ }, [canGoPrevMonth]);
86
+
87
+ const goToNextMonth = useCallback(() => {
88
+ if (canGoNextMonth) {
89
+ setViewDate((prev) => addMonths(prev, 1));
90
+ }
91
+ }, [canGoNextMonth]);
92
+
93
+ const goToToday = useCallback(() => {
94
+ const today = new Date();
95
+ setViewDate(getStartOfMonth(today));
96
+ }, []);
97
+
98
+ const setMonth = useCallback((monthIndex: number) => {
99
+ setViewDate((prev) => new Date(prev.getFullYear(), monthIndex, 1, 0, 0, 0, 0));
100
+ }, []);
101
+
102
+ const setYear = useCallback((year: number) => {
103
+ setViewDate((prev) => new Date(year, prev.getMonth(), 1, 0, 0, 0, 0));
104
+ }, []);
105
+
106
+ const jumpToDate = useCallback((date: Date) => {
107
+ setViewDate(getStartOfMonth(date));
108
+ }, []);
109
+
110
+ const days = useMemo(() => {
111
+ return buildCalendarGrid({
112
+ year: currentYear,
113
+ month: currentMonth,
114
+ firstDayOfWeek,
115
+ selectedDate,
116
+ range,
117
+ minimumDate,
118
+ maximumDate,
119
+ disabledDates,
120
+ disabledWeekdays,
121
+ });
122
+ }, [
123
+ currentYear,
124
+ currentMonth,
125
+ firstDayOfWeek,
126
+ selectedDate,
127
+ range,
128
+ minimumDate,
129
+ maximumDate,
130
+ disabledDates,
131
+ disabledWeekdays,
132
+ ]);
133
+
134
+ const weekdays = useMemo(() => {
135
+ return getOrderedWeekdays(firstDayOfWeek, locale);
136
+ }, [firstDayOfWeek, locale]);
137
+
138
+ return {
139
+ currentYear,
140
+ currentMonth,
141
+ currentMonthName,
142
+ days,
143
+ weekdays,
144
+ canGoPrevMonth,
145
+ canGoNextMonth,
146
+ goToPrevMonth,
147
+ goToNextMonth,
148
+ goToToday,
149
+ setMonth,
150
+ setYear,
151
+ jumpToDate,
152
+ };
153
+ };
@@ -0,0 +1,216 @@
1
+ import { useState, useCallback, useMemo, useEffect } from 'react';
2
+ import type {
3
+ DateFormat,
4
+ DatePickerLocale,
5
+ ValidationResult,
6
+ DisabledDateCheck,
7
+ } from '../types';
8
+ import { formatDate } from '../utils/dateFormatting';
9
+ import { parseDateStrict, formatMaskedInput } from '../utils/dateParsing';
10
+ import { validateDate } from '../utils/dateValidation';
11
+ import { isSameDay } from '../utils/dateUtils';
12
+
13
+ export interface UseDatePickerProps {
14
+ value?: Date | null;
15
+ defaultValue?: Date | null;
16
+ onChange?: (date: Date | null) => void;
17
+ format?: DateFormat;
18
+ locale: DatePickerLocale;
19
+ minimumDate?: Date;
20
+ maximumDate?: Date;
21
+ disabledDates?: (Date | string)[] | DisabledDateCheck;
22
+ disabledWeekdays?: number[];
23
+ allowManualEntry?: boolean;
24
+ defaultManualMode?: boolean;
25
+ }
26
+
27
+ export interface UseDatePickerReturn {
28
+ selectedDate: Date | null;
29
+ manualText: string;
30
+ isManualMode: boolean;
31
+ validationResult: ValidationResult;
32
+ selectDate: (date: Date | null) => void;
33
+ handleManualInputChange: (text: string) => void;
34
+ toggleManualMode: () => void;
35
+ setIsManualMode: (manual: boolean) => void;
36
+ clear: () => void;
37
+ resetValidation: () => void;
38
+ }
39
+
40
+ export const useDatePicker = ({
41
+ value: controlledValue,
42
+ defaultValue = null,
43
+ onChange,
44
+ format = 'DD/MM/YYYY',
45
+ locale,
46
+ minimumDate,
47
+ maximumDate,
48
+ disabledDates,
49
+ disabledWeekdays,
50
+ defaultManualMode = false,
51
+ }: UseDatePickerProps): UseDatePickerReturn => {
52
+ const isControlled = controlledValue !== undefined;
53
+
54
+ const [uncontrolledValue, setUncontrolledValue] = useState<Date | null>(defaultValue);
55
+
56
+ const selectedDate = useMemo<Date | null>(() => {
57
+ return isControlled ? (controlledValue ?? null) : uncontrolledValue;
58
+ }, [isControlled, controlledValue, uncontrolledValue]);
59
+
60
+ const [manualText, setManualText] = useState<string>(() => {
61
+ return selectedDate ? formatDate(selectedDate, format, locale) : '';
62
+ });
63
+
64
+ const [isManualMode, setIsManualMode] = useState<boolean>(Boolean(defaultManualMode));
65
+
66
+ const [validationResult, setValidationResult] = useState<ValidationResult>({
67
+ isValid: true,
68
+ });
69
+
70
+ // Keep manual text in sync when external selectedDate changes
71
+ useEffect(() => {
72
+ if (selectedDate) {
73
+ const currentFormatted = formatDate(selectedDate, format, locale);
74
+ setManualText(currentFormatted);
75
+ setValidationResult({ isValid: true });
76
+ } else {
77
+ setManualText('');
78
+ }
79
+ }, [selectedDate, format, locale]);
80
+
81
+ const selectDate = useCallback(
82
+ (newDate: Date | null) => {
83
+ if (newDate) {
84
+ const validation = validateDate(newDate, {
85
+ minimumDate,
86
+ maximumDate,
87
+ disabledDates,
88
+ disabledWeekdays,
89
+ locale,
90
+ });
91
+
92
+ setValidationResult(validation);
93
+
94
+ if (!validation.isValid) {
95
+ return;
96
+ }
97
+
98
+ const formatted = formatDate(newDate, format, locale);
99
+ setManualText(formatted);
100
+ } else {
101
+ setManualText('');
102
+ setValidationResult({ isValid: true });
103
+ }
104
+
105
+ if (!isControlled) {
106
+ setUncontrolledValue(newDate);
107
+ }
108
+
109
+ if (onChange) {
110
+ onChange(newDate);
111
+ }
112
+ },
113
+ [
114
+ isControlled,
115
+ onChange,
116
+ format,
117
+ locale,
118
+ minimumDate,
119
+ maximumDate,
120
+ disabledDates,
121
+ disabledWeekdays,
122
+ ]
123
+ );
124
+
125
+ const handleManualInputChange = useCallback(
126
+ (text: string) => {
127
+ const masked = formatMaskedInput(text, format);
128
+ setManualText(masked);
129
+
130
+ // If user completely cleared the input
131
+ if (!masked.trim()) {
132
+ setValidationResult({ isValid: true });
133
+ if (!isControlled) {
134
+ setUncontrolledValue(null);
135
+ }
136
+ if (onChange) {
137
+ onChange(null);
138
+ }
139
+ return;
140
+ }
141
+
142
+ // Check if user has entered the expected length of characters for a full date
143
+ // DD/MM/YYYY is 10 chars, YYYY-MM-DD is 10 chars
144
+ const isCompleteLength = masked.length >= 10;
145
+
146
+ if (isCompleteLength) {
147
+ const parsed = parseDateStrict(masked, format, locale);
148
+ if (!parsed.validation.isValid || !parsed.date) {
149
+ setValidationResult(parsed.validation);
150
+ return;
151
+ }
152
+
153
+ // Validate date boundaries and constraints
154
+ const constraintValidation = validateDate(parsed.date, {
155
+ minimumDate,
156
+ maximumDate,
157
+ disabledDates,
158
+ disabledWeekdays,
159
+ locale,
160
+ });
161
+
162
+ setValidationResult(constraintValidation);
163
+
164
+ if (constraintValidation.isValid) {
165
+ if (!isSameDay(selectedDate, parsed.date)) {
166
+ if (!isControlled) {
167
+ setUncontrolledValue(parsed.date);
168
+ }
169
+ if (onChange) {
170
+ onChange(parsed.date);
171
+ }
172
+ }
173
+ }
174
+ } else {
175
+ // While typing incomplete date, don't show red error yet unless characters exceed limits
176
+ setValidationResult({ isValid: true });
177
+ }
178
+ },
179
+ [
180
+ format,
181
+ locale,
182
+ isControlled,
183
+ onChange,
184
+ selectedDate,
185
+ minimumDate,
186
+ maximumDate,
187
+ disabledDates,
188
+ disabledWeekdays,
189
+ ]
190
+ );
191
+
192
+ const toggleManualMode = useCallback(() => {
193
+ setIsManualMode((prev) => !prev);
194
+ }, []);
195
+
196
+ const clear = useCallback(() => {
197
+ selectDate(null);
198
+ }, [selectDate]);
199
+
200
+ const resetValidation = useCallback(() => {
201
+ setValidationResult({ isValid: true });
202
+ }, []);
203
+
204
+ return {
205
+ selectedDate,
206
+ manualText,
207
+ isManualMode,
208
+ validationResult,
209
+ selectDate,
210
+ handleManualInputChange,
211
+ toggleManualMode,
212
+ setIsManualMode,
213
+ clear,
214
+ resetValidation,
215
+ };
216
+ };
@@ -0,0 +1,135 @@
1
+ import { useState, useCallback, useMemo } from 'react';
2
+ import type {
3
+ DateRange,
4
+ DatePickerLocale,
5
+ ValidationResult,
6
+ DisabledDateCheck,
7
+ } from '../types';
8
+ import { isBeforeDay } from '../utils/dateUtils';
9
+ import { validateDateRange } from '../utils/dateValidation';
10
+
11
+ export interface UseDateRangeProps {
12
+ startDate?: Date | null;
13
+ endDate?: Date | null;
14
+ defaultStartDate?: Date | null;
15
+ defaultEndDate?: Date | null;
16
+ onRangeChange?: (range: DateRange) => void;
17
+ maxRangeDays?: number;
18
+ minimumDate?: Date;
19
+ maximumDate?: Date;
20
+ disabledDates?: (Date | string)[] | DisabledDateCheck;
21
+ disabledWeekdays?: number[];
22
+ locale: DatePickerLocale;
23
+ }
24
+
25
+ export interface UseDateRangeReturn {
26
+ range: DateRange;
27
+ selectDate: (date: Date) => void;
28
+ clearRange: () => void;
29
+ validationResult: ValidationResult;
30
+ isSelectingEndDate: boolean;
31
+ }
32
+
33
+ export const useDateRange = ({
34
+ startDate: controlledStartDate,
35
+ endDate: controlledEndDate,
36
+ defaultStartDate = null,
37
+ defaultEndDate = null,
38
+ onRangeChange,
39
+ maxRangeDays,
40
+ minimumDate,
41
+ maximumDate,
42
+ disabledDates,
43
+ disabledWeekdays,
44
+ locale,
45
+ }: UseDateRangeProps): UseDateRangeReturn => {
46
+ const isControlled = controlledStartDate !== undefined;
47
+
48
+ const [uncontrolledRange, setUncontrolledRange] = useState<DateRange>({
49
+ startDate: defaultStartDate,
50
+ endDate: defaultEndDate,
51
+ });
52
+
53
+ const range = useMemo<DateRange>(() => {
54
+ return isControlled
55
+ ? {
56
+ startDate: controlledStartDate ?? null,
57
+ endDate: controlledEndDate ?? null,
58
+ }
59
+ : uncontrolledRange;
60
+ }, [isControlled, controlledStartDate, controlledEndDate, uncontrolledRange]);
61
+
62
+ const [validationResult, setValidationResult] = useState<ValidationResult>({
63
+ isValid: true,
64
+ });
65
+
66
+ const isSelectingEndDate = useMemo(() => {
67
+ return Boolean(range.startDate && !range.endDate);
68
+ }, [range.startDate, range.endDate]);
69
+
70
+ const updateRange = useCallback(
71
+ (newRange: DateRange) => {
72
+ const validation = validateDateRange(newRange.startDate, newRange.endDate, {
73
+ maxRangeDays,
74
+ minimumDate,
75
+ maximumDate,
76
+ disabledDates,
77
+ disabledWeekdays,
78
+ locale,
79
+ });
80
+
81
+ setValidationResult(validation);
82
+
83
+ if (!isControlled) {
84
+ setUncontrolledRange(newRange);
85
+ }
86
+
87
+ if (onRangeChange && validation.isValid) {
88
+ onRangeChange(newRange);
89
+ }
90
+ },
91
+ [
92
+ isControlled,
93
+ onRangeChange,
94
+ maxRangeDays,
95
+ minimumDate,
96
+ maximumDate,
97
+ disabledDates,
98
+ disabledWeekdays,
99
+ locale,
100
+ ]
101
+ );
102
+
103
+ const selectDate = useCallback(
104
+ (date: Date) => {
105
+ // 1. If no start date or both already selected, begin new range
106
+ if (!range.startDate || (range.startDate && range.endDate)) {
107
+ updateRange({ startDate: date, endDate: null });
108
+ return;
109
+ }
110
+
111
+ // 2. We have a start date and are selecting end date
112
+ if (range.startDate && !range.endDate) {
113
+ // If clicked date is before start date, restart selection with this new date as start
114
+ if (isBeforeDay(date, range.startDate)) {
115
+ updateRange({ startDate: date, endDate: null });
116
+ } else {
117
+ updateRange({ startDate: range.startDate, endDate: date });
118
+ }
119
+ }
120
+ },
121
+ [range.startDate, range.endDate, updateRange]
122
+ );
123
+
124
+ const clearRange = useCallback(() => {
125
+ updateRange({ startDate: null, endDate: null });
126
+ }, [updateRange]);
127
+
128
+ return {
129
+ range,
130
+ selectDate,
131
+ clearRange,
132
+ validationResult,
133
+ isSelectingEndDate,
134
+ };
135
+ };
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ // Components
2
+ export * from './components';
3
+
4
+ // Hooks
5
+ export * from './hooks';
6
+
7
+ // Utils
8
+ export * from './utils';
9
+
10
+ // Themes
11
+ export * from './themes';
12
+
13
+ // Localization
14
+ export * from './localization';
15
+
16
+ // Types
17
+ export * from './types';