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