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