@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,168 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
DatePickerTheme,
|
|
5
|
+
DatePickerLocale,
|
|
6
|
+
DateFormat,
|
|
7
|
+
DisabledDateCheck,
|
|
8
|
+
ValidationResult,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
import { Modal } from '../common/Modal';
|
|
11
|
+
import { Calendar } from '../Calendar/Calendar';
|
|
12
|
+
import { MonthYearSelectorModal } from '../Calendar/MonthYearSelectorModal';
|
|
13
|
+
|
|
14
|
+
export interface CalendarPopupProps {
|
|
15
|
+
visible: boolean;
|
|
16
|
+
onClose: () => void;
|
|
17
|
+
selectedDate: Date | null;
|
|
18
|
+
onSelectDate: (date: Date | null) => void;
|
|
19
|
+
theme: DatePickerTheme;
|
|
20
|
+
locale: DatePickerLocale;
|
|
21
|
+
format?: DateFormat;
|
|
22
|
+
minimumDate?: Date;
|
|
23
|
+
maximumDate?: Date;
|
|
24
|
+
disabledDates?: (Date | string)[] | DisabledDateCheck;
|
|
25
|
+
disabledWeekdays?: number[];
|
|
26
|
+
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
27
|
+
allowManualEntry?: boolean;
|
|
28
|
+
manualEntryType?: 'single' | 'split';
|
|
29
|
+
manualText?: string;
|
|
30
|
+
isManualMode?: boolean;
|
|
31
|
+
validationResult?: ValidationResult;
|
|
32
|
+
onManualTextChange?: (text: string) => void;
|
|
33
|
+
onToggleManualMode?: () => void;
|
|
34
|
+
onConfirm?: (date: Date | null) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const CalendarPopup: React.FC<CalendarPopupProps> = ({
|
|
38
|
+
visible,
|
|
39
|
+
onClose,
|
|
40
|
+
selectedDate,
|
|
41
|
+
onSelectDate,
|
|
42
|
+
theme,
|
|
43
|
+
locale,
|
|
44
|
+
format,
|
|
45
|
+
minimumDate,
|
|
46
|
+
maximumDate,
|
|
47
|
+
disabledDates,
|
|
48
|
+
disabledWeekdays,
|
|
49
|
+
firstDayOfWeek,
|
|
50
|
+
allowManualEntry,
|
|
51
|
+
manualEntryType,
|
|
52
|
+
manualText,
|
|
53
|
+
isManualMode,
|
|
54
|
+
validationResult,
|
|
55
|
+
onManualTextChange,
|
|
56
|
+
onToggleManualMode,
|
|
57
|
+
onConfirm,
|
|
58
|
+
}) => {
|
|
59
|
+
const [draftDate, setDraftDate] = useState<Date | null>(selectedDate);
|
|
60
|
+
const [isMonthYearOpen, setIsMonthYearOpen] = useState(false);
|
|
61
|
+
const [viewYear, setViewYear] = useState<number>(() => (selectedDate || new Date()).getFullYear());
|
|
62
|
+
const [viewMonth, setViewMonth] = useState<number>(() => (selectedDate || new Date()).getMonth());
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (visible) {
|
|
66
|
+
setDraftDate(selectedDate);
|
|
67
|
+
const d = selectedDate || new Date();
|
|
68
|
+
setViewYear(d.getFullYear());
|
|
69
|
+
setViewMonth(d.getMonth());
|
|
70
|
+
setIsMonthYearOpen(false);
|
|
71
|
+
}
|
|
72
|
+
}, [visible, selectedDate]);
|
|
73
|
+
|
|
74
|
+
const handleConfirm = (date: Date | null) => {
|
|
75
|
+
const finalDate = date !== undefined ? date : draftDate;
|
|
76
|
+
onSelectDate(finalDate);
|
|
77
|
+
onConfirm?.(finalDate);
|
|
78
|
+
onClose();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const handleViewYearMonthChange = (y: number, m: number) => {
|
|
82
|
+
setViewYear((prevY) => (prevY !== y ? y : prevY));
|
|
83
|
+
setViewMonth((prevM) => (prevM !== m ? m : prevM));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const handleMonthYearConfirm = (newYear: number, newMonth: number) => {
|
|
87
|
+
setViewYear(newYear);
|
|
88
|
+
setViewMonth(newMonth);
|
|
89
|
+
|
|
90
|
+
if (draftDate instanceof Date && !isNaN(draftDate.getTime())) {
|
|
91
|
+
const currentDay = draftDate.getDate();
|
|
92
|
+
const maxDaysInNewMonth = new Date(newYear, newMonth + 1, 0).getDate();
|
|
93
|
+
const clampedDay = Math.min(currentDay, maxDaysInNewMonth);
|
|
94
|
+
const updated = new Date(
|
|
95
|
+
newYear,
|
|
96
|
+
newMonth,
|
|
97
|
+
clampedDay,
|
|
98
|
+
draftDate.getHours(),
|
|
99
|
+
draftDate.getMinutes(),
|
|
100
|
+
draftDate.getSeconds()
|
|
101
|
+
);
|
|
102
|
+
setDraftDate(updated);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
setIsMonthYearOpen(false);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
<Modal visible={visible && !isMonthYearOpen} onClose={onClose} theme={theme}>
|
|
111
|
+
<View style={styles.calendarWrapper}>
|
|
112
|
+
<Calendar
|
|
113
|
+
selectedDate={draftDate}
|
|
114
|
+
onSelectDate={setDraftDate}
|
|
115
|
+
theme={theme}
|
|
116
|
+
locale={locale}
|
|
117
|
+
format={format}
|
|
118
|
+
minimumDate={minimumDate}
|
|
119
|
+
maximumDate={maximumDate}
|
|
120
|
+
disabledDates={disabledDates}
|
|
121
|
+
disabledWeekdays={disabledWeekdays}
|
|
122
|
+
firstDayOfWeek={firstDayOfWeek}
|
|
123
|
+
allowManualEntry={allowManualEntry}
|
|
124
|
+
manualEntryType={manualEntryType}
|
|
125
|
+
manualText={manualText}
|
|
126
|
+
isManualMode={isManualMode}
|
|
127
|
+
validationResult={validationResult}
|
|
128
|
+
onManualTextChange={onManualTextChange}
|
|
129
|
+
onToggleManualMode={onToggleManualMode}
|
|
130
|
+
showActionButtons={true}
|
|
131
|
+
showTodayButton={true}
|
|
132
|
+
showClearButton={true}
|
|
133
|
+
onConfirm={handleConfirm}
|
|
134
|
+
onCancel={onClose}
|
|
135
|
+
onClear={() => setDraftDate(null)}
|
|
136
|
+
style={styles.calendarInner}
|
|
137
|
+
viewYear={viewYear}
|
|
138
|
+
viewMonth={viewMonth}
|
|
139
|
+
onViewYearMonthChange={handleViewYearMonthChange}
|
|
140
|
+
onOpenMonthYearSelector={() => setIsMonthYearOpen(true)}
|
|
141
|
+
/>
|
|
142
|
+
</View>
|
|
143
|
+
</Modal>
|
|
144
|
+
|
|
145
|
+
<MonthYearSelectorModal
|
|
146
|
+
visible={visible && isMonthYearOpen}
|
|
147
|
+
onClose={() => setIsMonthYearOpen(false)}
|
|
148
|
+
currentYear={viewYear}
|
|
149
|
+
currentMonth={viewMonth}
|
|
150
|
+
theme={theme}
|
|
151
|
+
locale={locale}
|
|
152
|
+
onConfirm={handleMonthYearConfirm}
|
|
153
|
+
/>
|
|
154
|
+
</>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const styles = StyleSheet.create({
|
|
159
|
+
calendarWrapper: {
|
|
160
|
+
width: '100%',
|
|
161
|
+
flex: 1,
|
|
162
|
+
},
|
|
163
|
+
calendarInner: {
|
|
164
|
+
borderWidth: 0,
|
|
165
|
+
backgroundColor: 'transparent',
|
|
166
|
+
padding: 0,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
TextInput,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
StyleProp,
|
|
9
|
+
ViewStyle,
|
|
10
|
+
TextStyle,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import type {
|
|
13
|
+
DatePickerTheme,
|
|
14
|
+
DatePickerLocale,
|
|
15
|
+
DateFormat,
|
|
16
|
+
DisabledDateCheck,
|
|
17
|
+
} from '../../types';
|
|
18
|
+
import { useDatePicker } from '../../hooks/useDatePicker';
|
|
19
|
+
import { CalendarPopup } from './CalendarPopup';
|
|
20
|
+
import { IconButton } from '../common/IconButton';
|
|
21
|
+
import { DateValidationMessage } from '../ManualDateInput/DateValidationMessage';
|
|
22
|
+
import { getPlaceholderForFormat } from '../../utils/dateFormatting';
|
|
23
|
+
|
|
24
|
+
export interface DateInputProps {
|
|
25
|
+
value?: Date | null;
|
|
26
|
+
defaultValue?: Date | null;
|
|
27
|
+
onChange?: (date: Date | null) => void;
|
|
28
|
+
onConfirm?: (date: Date | null) => void;
|
|
29
|
+
onCancel?: () => void;
|
|
30
|
+
onClear?: () => void;
|
|
31
|
+
format?: DateFormat;
|
|
32
|
+
theme: DatePickerTheme;
|
|
33
|
+
locale: DatePickerLocale;
|
|
34
|
+
minimumDate?: Date;
|
|
35
|
+
maximumDate?: Date;
|
|
36
|
+
disabledDates?: (Date | string)[] | DisabledDateCheck;
|
|
37
|
+
disabledWeekdays?: number[];
|
|
38
|
+
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
39
|
+
allowManualEntry?: boolean;
|
|
40
|
+
manualEntryType?: 'single' | 'split';
|
|
41
|
+
placeholder?: string;
|
|
42
|
+
label?: string;
|
|
43
|
+
editable?: boolean;
|
|
44
|
+
style?: StyleProp<ViewStyle>;
|
|
45
|
+
inputStyle?: StyleProp<TextStyle>;
|
|
46
|
+
inputContainerStyle?: StyleProp<ViewStyle>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const DateInput: React.FC<DateInputProps> = ({
|
|
50
|
+
value,
|
|
51
|
+
defaultValue,
|
|
52
|
+
onChange,
|
|
53
|
+
onConfirm,
|
|
54
|
+
onCancel,
|
|
55
|
+
onClear,
|
|
56
|
+
format = 'DD/MM/YYYY',
|
|
57
|
+
theme,
|
|
58
|
+
locale,
|
|
59
|
+
minimumDate,
|
|
60
|
+
maximumDate,
|
|
61
|
+
disabledDates,
|
|
62
|
+
disabledWeekdays,
|
|
63
|
+
firstDayOfWeek = 0,
|
|
64
|
+
allowManualEntry = true,
|
|
65
|
+
manualEntryType = 'single',
|
|
66
|
+
placeholder,
|
|
67
|
+
label,
|
|
68
|
+
editable = true,
|
|
69
|
+
style,
|
|
70
|
+
inputStyle,
|
|
71
|
+
inputContainerStyle,
|
|
72
|
+
}) => {
|
|
73
|
+
const [isPopupOpen, setIsPopupOpen] = useState(false);
|
|
74
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
75
|
+
|
|
76
|
+
const {
|
|
77
|
+
selectedDate,
|
|
78
|
+
manualText,
|
|
79
|
+
isManualMode,
|
|
80
|
+
validationResult,
|
|
81
|
+
selectDate,
|
|
82
|
+
handleManualInputChange,
|
|
83
|
+
toggleManualMode,
|
|
84
|
+
clear,
|
|
85
|
+
} = useDatePicker({
|
|
86
|
+
value,
|
|
87
|
+
defaultValue,
|
|
88
|
+
onChange: (d) => {
|
|
89
|
+
onChange?.(d);
|
|
90
|
+
},
|
|
91
|
+
format,
|
|
92
|
+
locale,
|
|
93
|
+
minimumDate,
|
|
94
|
+
maximumDate,
|
|
95
|
+
disabledDates,
|
|
96
|
+
disabledWeekdays,
|
|
97
|
+
allowManualEntry,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const defaultPlaceholder = placeholder || getPlaceholderForFormat(format);
|
|
101
|
+
|
|
102
|
+
const handleFieldPress = () => {
|
|
103
|
+
if (!allowManualEntry && editable) {
|
|
104
|
+
setIsPopupOpen(true);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handleClearPress = () => {
|
|
109
|
+
clear();
|
|
110
|
+
onClear?.();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const handleConfirmPopup = (confirmedDate: Date | null) => {
|
|
114
|
+
selectDate(confirmedDate);
|
|
115
|
+
onChange?.(confirmedDate);
|
|
116
|
+
onConfirm?.(confirmedDate);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const getBorderColor = () => {
|
|
120
|
+
if (!validationResult.isValid) return theme.errorColor;
|
|
121
|
+
if (isFocused) return theme.primaryColor;
|
|
122
|
+
return theme.borderColor;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<View style={[styles.container, style]}>
|
|
127
|
+
{label && (
|
|
128
|
+
<Text
|
|
129
|
+
style={[
|
|
130
|
+
styles.label,
|
|
131
|
+
{ color: theme.textColor, fontSize: theme.fontSize.small },
|
|
132
|
+
]}
|
|
133
|
+
>
|
|
134
|
+
{label}
|
|
135
|
+
</Text>
|
|
136
|
+
)}
|
|
137
|
+
|
|
138
|
+
<TouchableOpacity
|
|
139
|
+
activeOpacity={allowManualEntry ? 1 : 0.7}
|
|
140
|
+
onPress={handleFieldPress}
|
|
141
|
+
style={[
|
|
142
|
+
styles.inputRow,
|
|
143
|
+
{
|
|
144
|
+
backgroundColor: theme.cardColor || theme.surfaceColor,
|
|
145
|
+
borderColor: getBorderColor(),
|
|
146
|
+
borderRadius: Math.max(theme.borderRadius, 14),
|
|
147
|
+
shadowColor: isFocused ? theme.primaryColor : '#000',
|
|
148
|
+
shadowOpacity: isFocused ? 0.12 : 0.03,
|
|
149
|
+
},
|
|
150
|
+
inputContainerStyle,
|
|
151
|
+
]}
|
|
152
|
+
>
|
|
153
|
+
<TextInput
|
|
154
|
+
value={manualText}
|
|
155
|
+
onChangeText={handleManualInputChange}
|
|
156
|
+
onFocus={() => setIsFocused(true)}
|
|
157
|
+
onBlur={() => setIsFocused(false)}
|
|
158
|
+
placeholder={defaultPlaceholder}
|
|
159
|
+
placeholderTextColor={theme.disabledTextColor}
|
|
160
|
+
editable={editable && allowManualEntry}
|
|
161
|
+
keyboardType="numeric"
|
|
162
|
+
maxLength={10}
|
|
163
|
+
style={[
|
|
164
|
+
styles.textInput,
|
|
165
|
+
{
|
|
166
|
+
color: theme.textColor,
|
|
167
|
+
fontSize: theme.fontSize.medium,
|
|
168
|
+
},
|
|
169
|
+
inputStyle,
|
|
170
|
+
]}
|
|
171
|
+
accessibilityLabel={label || defaultPlaceholder}
|
|
172
|
+
/>
|
|
173
|
+
|
|
174
|
+
{manualText.length > 0 && editable && (
|
|
175
|
+
<IconButton
|
|
176
|
+
icon="close"
|
|
177
|
+
size={16}
|
|
178
|
+
color={theme.secondaryTextColor}
|
|
179
|
+
onPress={handleClearPress}
|
|
180
|
+
accessibilityLabel={locale.clear}
|
|
181
|
+
style={styles.actionIcon}
|
|
182
|
+
/>
|
|
183
|
+
)}
|
|
184
|
+
|
|
185
|
+
<IconButton
|
|
186
|
+
icon="calendar"
|
|
187
|
+
size={18}
|
|
188
|
+
color={theme.primaryColor}
|
|
189
|
+
onPress={() => setIsPopupOpen(true)}
|
|
190
|
+
disabled={!editable}
|
|
191
|
+
accessibilityLabel={locale.selectDate}
|
|
192
|
+
style={styles.actionIcon}
|
|
193
|
+
/>
|
|
194
|
+
</TouchableOpacity>
|
|
195
|
+
|
|
196
|
+
<DateValidationMessage validation={validationResult} theme={theme} />
|
|
197
|
+
|
|
198
|
+
<CalendarPopup
|
|
199
|
+
visible={isPopupOpen}
|
|
200
|
+
onClose={() => {
|
|
201
|
+
setIsPopupOpen(false);
|
|
202
|
+
onCancel?.();
|
|
203
|
+
}}
|
|
204
|
+
selectedDate={selectedDate}
|
|
205
|
+
onSelectDate={(d) => {
|
|
206
|
+
selectDate(d);
|
|
207
|
+
onChange?.(d);
|
|
208
|
+
}}
|
|
209
|
+
onConfirm={handleConfirmPopup}
|
|
210
|
+
theme={theme}
|
|
211
|
+
locale={locale}
|
|
212
|
+
format={format}
|
|
213
|
+
minimumDate={minimumDate}
|
|
214
|
+
maximumDate={maximumDate}
|
|
215
|
+
disabledDates={disabledDates}
|
|
216
|
+
disabledWeekdays={disabledWeekdays}
|
|
217
|
+
firstDayOfWeek={firstDayOfWeek}
|
|
218
|
+
allowManualEntry={allowManualEntry}
|
|
219
|
+
manualEntryType={manualEntryType}
|
|
220
|
+
manualText={manualText}
|
|
221
|
+
isManualMode={isManualMode}
|
|
222
|
+
validationResult={validationResult}
|
|
223
|
+
onManualTextChange={handleManualInputChange}
|
|
224
|
+
onToggleManualMode={toggleManualMode}
|
|
225
|
+
/>
|
|
226
|
+
</View>
|
|
227
|
+
);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const styles = StyleSheet.create({
|
|
231
|
+
container: {
|
|
232
|
+
width: '100%',
|
|
233
|
+
},
|
|
234
|
+
label: {
|
|
235
|
+
fontWeight: '700',
|
|
236
|
+
marginBottom: 8,
|
|
237
|
+
letterSpacing: -0.2,
|
|
238
|
+
},
|
|
239
|
+
inputRow: {
|
|
240
|
+
flexDirection: 'row',
|
|
241
|
+
alignItems: 'center',
|
|
242
|
+
borderWidth: 1.5,
|
|
243
|
+
paddingHorizontal: 14,
|
|
244
|
+
height: 52,
|
|
245
|
+
shadowOffset: { width: 0, height: 2 },
|
|
246
|
+
shadowRadius: 6,
|
|
247
|
+
elevation: 2,
|
|
248
|
+
},
|
|
249
|
+
textInput: {
|
|
250
|
+
flex: 1,
|
|
251
|
+
height: '100%',
|
|
252
|
+
padding: 0,
|
|
253
|
+
fontWeight: '600',
|
|
254
|
+
letterSpacing: 0.5,
|
|
255
|
+
},
|
|
256
|
+
actionIcon: {
|
|
257
|
+
marginLeft: 8,
|
|
258
|
+
},
|
|
259
|
+
});
|