@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.
- package/CHANGELOG.md +35 -0
- package/LICENSE +5 -0
- package/README.md +942 -2
- package/assets/screenshots/calendar-picker-blue.jpg +0 -0
- package/assets/screenshots/calendar-picker.jpg +0 -0
- package/assets/screenshots/datetime-picker-date.jpg +0 -0
- package/assets/screenshots/datetime-picker-time-blue.jpg +0 -0
- package/assets/screenshots/input-modal-picker.jpg +0 -0
- package/assets/screenshots/manual-entry-single.jpg +0 -0
- package/assets/screenshots/manual-entry-split.jpg +0 -0
- package/assets/screenshots/month-year-selector-modal.jpg +0 -0
- package/assets/screenshots/range-picker.jpg +0 -0
- package/assets/screenshots/time-12h-wheel.jpg +0 -0
- package/assets/screenshots/time-24h-military-blue.jpg +0 -0
- package/assets/screenshots/wheel-date-picker.jpg +0 -0
- package/lib/components/Calendar/Calendar.d.ts +35 -0
- package/lib/components/Calendar/Calendar.d.ts.map +1 -0
- package/lib/components/Calendar/Calendar.js +126 -0
- package/lib/components/Calendar/Calendar.js.map +1 -0
- package/lib/components/Calendar/CalendarGrid.d.ts +11 -0
- package/lib/components/Calendar/CalendarGrid.d.ts.map +1 -0
- package/lib/components/Calendar/CalendarGrid.js +22 -0
- package/lib/components/Calendar/CalendarGrid.js.map +1 -0
- package/lib/components/Calendar/CalendarHeader.d.ts +23 -0
- package/lib/components/Calendar/CalendarHeader.d.ts.map +1 -0
- package/lib/components/Calendar/CalendarHeader.js +62 -0
- package/lib/components/Calendar/CalendarHeader.js.map +1 -0
- package/lib/components/Calendar/DateCell.d.ts +11 -0
- package/lib/components/Calendar/DateCell.d.ts.map +1 -0
- package/lib/components/Calendar/DateCell.js +71 -0
- package/lib/components/Calendar/DateCell.js.map +1 -0
- package/lib/components/Calendar/MonthYearSelectorModal.d.ts +17 -0
- package/lib/components/Calendar/MonthYearSelectorModal.d.ts.map +1 -0
- package/lib/components/Calendar/MonthYearSelectorModal.js +253 -0
- package/lib/components/Calendar/MonthYearSelectorModal.js.map +1 -0
- package/lib/components/Calendar/WeekDays.d.ts +13 -0
- package/lib/components/Calendar/WeekDays.d.ts.map +1 -0
- package/lib/components/Calendar/WeekDays.js +34 -0
- package/lib/components/Calendar/WeekDays.js.map +1 -0
- package/lib/components/Calendar/index.d.ts +7 -0
- package/lib/components/Calendar/index.d.ts.map +1 -0
- package/lib/components/Calendar/index.js +23 -0
- package/lib/components/Calendar/index.js.map +1 -0
- package/lib/components/DatePicker.d.ts +4 -0
- package/lib/components/DatePicker.d.ts.map +1 -0
- package/lib/components/DatePicker.js +498 -0
- package/lib/components/DatePicker.js.map +1 -0
- package/lib/components/Input/CalendarPopup.d.ts +26 -0
- package/lib/components/Input/CalendarPopup.d.ts.map +1 -0
- package/lib/components/Input/CalendarPopup.js +60 -0
- package/lib/components/Input/CalendarPopup.js.map +1 -0
- package/lib/components/Input/DateInput.d.ts +29 -0
- package/lib/components/Input/DateInput.d.ts.map +1 -0
- package/lib/components/Input/DateInput.js +110 -0
- package/lib/components/Input/DateInput.js.map +1 -0
- package/lib/components/Input/index.d.ts +3 -0
- package/lib/components/Input/index.d.ts.map +1 -0
- package/lib/components/Input/index.js +19 -0
- package/lib/components/Input/index.js.map +1 -0
- package/lib/components/ManualDateInput/DateInputField.d.ts +19 -0
- package/lib/components/ManualDateInput/DateInputField.d.ts.map +1 -0
- package/lib/components/ManualDateInput/DateInputField.js +345 -0
- package/lib/components/ManualDateInput/DateInputField.js.map +1 -0
- package/lib/components/ManualDateInput/DateValidationMessage.d.ts +8 -0
- package/lib/components/ManualDateInput/DateValidationMessage.d.ts.map +1 -0
- package/lib/components/ManualDateInput/DateValidationMessage.js +45 -0
- package/lib/components/ManualDateInput/DateValidationMessage.js.map +1 -0
- package/lib/components/ManualDateInput/ManualDateInput.d.ts +19 -0
- package/lib/components/ManualDateInput/ManualDateInput.d.ts.map +1 -0
- package/lib/components/ManualDateInput/ManualDateInput.js +18 -0
- package/lib/components/ManualDateInput/ManualDateInput.js.map +1 -0
- package/lib/components/ManualDateInput/index.d.ts +4 -0
- package/lib/components/ManualDateInput/index.d.ts.map +1 -0
- package/lib/components/ManualDateInput/index.js +20 -0
- package/lib/components/ManualDateInput/index.js.map +1 -0
- package/lib/components/Range/RangeDateCell.d.ts +11 -0
- package/lib/components/Range/RangeDateCell.d.ts.map +1 -0
- package/lib/components/Range/RangeDateCell.js +107 -0
- package/lib/components/Range/RangeDateCell.js.map +1 -0
- package/lib/components/Range/RangePicker.d.ts +29 -0
- package/lib/components/Range/RangePicker.d.ts.map +1 -0
- package/lib/components/Range/RangePicker.js +261 -0
- package/lib/components/Range/RangePicker.js.map +1 -0
- package/lib/components/Range/index.d.ts +3 -0
- package/lib/components/Range/index.d.ts.map +1 -0
- package/lib/components/Range/index.js +19 -0
- package/lib/components/Range/index.js.map +1 -0
- package/lib/components/Time/ClockDial.d.ts +15 -0
- package/lib/components/Time/ClockDial.d.ts.map +1 -0
- package/lib/components/Time/ClockDial.js +347 -0
- package/lib/components/Time/ClockDial.js.map +1 -0
- package/lib/components/Time/DateTimePicker.d.ts +31 -0
- package/lib/components/Time/DateTimePicker.d.ts.map +1 -0
- package/lib/components/Time/DateTimePicker.js +197 -0
- package/lib/components/Time/DateTimePicker.js.map +1 -0
- package/lib/components/Time/TimePicker.d.ts +31 -0
- package/lib/components/Time/TimePicker.d.ts.map +1 -0
- package/lib/components/Time/TimePicker.js +550 -0
- package/lib/components/Time/TimePicker.js.map +1 -0
- package/lib/components/Time/WheelTimePicker.d.ts +27 -0
- package/lib/components/Time/WheelTimePicker.d.ts.map +1 -0
- package/lib/components/Time/WheelTimePicker.js +203 -0
- package/lib/components/Time/WheelTimePicker.js.map +1 -0
- package/lib/components/Time/index.d.ts +5 -0
- package/lib/components/Time/index.d.ts.map +1 -0
- package/lib/components/Time/index.js +21 -0
- package/lib/components/Time/index.js.map +1 -0
- package/lib/components/Wheel/WheelColumn.d.ts +17 -0
- package/lib/components/Wheel/WheelColumn.d.ts.map +1 -0
- package/lib/components/Wheel/WheelColumn.js +192 -0
- package/lib/components/Wheel/WheelColumn.js.map +1 -0
- package/lib/components/Wheel/WheelPicker.d.ts +26 -0
- package/lib/components/Wheel/WheelPicker.d.ts.map +1 -0
- package/lib/components/Wheel/WheelPicker.js +123 -0
- package/lib/components/Wheel/WheelPicker.js.map +1 -0
- package/lib/components/Wheel/index.d.ts +3 -0
- package/lib/components/Wheel/index.d.ts.map +1 -0
- package/lib/components/Wheel/index.js +19 -0
- package/lib/components/Wheel/index.js.map +1 -0
- package/lib/components/common/Button.d.ts +17 -0
- package/lib/components/common/Button.d.ts.map +1 -0
- package/lib/components/common/Button.js +77 -0
- package/lib/components/common/Button.js.map +1 -0
- package/lib/components/common/IconButton.d.ts +14 -0
- package/lib/components/common/IconButton.d.ts.map +1 -0
- package/lib/components/common/IconButton.js +150 -0
- package/lib/components/common/IconButton.js.map +1 -0
- package/lib/components/common/Modal.d.ts +13 -0
- package/lib/components/common/Modal.d.ts.map +1 -0
- package/lib/components/common/Modal.js +65 -0
- package/lib/components/common/Modal.js.map +1 -0
- package/lib/components/common/index.d.ts +4 -0
- package/lib/components/common/index.d.ts.map +1 -0
- package/lib/components/common/index.js +20 -0
- package/lib/components/common/index.js.map +1 -0
- package/lib/components/index.d.ts +9 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +25 -0
- package/lib/components/index.js.map +1 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/index.js +20 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useCalendar.d.ts +34 -0
- package/lib/hooks/useCalendar.d.ts.map +1 -0
- package/lib/hooks/useCalendar.js +93 -0
- package/lib/hooks/useCalendar.js.map +1 -0
- package/lib/hooks/useDatePicker.d.ts +28 -0
- package/lib/hooks/useDatePicker.d.ts.map +1 -0
- package/lib/hooks/useDatePicker.js +150 -0
- package/lib/hooks/useDatePicker.js.map +1 -0
- package/lib/hooks/useDateRange.d.ts +23 -0
- package/lib/hooks/useDateRange.d.ts.map +1 -0
- package/lib/hooks/useDateRange.js +82 -0
- package/lib/hooks/useDateRange.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +29 -0
- package/lib/index.js.map +1 -0
- package/lib/localization/en.d.ts +3 -0
- package/lib/localization/en.d.ts.map +1 -0
- package/lib/localization/en.js +80 -0
- package/lib/localization/en.js.map +1 -0
- package/lib/localization/gu.d.ts +3 -0
- package/lib/localization/gu.d.ts.map +1 -0
- package/lib/localization/gu.js +80 -0
- package/lib/localization/gu.js.map +1 -0
- package/lib/localization/hi.d.ts +3 -0
- package/lib/localization/hi.d.ts.map +1 -0
- package/lib/localization/hi.js +80 -0
- package/lib/localization/hi.js.map +1 -0
- package/lib/localization/index.d.ts +8 -0
- package/lib/localization/index.d.ts.map +1 -0
- package/lib/localization/index.js +32 -0
- package/lib/localization/index.js.map +1 -0
- package/lib/themes/dark.d.ts +3 -0
- package/lib/themes/dark.d.ts.map +1 -0
- package/lib/themes/dark.js +30 -0
- package/lib/themes/dark.js.map +1 -0
- package/lib/themes/index.d.ts +16 -0
- package/lib/themes/index.d.ts.map +1 -0
- package/lib/themes/index.js +56 -0
- package/lib/themes/index.js.map +1 -0
- package/lib/themes/light.d.ts +3 -0
- package/lib/themes/light.d.ts.map +1 -0
- package/lib/themes/light.js +30 -0
- package/lib/themes/light.js.map +1 -0
- package/lib/types/index.d.ts +344 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/lib/utils/calendarUtils.d.ts +27 -0
- package/lib/utils/calendarUtils.d.ts.map +1 -0
- package/lib/utils/calendarUtils.js +108 -0
- package/lib/utils/calendarUtils.js.map +1 -0
- package/lib/utils/dateFormatting.d.ts +29 -0
- package/lib/utils/dateFormatting.d.ts.map +1 -0
- package/lib/utils/dateFormatting.js +114 -0
- package/lib/utils/dateFormatting.js.map +1 -0
- package/lib/utils/dateParsing.d.ts +23 -0
- package/lib/utils/dateParsing.d.ts.map +1 -0
- package/lib/utils/dateParsing.js +289 -0
- package/lib/utils/dateParsing.js.map +1 -0
- package/lib/utils/dateUtils.d.ts +20 -0
- package/lib/utils/dateUtils.d.ts.map +1 -0
- package/lib/utils/dateUtils.js +115 -0
- package/lib/utils/dateUtils.js.map +1 -0
- package/lib/utils/dateValidation.d.ts +36 -0
- package/lib/utils/dateValidation.d.ts.map +1 -0
- package/lib/utils/dateValidation.js +196 -0
- package/lib/utils/dateValidation.js.map +1 -0
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +23 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/timeUtils.d.ts +78 -0
- package/lib/utils/timeUtils.d.ts.map +1 -0
- package/lib/utils/timeUtils.js +335 -0
- package/lib/utils/timeUtils.js.map +1 -0
- package/package.json +92 -3
- package/src/components/Calendar/Calendar.tsx +314 -0
- package/src/components/Calendar/CalendarGrid.tsx +47 -0
- package/src/components/Calendar/CalendarHeader.tsx +176 -0
- package/src/components/Calendar/DateCell.tsx +118 -0
- package/src/components/Calendar/MonthYearSelectorModal.tsx +407 -0
- package/src/components/Calendar/WeekDays.tsx +49 -0
- package/src/components/Calendar/index.ts +6 -0
- package/src/components/DatePicker.tsx +834 -0
- package/src/components/Input/CalendarPopup.tsx +168 -0
- package/src/components/Input/DateInput.tsx +259 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/ManualDateInput/DateInputField.tsx +493 -0
- package/src/components/ManualDateInput/DateValidationMessage.tsx +65 -0
- package/src/components/ManualDateInput/ManualDateInput.tsx +66 -0
- package/src/components/ManualDateInput/index.ts +3 -0
- package/src/components/Range/RangeDateCell.tsx +174 -0
- package/src/components/Range/RangePicker.tsx +484 -0
- package/src/components/Range/index.ts +2 -0
- package/src/components/Time/ClockDial.tsx +450 -0
- package/src/components/Time/DateTimePicker.tsx +395 -0
- package/src/components/Time/TimePicker.tsx +899 -0
- package/src/components/Time/WheelTimePicker.tsx +356 -0
- package/src/components/Time/index.ts +4 -0
- package/src/components/Wheel/WheelColumn.tsx +300 -0
- package/src/components/Wheel/WheelPicker.tsx +265 -0
- package/src/components/Wheel/index.ts +2 -0
- package/src/components/common/Button.tsx +125 -0
- package/src/components/common/IconButton.tsx +237 -0
- package/src/components/common/Modal.tsx +137 -0
- package/src/components/common/index.ts +3 -0
- package/src/components/index.ts +8 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useCalendar.ts +153 -0
- package/src/hooks/useDatePicker.ts +216 -0
- package/src/hooks/useDateRange.ts +135 -0
- package/src/index.ts +17 -0
- package/src/localization/en.ts +78 -0
- package/src/localization/gu.ts +78 -0
- package/src/localization/hi.ts +78 -0
- package/src/localization/index.ts +31 -0
- package/src/themes/dark.ts +28 -0
- package/src/themes/index.ts +73 -0
- package/src/themes/light.ts +28 -0
- package/src/types/index.ts +452 -0
- package/src/utils/calendarUtils.ts +152 -0
- package/src/utils/dateFormatting.ts +125 -0
- package/src/utils/dateParsing.ts +335 -0
- package/src/utils/dateUtils.ts +117 -0
- package/src/utils/dateValidation.ts +276 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/timeUtils.ts +416 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
DatePickerTheme,
|
|
5
|
+
DatePickerLocale,
|
|
6
|
+
DateFormat,
|
|
7
|
+
DisabledDateCheck,
|
|
8
|
+
ValidationResult,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
import { useCalendar } from '../../hooks/useCalendar';
|
|
11
|
+
import { CalendarHeader } from './CalendarHeader';
|
|
12
|
+
import { WeekDays } from './WeekDays';
|
|
13
|
+
import { CalendarGrid } from './CalendarGrid';
|
|
14
|
+
import { ManualDateInput } from '../ManualDateInput/ManualDateInput';
|
|
15
|
+
import { Button } from '../common/Button';
|
|
16
|
+
|
|
17
|
+
export interface CalendarProps {
|
|
18
|
+
selectedDate: Date | null;
|
|
19
|
+
onSelectDate: (date: Date | null) => void;
|
|
20
|
+
theme: DatePickerTheme;
|
|
21
|
+
locale: DatePickerLocale;
|
|
22
|
+
format?: DateFormat;
|
|
23
|
+
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
24
|
+
minimumDate?: Date;
|
|
25
|
+
maximumDate?: Date;
|
|
26
|
+
disabledDates?: (Date | string)[] | DisabledDateCheck;
|
|
27
|
+
disabledWeekdays?: number[];
|
|
28
|
+
allowManualEntry?: boolean;
|
|
29
|
+
manualEntryType?: 'single' | 'split';
|
|
30
|
+
manualText?: string;
|
|
31
|
+
isManualMode?: boolean;
|
|
32
|
+
validationResult?: ValidationResult;
|
|
33
|
+
onManualTextChange?: (text: string) => void;
|
|
34
|
+
onToggleManualMode?: () => void;
|
|
35
|
+
showActionButtons?: boolean;
|
|
36
|
+
showTodayButton?: boolean;
|
|
37
|
+
showClearButton?: boolean;
|
|
38
|
+
onConfirm?: (date: Date | null) => void;
|
|
39
|
+
onCancel?: () => void;
|
|
40
|
+
onClear?: () => void;
|
|
41
|
+
style?: StyleProp<ViewStyle>;
|
|
42
|
+
onOpenMonthYearSelector?: () => void;
|
|
43
|
+
viewYear?: number;
|
|
44
|
+
viewMonth?: number;
|
|
45
|
+
onViewYearMonthChange?: (year: number, month: number) => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const Calendar: React.FC<CalendarProps> = ({
|
|
49
|
+
selectedDate,
|
|
50
|
+
onSelectDate,
|
|
51
|
+
theme,
|
|
52
|
+
locale,
|
|
53
|
+
format = 'DD/MM/YYYY',
|
|
54
|
+
firstDayOfWeek = 0,
|
|
55
|
+
minimumDate,
|
|
56
|
+
maximumDate,
|
|
57
|
+
disabledDates,
|
|
58
|
+
disabledWeekdays,
|
|
59
|
+
allowManualEntry = false,
|
|
60
|
+
manualEntryType = 'single',
|
|
61
|
+
manualText = '',
|
|
62
|
+
isManualMode = false,
|
|
63
|
+
validationResult = { isValid: true },
|
|
64
|
+
onManualTextChange,
|
|
65
|
+
onToggleManualMode,
|
|
66
|
+
showActionButtons = true,
|
|
67
|
+
showTodayButton = true,
|
|
68
|
+
showClearButton = true,
|
|
69
|
+
onConfirm,
|
|
70
|
+
onCancel,
|
|
71
|
+
onClear,
|
|
72
|
+
style,
|
|
73
|
+
onOpenMonthYearSelector,
|
|
74
|
+
viewYear,
|
|
75
|
+
viewMonth,
|
|
76
|
+
onViewYearMonthChange,
|
|
77
|
+
}) => {
|
|
78
|
+
const {
|
|
79
|
+
currentYear,
|
|
80
|
+
currentMonth,
|
|
81
|
+
currentMonthName,
|
|
82
|
+
days,
|
|
83
|
+
weekdays,
|
|
84
|
+
canGoPrevMonth,
|
|
85
|
+
canGoNextMonth,
|
|
86
|
+
goToPrevMonth,
|
|
87
|
+
goToNextMonth,
|
|
88
|
+
goToToday,
|
|
89
|
+
setMonth,
|
|
90
|
+
setYear,
|
|
91
|
+
jumpToDate,
|
|
92
|
+
} = useCalendar({
|
|
93
|
+
initialDate: selectedDate,
|
|
94
|
+
selectedDate,
|
|
95
|
+
firstDayOfWeek,
|
|
96
|
+
minimumDate,
|
|
97
|
+
maximumDate,
|
|
98
|
+
disabledDates,
|
|
99
|
+
disabledWeekdays,
|
|
100
|
+
locale,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Track previous selectedDate timestamp to avoid redundant jumpToDate calls
|
|
104
|
+
const prevSelectedDateRef = useRef<number | null>(
|
|
105
|
+
selectedDate ? selectedDate.getTime() : null
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
const time = selectedDate ? selectedDate.getTime() : null;
|
|
110
|
+
if (time !== null && time !== prevSelectedDateRef.current) {
|
|
111
|
+
prevSelectedDateRef.current = time;
|
|
112
|
+
jumpToDate(new Date(time));
|
|
113
|
+
}
|
|
114
|
+
}, [selectedDate, jumpToDate]);
|
|
115
|
+
|
|
116
|
+
// Synchronize calendar view with external viewYear & viewMonth when provided
|
|
117
|
+
const prevViewYearRef = useRef<number | undefined>(viewYear);
|
|
118
|
+
const prevViewMonthRef = useRef<number | undefined>(viewMonth);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (viewYear !== undefined && viewMonth !== undefined) {
|
|
122
|
+
if (
|
|
123
|
+
viewYear !== prevViewYearRef.current ||
|
|
124
|
+
viewMonth !== prevViewMonthRef.current
|
|
125
|
+
) {
|
|
126
|
+
prevViewYearRef.current = viewYear;
|
|
127
|
+
prevViewMonthRef.current = viewMonth;
|
|
128
|
+
if (currentYear !== viewYear || currentMonth !== viewMonth) {
|
|
129
|
+
jumpToDate(new Date(viewYear, viewMonth, 1));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, [viewYear, viewMonth, currentYear, currentMonth, jumpToDate]);
|
|
134
|
+
|
|
135
|
+
// Notify parent of view changes (e.g. prev/next month chevrons) only when values actually change
|
|
136
|
+
const onViewYearMonthChangeRef = useRef(onViewYearMonthChange);
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
onViewYearMonthChangeRef.current = onViewYearMonthChange;
|
|
139
|
+
}, [onViewYearMonthChange]);
|
|
140
|
+
|
|
141
|
+
const prevReportedYearRef = useRef<number>(currentYear);
|
|
142
|
+
const prevReportedMonthRef = useRef<number>(currentMonth);
|
|
143
|
+
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (
|
|
146
|
+
currentYear !== prevReportedYearRef.current ||
|
|
147
|
+
currentMonth !== prevReportedMonthRef.current
|
|
148
|
+
) {
|
|
149
|
+
prevReportedYearRef.current = currentYear;
|
|
150
|
+
prevReportedMonthRef.current = currentMonth;
|
|
151
|
+
onViewYearMonthChangeRef.current?.(currentYear, currentMonth);
|
|
152
|
+
}
|
|
153
|
+
}, [currentYear, currentMonth]);
|
|
154
|
+
|
|
155
|
+
const handleTodayPress = () => {
|
|
156
|
+
goToToday();
|
|
157
|
+
const today = new Date();
|
|
158
|
+
onSelectDate(today);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const handleClearPress = () => {
|
|
162
|
+
if (onClear) {
|
|
163
|
+
onClear();
|
|
164
|
+
} else {
|
|
165
|
+
onSelectDate(null);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<View
|
|
171
|
+
style={[
|
|
172
|
+
styles.container,
|
|
173
|
+
{
|
|
174
|
+
backgroundColor: theme.cardColor,
|
|
175
|
+
borderColor: theme.borderColor,
|
|
176
|
+
borderRadius: theme.borderRadius,
|
|
177
|
+
},
|
|
178
|
+
style,
|
|
179
|
+
]}
|
|
180
|
+
>
|
|
181
|
+
<CalendarHeader
|
|
182
|
+
currentYear={currentYear}
|
|
183
|
+
currentMonth={currentMonth}
|
|
184
|
+
currentMonthName={currentMonthName}
|
|
185
|
+
theme={theme}
|
|
186
|
+
locale={locale}
|
|
187
|
+
canGoPrevMonth={canGoPrevMonth}
|
|
188
|
+
canGoNextMonth={canGoNextMonth}
|
|
189
|
+
onPrevMonth={goToPrevMonth}
|
|
190
|
+
onNextMonth={goToNextMonth}
|
|
191
|
+
onSelectMonth={setMonth}
|
|
192
|
+
onSelectYear={setYear}
|
|
193
|
+
allowManualEntry={allowManualEntry}
|
|
194
|
+
isManualMode={isManualMode}
|
|
195
|
+
onToggleManualMode={onToggleManualMode}
|
|
196
|
+
onOpenMonthYearSelector={onOpenMonthYearSelector}
|
|
197
|
+
/>
|
|
198
|
+
|
|
199
|
+
{isManualMode ? (
|
|
200
|
+
<View style={styles.manualContainer}>
|
|
201
|
+
<ManualDateInput
|
|
202
|
+
value={manualText}
|
|
203
|
+
onChangeText={(t) => onManualTextChange?.(t)}
|
|
204
|
+
validation={validationResult}
|
|
205
|
+
format={format}
|
|
206
|
+
theme={theme}
|
|
207
|
+
locale={locale}
|
|
208
|
+
type={manualEntryType}
|
|
209
|
+
/>
|
|
210
|
+
</View>
|
|
211
|
+
) : (
|
|
212
|
+
<>
|
|
213
|
+
<WeekDays weekdays={weekdays} theme={theme} />
|
|
214
|
+
<CalendarGrid
|
|
215
|
+
days={days}
|
|
216
|
+
theme={theme}
|
|
217
|
+
locale={locale}
|
|
218
|
+
onSelectDate={onSelectDate}
|
|
219
|
+
/>
|
|
220
|
+
</>
|
|
221
|
+
)}
|
|
222
|
+
|
|
223
|
+
{showActionButtons && (
|
|
224
|
+
<View style={styles.actionsFooter}>
|
|
225
|
+
<View style={styles.leftActions}>
|
|
226
|
+
{showTodayButton && (
|
|
227
|
+
<Button
|
|
228
|
+
title={locale.today}
|
|
229
|
+
variant="text"
|
|
230
|
+
size="small"
|
|
231
|
+
theme={theme}
|
|
232
|
+
onPress={handleTodayPress}
|
|
233
|
+
style={styles.actionBtn}
|
|
234
|
+
/>
|
|
235
|
+
)}
|
|
236
|
+
{showClearButton && (
|
|
237
|
+
<Button
|
|
238
|
+
title={locale.clear}
|
|
239
|
+
variant="text"
|
|
240
|
+
size="small"
|
|
241
|
+
theme={theme}
|
|
242
|
+
onPress={handleClearPress}
|
|
243
|
+
style={styles.actionBtn}
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
</View>
|
|
247
|
+
|
|
248
|
+
<View style={styles.rightActions}>
|
|
249
|
+
{onCancel && (
|
|
250
|
+
<Button
|
|
251
|
+
title={locale.cancel}
|
|
252
|
+
variant="outline"
|
|
253
|
+
size="small"
|
|
254
|
+
theme={theme}
|
|
255
|
+
onPress={onCancel}
|
|
256
|
+
style={styles.actionBtn}
|
|
257
|
+
/>
|
|
258
|
+
)}
|
|
259
|
+
{onConfirm && (
|
|
260
|
+
<Button
|
|
261
|
+
title={locale.confirm}
|
|
262
|
+
variant="primary"
|
|
263
|
+
size="small"
|
|
264
|
+
theme={theme}
|
|
265
|
+
onPress={() => onConfirm(selectedDate)}
|
|
266
|
+
style={styles.actionBtn}
|
|
267
|
+
/>
|
|
268
|
+
)}
|
|
269
|
+
</View>
|
|
270
|
+
</View>
|
|
271
|
+
)}
|
|
272
|
+
</View>
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const styles = StyleSheet.create({
|
|
277
|
+
container: {
|
|
278
|
+
padding: 10,
|
|
279
|
+
borderWidth: 1,
|
|
280
|
+
overflow: 'hidden',
|
|
281
|
+
flexGrow: 1,
|
|
282
|
+
justifyContent: 'space-between',
|
|
283
|
+
},
|
|
284
|
+
manualContainer: {
|
|
285
|
+
paddingTop: 6,
|
|
286
|
+
paddingBottom: 8,
|
|
287
|
+
paddingHorizontal: 4,
|
|
288
|
+
flex: 1,
|
|
289
|
+
justifyContent: 'flex-start',
|
|
290
|
+
},
|
|
291
|
+
actionsFooter: {
|
|
292
|
+
flexDirection: 'row',
|
|
293
|
+
alignItems: 'center',
|
|
294
|
+
justifyContent: 'space-between',
|
|
295
|
+
paddingTop: 10,
|
|
296
|
+
paddingBottom: 2,
|
|
297
|
+
marginTop: 'auto',
|
|
298
|
+
borderTopWidth: 1,
|
|
299
|
+
borderTopColor: 'rgba(0,0,0,0.06)',
|
|
300
|
+
},
|
|
301
|
+
leftActions: {
|
|
302
|
+
flexDirection: 'row',
|
|
303
|
+
alignItems: 'center',
|
|
304
|
+
gap: 8,
|
|
305
|
+
},
|
|
306
|
+
rightActions: {
|
|
307
|
+
flexDirection: 'row',
|
|
308
|
+
alignItems: 'center',
|
|
309
|
+
gap: 8,
|
|
310
|
+
},
|
|
311
|
+
actionBtn: {
|
|
312
|
+
marginHorizontal: 0,
|
|
313
|
+
},
|
|
314
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import type { CalendarDayCell, DatePickerTheme, DatePickerLocale } from '../../types';
|
|
4
|
+
import { DateCell } from './DateCell';
|
|
5
|
+
|
|
6
|
+
export interface CalendarGridProps {
|
|
7
|
+
days: CalendarDayCell[];
|
|
8
|
+
theme: DatePickerTheme;
|
|
9
|
+
locale: DatePickerLocale;
|
|
10
|
+
onSelectDate: (date: Date) => void;
|
|
11
|
+
cellSize?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const CalendarGrid: React.FC<CalendarGridProps> = ({
|
|
15
|
+
days,
|
|
16
|
+
theme,
|
|
17
|
+
locale,
|
|
18
|
+
onSelectDate,
|
|
19
|
+
cellSize,
|
|
20
|
+
}) => {
|
|
21
|
+
return (
|
|
22
|
+
<View style={styles.grid}>
|
|
23
|
+
{days.map((cell) => {
|
|
24
|
+
const key = `${cell.date.getFullYear()}-${cell.date.getMonth()}-${cell.date.getDate()}`;
|
|
25
|
+
return (
|
|
26
|
+
<DateCell
|
|
27
|
+
key={key}
|
|
28
|
+
cell={cell}
|
|
29
|
+
theme={theme}
|
|
30
|
+
locale={locale}
|
|
31
|
+
onPress={onSelectDate}
|
|
32
|
+
size={cellSize}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
})}
|
|
36
|
+
</View>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const styles = StyleSheet.create({
|
|
41
|
+
grid: {
|
|
42
|
+
flexDirection: 'row',
|
|
43
|
+
flexWrap: 'wrap',
|
|
44
|
+
width: '100%',
|
|
45
|
+
paddingVertical: 6,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import type { DatePickerTheme, DatePickerLocale } from '../../types';
|
|
9
|
+
import { IconButton } from '../common/IconButton';
|
|
10
|
+
import { MonthYearSelectorModal } from './MonthYearSelectorModal';
|
|
11
|
+
|
|
12
|
+
export interface CalendarHeaderProps {
|
|
13
|
+
currentYear: number;
|
|
14
|
+
currentMonth: number;
|
|
15
|
+
currentMonthName: string;
|
|
16
|
+
theme: DatePickerTheme;
|
|
17
|
+
locale: DatePickerLocale;
|
|
18
|
+
canGoPrevMonth: boolean;
|
|
19
|
+
canGoNextMonth: boolean;
|
|
20
|
+
onPrevMonth: () => void;
|
|
21
|
+
onNextMonth: () => void;
|
|
22
|
+
onSelectMonth: (monthIndex: number) => void;
|
|
23
|
+
onSelectYear: (year: number) => void;
|
|
24
|
+
allowManualEntry?: boolean;
|
|
25
|
+
isManualMode?: boolean;
|
|
26
|
+
onToggleManualMode?: () => void;
|
|
27
|
+
minYear?: number;
|
|
28
|
+
maxYear?: number;
|
|
29
|
+
onOpenMonthYearSelector?: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const CalendarHeader: React.FC<CalendarHeaderProps> = ({
|
|
33
|
+
currentYear,
|
|
34
|
+
currentMonth,
|
|
35
|
+
currentMonthName,
|
|
36
|
+
theme,
|
|
37
|
+
locale,
|
|
38
|
+
canGoPrevMonth,
|
|
39
|
+
canGoNextMonth,
|
|
40
|
+
onPrevMonth,
|
|
41
|
+
onNextMonth,
|
|
42
|
+
onSelectMonth,
|
|
43
|
+
onSelectYear,
|
|
44
|
+
allowManualEntry = false,
|
|
45
|
+
isManualMode = false,
|
|
46
|
+
onToggleManualMode,
|
|
47
|
+
minYear = 1970,
|
|
48
|
+
maxYear = 2050,
|
|
49
|
+
onOpenMonthYearSelector,
|
|
50
|
+
}) => {
|
|
51
|
+
const [isSelectorOpen, setIsSelectorOpen] = useState(false);
|
|
52
|
+
|
|
53
|
+
const handleTitlePress = () => {
|
|
54
|
+
if (onOpenMonthYearSelector) {
|
|
55
|
+
onOpenMonthYearSelector();
|
|
56
|
+
} else {
|
|
57
|
+
setIsSelectorOpen(true);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<View style={styles.container}>
|
|
63
|
+
<TouchableOpacity
|
|
64
|
+
activeOpacity={0.7}
|
|
65
|
+
onPress={handleTitlePress}
|
|
66
|
+
style={styles.titleContainer}
|
|
67
|
+
accessibilityRole="button"
|
|
68
|
+
accessibilityLabel={`${currentMonthName} ${currentYear}, tap to change month and year`}
|
|
69
|
+
>
|
|
70
|
+
<Text
|
|
71
|
+
style={[
|
|
72
|
+
styles.titleText,
|
|
73
|
+
{
|
|
74
|
+
color: theme.textColor,
|
|
75
|
+
fontSize: theme.fontSize.large,
|
|
76
|
+
},
|
|
77
|
+
]}
|
|
78
|
+
>
|
|
79
|
+
{`${currentMonthName} ${currentYear}`}
|
|
80
|
+
</Text>
|
|
81
|
+
<View style={styles.dropdownCaret}>
|
|
82
|
+
<Text style={[styles.caretText, { color: theme.secondaryTextColor }]}>
|
|
83
|
+
▾
|
|
84
|
+
</Text>
|
|
85
|
+
</View>
|
|
86
|
+
</TouchableOpacity>
|
|
87
|
+
|
|
88
|
+
<View style={styles.actions}>
|
|
89
|
+
{allowManualEntry && onToggleManualMode && (
|
|
90
|
+
<IconButton
|
|
91
|
+
icon={isManualMode ? 'calendar' : 'keyboard'}
|
|
92
|
+
color={theme.primaryColor}
|
|
93
|
+
onPress={onToggleManualMode}
|
|
94
|
+
size={18}
|
|
95
|
+
accessibilityLabel={
|
|
96
|
+
isManualMode ? locale.switchCalendar : locale.switchManual
|
|
97
|
+
}
|
|
98
|
+
style={styles.actionButton}
|
|
99
|
+
/>
|
|
100
|
+
)}
|
|
101
|
+
|
|
102
|
+
<IconButton
|
|
103
|
+
icon="chevron-left"
|
|
104
|
+
disabled={!canGoPrevMonth}
|
|
105
|
+
color={canGoPrevMonth ? theme.textColor : theme.disabledTextColor}
|
|
106
|
+
onPress={onPrevMonth}
|
|
107
|
+
size={18}
|
|
108
|
+
accessibilityLabel="Previous month"
|
|
109
|
+
style={styles.actionButton}
|
|
110
|
+
/>
|
|
111
|
+
|
|
112
|
+
<IconButton
|
|
113
|
+
icon="chevron-right"
|
|
114
|
+
disabled={!canGoNextMonth}
|
|
115
|
+
color={canGoNextMonth ? theme.textColor : theme.disabledTextColor}
|
|
116
|
+
onPress={onNextMonth}
|
|
117
|
+
size={18}
|
|
118
|
+
accessibilityLabel="Next month"
|
|
119
|
+
style={styles.actionButton}
|
|
120
|
+
/>
|
|
121
|
+
</View>
|
|
122
|
+
|
|
123
|
+
{/* Internal Month & Year Selection Modal (fallback when not managed externally by parent modal) */}
|
|
124
|
+
{!onOpenMonthYearSelector && (
|
|
125
|
+
<MonthYearSelectorModal
|
|
126
|
+
visible={isSelectorOpen}
|
|
127
|
+
onClose={() => setIsSelectorOpen(false)}
|
|
128
|
+
currentYear={currentYear}
|
|
129
|
+
currentMonth={currentMonth}
|
|
130
|
+
theme={theme}
|
|
131
|
+
locale={locale}
|
|
132
|
+
onSelectMonth={onSelectMonth}
|
|
133
|
+
onSelectYear={onSelectYear}
|
|
134
|
+
onConfirm={(y, m) => {
|
|
135
|
+
onSelectYear(y);
|
|
136
|
+
onSelectMonth(m);
|
|
137
|
+
setIsSelectorOpen(false);
|
|
138
|
+
}}
|
|
139
|
+
minYear={minYear}
|
|
140
|
+
maxYear={maxYear}
|
|
141
|
+
/>
|
|
142
|
+
)}
|
|
143
|
+
</View>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const styles = StyleSheet.create({
|
|
148
|
+
container: {
|
|
149
|
+
flexDirection: 'row',
|
|
150
|
+
alignItems: 'center',
|
|
151
|
+
justifyContent: 'space-between',
|
|
152
|
+
paddingHorizontal: 8,
|
|
153
|
+
paddingVertical: 12,
|
|
154
|
+
},
|
|
155
|
+
titleContainer: {
|
|
156
|
+
flexDirection: 'row',
|
|
157
|
+
alignItems: 'center',
|
|
158
|
+
},
|
|
159
|
+
titleText: {
|
|
160
|
+
fontWeight: '700',
|
|
161
|
+
},
|
|
162
|
+
dropdownCaret: {
|
|
163
|
+
marginLeft: 6,
|
|
164
|
+
marginBottom: 2,
|
|
165
|
+
},
|
|
166
|
+
caretText: {
|
|
167
|
+
fontSize: 14,
|
|
168
|
+
},
|
|
169
|
+
actions: {
|
|
170
|
+
flexDirection: 'row',
|
|
171
|
+
alignItems: 'center',
|
|
172
|
+
},
|
|
173
|
+
actionButton: {
|
|
174
|
+
marginLeft: 2,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
TouchableOpacity,
|
|
4
|
+
Text,
|
|
5
|
+
View,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import type { CalendarDayCell, DatePickerTheme, DatePickerLocale } from '../../types';
|
|
9
|
+
import { formatDate } from '../../utils/dateFormatting';
|
|
10
|
+
|
|
11
|
+
export interface DateCellProps {
|
|
12
|
+
cell: CalendarDayCell;
|
|
13
|
+
theme: DatePickerTheme;
|
|
14
|
+
locale: DatePickerLocale;
|
|
15
|
+
onPress: (date: Date) => void;
|
|
16
|
+
size?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const DateCell: React.FC<DateCellProps> = ({
|
|
20
|
+
cell,
|
|
21
|
+
theme,
|
|
22
|
+
locale,
|
|
23
|
+
onPress,
|
|
24
|
+
size = 40,
|
|
25
|
+
}) => {
|
|
26
|
+
const {
|
|
27
|
+
date,
|
|
28
|
+
dayNumber,
|
|
29
|
+
isCurrentMonth,
|
|
30
|
+
isToday,
|
|
31
|
+
isSelected,
|
|
32
|
+
isDisabled,
|
|
33
|
+
} = cell;
|
|
34
|
+
|
|
35
|
+
const accessibleDateLabel = formatDate(date, 'DD MMMM YYYY', locale);
|
|
36
|
+
|
|
37
|
+
const getTextColor = (): string => {
|
|
38
|
+
if (isDisabled) {
|
|
39
|
+
return theme.disabledTextColor;
|
|
40
|
+
}
|
|
41
|
+
if (isSelected) {
|
|
42
|
+
return theme.selectedDayTextColor;
|
|
43
|
+
}
|
|
44
|
+
if (isToday) {
|
|
45
|
+
return theme.todayTextColor;
|
|
46
|
+
}
|
|
47
|
+
if (!isCurrentMonth) {
|
|
48
|
+
return theme.secondaryTextColor;
|
|
49
|
+
}
|
|
50
|
+
return theme.textColor;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<TouchableOpacity
|
|
55
|
+
activeOpacity={0.7}
|
|
56
|
+
disabled={isDisabled}
|
|
57
|
+
onPress={() => onPress(date)}
|
|
58
|
+
accessibilityRole="button"
|
|
59
|
+
accessibilityLabel={accessibleDateLabel}
|
|
60
|
+
accessibilityState={{
|
|
61
|
+
selected: isSelected,
|
|
62
|
+
disabled: isDisabled,
|
|
63
|
+
}}
|
|
64
|
+
style={[
|
|
65
|
+
styles.cellWrapper,
|
|
66
|
+
{
|
|
67
|
+
width: `${100 / 7}%`,
|
|
68
|
+
height: size,
|
|
69
|
+
},
|
|
70
|
+
]}
|
|
71
|
+
>
|
|
72
|
+
<View
|
|
73
|
+
style={[
|
|
74
|
+
styles.cellCircle,
|
|
75
|
+
{
|
|
76
|
+
width: size * 0.85,
|
|
77
|
+
height: size * 0.85,
|
|
78
|
+
borderRadius: (size * 0.85) / 2,
|
|
79
|
+
backgroundColor: isSelected
|
|
80
|
+
? theme.selectedDayBackgroundColor
|
|
81
|
+
: 'transparent',
|
|
82
|
+
borderWidth: isToday && !isSelected ? 1.5 : 0,
|
|
83
|
+
borderColor: isToday && !isSelected ? theme.todayBorderColor : 'transparent',
|
|
84
|
+
opacity: !isCurrentMonth ? 0.45 : 1,
|
|
85
|
+
},
|
|
86
|
+
]}
|
|
87
|
+
>
|
|
88
|
+
<Text
|
|
89
|
+
style={[
|
|
90
|
+
styles.dayText,
|
|
91
|
+
{
|
|
92
|
+
color: getTextColor(),
|
|
93
|
+
fontSize: theme.fontSize.medium,
|
|
94
|
+
fontWeight: isSelected || isToday ? '700' : '400',
|
|
95
|
+
},
|
|
96
|
+
]}
|
|
97
|
+
>
|
|
98
|
+
{dayNumber}
|
|
99
|
+
</Text>
|
|
100
|
+
</View>
|
|
101
|
+
</TouchableOpacity>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const styles = StyleSheet.create({
|
|
106
|
+
cellWrapper: {
|
|
107
|
+
alignItems: 'center',
|
|
108
|
+
justifyContent: 'center',
|
|
109
|
+
paddingVertical: 2,
|
|
110
|
+
},
|
|
111
|
+
cellCircle: {
|
|
112
|
+
alignItems: 'center',
|
|
113
|
+
justifyContent: 'center',
|
|
114
|
+
},
|
|
115
|
+
dayText: {
|
|
116
|
+
textAlign: 'center',
|
|
117
|
+
},
|
|
118
|
+
});
|