@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,174 @@
|
|
|
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 RangeDateCellProps {
|
|
12
|
+
cell: CalendarDayCell;
|
|
13
|
+
theme: DatePickerTheme;
|
|
14
|
+
locale: DatePickerLocale;
|
|
15
|
+
onPress: (date: Date) => void;
|
|
16
|
+
size?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const RangeDateCell: React.FC<RangeDateCellProps> = ({
|
|
20
|
+
cell,
|
|
21
|
+
theme,
|
|
22
|
+
locale,
|
|
23
|
+
onPress,
|
|
24
|
+
size = 40,
|
|
25
|
+
}) => {
|
|
26
|
+
const {
|
|
27
|
+
date,
|
|
28
|
+
dayNumber,
|
|
29
|
+
isCurrentMonth,
|
|
30
|
+
isToday,
|
|
31
|
+
isRangeStart,
|
|
32
|
+
isRangeEnd,
|
|
33
|
+
isInRange,
|
|
34
|
+
isDisabled,
|
|
35
|
+
} = cell;
|
|
36
|
+
|
|
37
|
+
const accessibleDateLabel = formatDate(date, 'DD MMMM YYYY', locale);
|
|
38
|
+
|
|
39
|
+
const getTextColor = (): string => {
|
|
40
|
+
if (isDisabled) return theme.disabledTextColor;
|
|
41
|
+
if (isRangeStart || isRangeEnd) return theme.selectedDayTextColor;
|
|
42
|
+
if (isInRange) return theme.rangeBetweenTextColor;
|
|
43
|
+
if (isToday) return theme.todayTextColor;
|
|
44
|
+
if (!isCurrentMonth) return theme.secondaryTextColor;
|
|
45
|
+
return theme.textColor;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const isEdge = isRangeStart || isRangeEnd;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<TouchableOpacity
|
|
52
|
+
activeOpacity={0.7}
|
|
53
|
+
disabled={isDisabled}
|
|
54
|
+
onPress={() => onPress(date)}
|
|
55
|
+
accessibilityRole="button"
|
|
56
|
+
accessibilityLabel={accessibleDateLabel}
|
|
57
|
+
accessibilityState={{
|
|
58
|
+
selected: isEdge || isInRange,
|
|
59
|
+
disabled: isDisabled,
|
|
60
|
+
}}
|
|
61
|
+
style={[
|
|
62
|
+
styles.cellWrapper,
|
|
63
|
+
{
|
|
64
|
+
width: `${100 / 7}%`,
|
|
65
|
+
height: size,
|
|
66
|
+
},
|
|
67
|
+
]}
|
|
68
|
+
>
|
|
69
|
+
{/* Background connector for range */}
|
|
70
|
+
{isInRange && !isEdge && (
|
|
71
|
+
<View
|
|
72
|
+
style={[
|
|
73
|
+
styles.rangeRibbon,
|
|
74
|
+
{
|
|
75
|
+
backgroundColor: theme.rangeBetweenBackgroundColor,
|
|
76
|
+
height: size * 0.85,
|
|
77
|
+
},
|
|
78
|
+
]}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
|
|
82
|
+
{/* Half connector for Start date */}
|
|
83
|
+
{isRangeStart && cell.isRangeEnd === false && (
|
|
84
|
+
<View
|
|
85
|
+
style={[
|
|
86
|
+
styles.rangeRibbon,
|
|
87
|
+
styles.ribbonRightHalf,
|
|
88
|
+
{
|
|
89
|
+
backgroundColor: theme.rangeBetweenBackgroundColor,
|
|
90
|
+
height: size * 0.85,
|
|
91
|
+
},
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
|
|
96
|
+
{/* Half connector for End date */}
|
|
97
|
+
{isRangeEnd && cell.isRangeStart === false && (
|
|
98
|
+
<View
|
|
99
|
+
style={[
|
|
100
|
+
styles.rangeRibbon,
|
|
101
|
+
styles.ribbonLeftHalf,
|
|
102
|
+
{
|
|
103
|
+
backgroundColor: theme.rangeBetweenBackgroundColor,
|
|
104
|
+
height: size * 0.85,
|
|
105
|
+
},
|
|
106
|
+
]}
|
|
107
|
+
/>
|
|
108
|
+
)}
|
|
109
|
+
|
|
110
|
+
{/* Circle pill */}
|
|
111
|
+
<View
|
|
112
|
+
style={[
|
|
113
|
+
styles.cellCircle,
|
|
114
|
+
{
|
|
115
|
+
width: size * 0.85,
|
|
116
|
+
height: size * 0.85,
|
|
117
|
+
borderRadius: (size * 0.85) / 2,
|
|
118
|
+
backgroundColor: isEdge
|
|
119
|
+
? theme.selectedDayBackgroundColor
|
|
120
|
+
: 'transparent',
|
|
121
|
+
borderWidth: isToday && !isEdge ? 1.5 : 0,
|
|
122
|
+
borderColor: isToday && !isEdge ? theme.todayBorderColor : 'transparent',
|
|
123
|
+
opacity: !isCurrentMonth ? 0.45 : 1,
|
|
124
|
+
},
|
|
125
|
+
]}
|
|
126
|
+
>
|
|
127
|
+
<Text
|
|
128
|
+
style={[
|
|
129
|
+
styles.dayText,
|
|
130
|
+
{
|
|
131
|
+
color: getTextColor(),
|
|
132
|
+
fontSize: theme.fontSize.medium,
|
|
133
|
+
fontWeight: isEdge || isToday ? '700' : '400',
|
|
134
|
+
},
|
|
135
|
+
]}
|
|
136
|
+
>
|
|
137
|
+
{dayNumber}
|
|
138
|
+
</Text>
|
|
139
|
+
</View>
|
|
140
|
+
</TouchableOpacity>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const styles = StyleSheet.create({
|
|
145
|
+
cellWrapper: {
|
|
146
|
+
alignItems: 'center',
|
|
147
|
+
justifyContent: 'center',
|
|
148
|
+
position: 'relative',
|
|
149
|
+
paddingVertical: 2,
|
|
150
|
+
},
|
|
151
|
+
rangeRibbon: {
|
|
152
|
+
position: 'absolute',
|
|
153
|
+
left: 0,
|
|
154
|
+
right: 0,
|
|
155
|
+
top: '7.5%',
|
|
156
|
+
zIndex: 0,
|
|
157
|
+
},
|
|
158
|
+
ribbonRightHalf: {
|
|
159
|
+
left: '50%',
|
|
160
|
+
right: 0,
|
|
161
|
+
},
|
|
162
|
+
ribbonLeftHalf: {
|
|
163
|
+
left: 0,
|
|
164
|
+
right: '50%',
|
|
165
|
+
},
|
|
166
|
+
cellCircle: {
|
|
167
|
+
alignItems: 'center',
|
|
168
|
+
justifyContent: 'center',
|
|
169
|
+
zIndex: 1,
|
|
170
|
+
},
|
|
171
|
+
dayText: {
|
|
172
|
+
textAlign: 'center',
|
|
173
|
+
},
|
|
174
|
+
});
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from 'react';
|
|
2
|
+
import { View, Text, StyleSheet, StyleProp, ViewStyle, TouchableOpacity } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
DatePickerTheme,
|
|
5
|
+
DatePickerLocale,
|
|
6
|
+
DateRange,
|
|
7
|
+
DisabledDateCheck,
|
|
8
|
+
DateFormat,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
import { useCalendar } from '../../hooks/useCalendar';
|
|
11
|
+
import { useDateRange } from '../../hooks/useDateRange';
|
|
12
|
+
import { CalendarHeader } from '../Calendar/CalendarHeader';
|
|
13
|
+
import { WeekDays } from '../Calendar/WeekDays';
|
|
14
|
+
import { RangeDateCell } from './RangeDateCell';
|
|
15
|
+
import { Button } from '../common/Button';
|
|
16
|
+
import { DateValidationMessage } from '../ManualDateInput/DateValidationMessage';
|
|
17
|
+
import { formatDate } from '../../utils/dateFormatting';
|
|
18
|
+
|
|
19
|
+
export interface RangePickerProps {
|
|
20
|
+
startDate?: Date | null;
|
|
21
|
+
endDate?: Date | null;
|
|
22
|
+
defaultStartDate?: Date | null;
|
|
23
|
+
defaultEndDate?: Date | null;
|
|
24
|
+
onRangeChange?: (range: DateRange) => void;
|
|
25
|
+
maxRangeDays?: number;
|
|
26
|
+
format?: DateFormat;
|
|
27
|
+
theme: DatePickerTheme;
|
|
28
|
+
locale: DatePickerLocale;
|
|
29
|
+
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
30
|
+
minimumDate?: Date;
|
|
31
|
+
maximumDate?: Date;
|
|
32
|
+
disabledDates?: (Date | string)[] | DisabledDateCheck;
|
|
33
|
+
disabledWeekdays?: number[];
|
|
34
|
+
showActionButtons?: boolean;
|
|
35
|
+
onConfirm?: (range: DateRange) => void;
|
|
36
|
+
onCancel?: () => void;
|
|
37
|
+
style?: StyleProp<ViewStyle>;
|
|
38
|
+
onOpenMonthYearSelector?: () => void;
|
|
39
|
+
viewYear?: number;
|
|
40
|
+
viewMonth?: number;
|
|
41
|
+
onViewYearMonthChange?: (year: number, month: number) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const RangePicker: React.FC<RangePickerProps> = ({
|
|
45
|
+
startDate,
|
|
46
|
+
endDate,
|
|
47
|
+
defaultStartDate,
|
|
48
|
+
defaultEndDate,
|
|
49
|
+
onRangeChange,
|
|
50
|
+
maxRangeDays,
|
|
51
|
+
format = 'DD/MM/YYYY',
|
|
52
|
+
theme,
|
|
53
|
+
locale,
|
|
54
|
+
firstDayOfWeek = 0,
|
|
55
|
+
minimumDate,
|
|
56
|
+
maximumDate,
|
|
57
|
+
disabledDates,
|
|
58
|
+
disabledWeekdays,
|
|
59
|
+
showActionButtons = true,
|
|
60
|
+
onConfirm,
|
|
61
|
+
onCancel,
|
|
62
|
+
style,
|
|
63
|
+
onOpenMonthYearSelector,
|
|
64
|
+
viewYear,
|
|
65
|
+
viewMonth,
|
|
66
|
+
onViewYearMonthChange,
|
|
67
|
+
}) => {
|
|
68
|
+
const {
|
|
69
|
+
range,
|
|
70
|
+
selectDate,
|
|
71
|
+
clearRange,
|
|
72
|
+
validationResult,
|
|
73
|
+
isSelectingEndDate,
|
|
74
|
+
} = useDateRange({
|
|
75
|
+
startDate,
|
|
76
|
+
endDate,
|
|
77
|
+
defaultStartDate,
|
|
78
|
+
defaultEndDate,
|
|
79
|
+
onRangeChange,
|
|
80
|
+
maxRangeDays,
|
|
81
|
+
minimumDate,
|
|
82
|
+
maximumDate,
|
|
83
|
+
disabledDates,
|
|
84
|
+
disabledWeekdays,
|
|
85
|
+
locale,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const {
|
|
89
|
+
currentYear,
|
|
90
|
+
currentMonth,
|
|
91
|
+
currentMonthName,
|
|
92
|
+
days,
|
|
93
|
+
weekdays,
|
|
94
|
+
canGoPrevMonth,
|
|
95
|
+
canGoNextMonth,
|
|
96
|
+
goToPrevMonth,
|
|
97
|
+
goToNextMonth,
|
|
98
|
+
setMonth,
|
|
99
|
+
setYear,
|
|
100
|
+
jumpToDate,
|
|
101
|
+
} = useCalendar({
|
|
102
|
+
initialDate: range.startDate || new Date(),
|
|
103
|
+
range,
|
|
104
|
+
firstDayOfWeek,
|
|
105
|
+
minimumDate,
|
|
106
|
+
maximumDate,
|
|
107
|
+
disabledDates,
|
|
108
|
+
disabledWeekdays,
|
|
109
|
+
locale,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Synchronize calendar view with external viewYear & viewMonth when provided
|
|
113
|
+
const prevViewYearRef = useRef<number | undefined>(viewYear);
|
|
114
|
+
const prevViewMonthRef = useRef<number | undefined>(viewMonth);
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (viewYear !== undefined && viewMonth !== undefined) {
|
|
118
|
+
if (
|
|
119
|
+
viewYear !== prevViewYearRef.current ||
|
|
120
|
+
viewMonth !== prevViewMonthRef.current
|
|
121
|
+
) {
|
|
122
|
+
prevViewYearRef.current = viewYear;
|
|
123
|
+
prevViewMonthRef.current = viewMonth;
|
|
124
|
+
if (currentYear !== viewYear || currentMonth !== viewMonth) {
|
|
125
|
+
jumpToDate(new Date(viewYear, viewMonth, 1));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}, [viewYear, viewMonth, currentYear, currentMonth, jumpToDate]);
|
|
130
|
+
|
|
131
|
+
// Notify parent of view changes (e.g. prev/next month chevrons)
|
|
132
|
+
const onViewYearMonthChangeRef = useRef(onViewYearMonthChange);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
onViewYearMonthChangeRef.current = onViewYearMonthChange;
|
|
135
|
+
}, [onViewYearMonthChange]);
|
|
136
|
+
|
|
137
|
+
const prevReportedYearRef = useRef<number>(currentYear);
|
|
138
|
+
const prevReportedMonthRef = useRef<number>(currentMonth);
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (
|
|
142
|
+
currentYear !== prevReportedYearRef.current ||
|
|
143
|
+
currentMonth !== prevReportedMonthRef.current
|
|
144
|
+
) {
|
|
145
|
+
prevReportedYearRef.current = currentYear;
|
|
146
|
+
prevReportedMonthRef.current = currentMonth;
|
|
147
|
+
onViewYearMonthChangeRef.current?.(currentYear, currentMonth);
|
|
148
|
+
}
|
|
149
|
+
}, [currentYear, currentMonth]);
|
|
150
|
+
|
|
151
|
+
const formattedStart = range.startDate
|
|
152
|
+
? formatDate(range.startDate, format, locale)
|
|
153
|
+
: '--/--/----';
|
|
154
|
+
const formattedEnd = range.endDate
|
|
155
|
+
? formatDate(range.endDate, format, locale)
|
|
156
|
+
: '--/--/----';
|
|
157
|
+
|
|
158
|
+
const isSelectingEnd = isSelectingEndDate;
|
|
159
|
+
const isSelectingStart = !range.startDate || Boolean(range.startDate && range.endDate);
|
|
160
|
+
const defaultBorderColor = theme.borderColor === '#E2E8F0' ? '#CBD5E1' : theme.borderColor;
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<View
|
|
164
|
+
style={[
|
|
165
|
+
styles.container,
|
|
166
|
+
{
|
|
167
|
+
backgroundColor: theme.cardColor,
|
|
168
|
+
borderColor: theme.borderColor,
|
|
169
|
+
borderRadius: theme.borderRadius,
|
|
170
|
+
},
|
|
171
|
+
style,
|
|
172
|
+
]}
|
|
173
|
+
>
|
|
174
|
+
{/* Range Status Header */}
|
|
175
|
+
<View style={styles.rangeHeaderContainer}>
|
|
176
|
+
{/* Start Date Card Box */}
|
|
177
|
+
<TouchableOpacity
|
|
178
|
+
activeOpacity={0.8}
|
|
179
|
+
onPress={() => {
|
|
180
|
+
if (range.startDate && range.endDate) {
|
|
181
|
+
clearRange();
|
|
182
|
+
}
|
|
183
|
+
}}
|
|
184
|
+
style={[
|
|
185
|
+
styles.dateCard,
|
|
186
|
+
{
|
|
187
|
+
backgroundColor: isSelectingStart && !range.startDate
|
|
188
|
+
? `${theme.primaryColor}0C`
|
|
189
|
+
: (theme.cardColor || theme.surfaceColor),
|
|
190
|
+
borderColor: isSelectingStart && !range.startDate
|
|
191
|
+
? theme.primaryColor
|
|
192
|
+
: (range.startDate ? `${theme.primaryColor}80` : defaultBorderColor),
|
|
193
|
+
},
|
|
194
|
+
]}
|
|
195
|
+
>
|
|
196
|
+
<View style={styles.dateCardHeader}>
|
|
197
|
+
<View
|
|
198
|
+
style={[
|
|
199
|
+
styles.statusDot,
|
|
200
|
+
{
|
|
201
|
+
backgroundColor: range.startDate
|
|
202
|
+
? theme.primaryColor
|
|
203
|
+
: (isSelectingStart ? theme.primaryColor : theme.disabledTextColor),
|
|
204
|
+
},
|
|
205
|
+
]}
|
|
206
|
+
/>
|
|
207
|
+
<Text
|
|
208
|
+
style={[
|
|
209
|
+
styles.dateCardLabel,
|
|
210
|
+
{
|
|
211
|
+
color: range.startDate || isSelectingStart
|
|
212
|
+
? theme.primaryColor
|
|
213
|
+
: theme.secondaryTextColor,
|
|
214
|
+
},
|
|
215
|
+
]}
|
|
216
|
+
numberOfLines={1}
|
|
217
|
+
>
|
|
218
|
+
{locale.startDate}
|
|
219
|
+
</Text>
|
|
220
|
+
</View>
|
|
221
|
+
<Text
|
|
222
|
+
style={[
|
|
223
|
+
styles.dateCardValue,
|
|
224
|
+
{
|
|
225
|
+
color: range.startDate ? theme.textColor : theme.disabledTextColor,
|
|
226
|
+
fontSize: theme.fontSize.medium,
|
|
227
|
+
},
|
|
228
|
+
]}
|
|
229
|
+
numberOfLines={1}
|
|
230
|
+
>
|
|
231
|
+
{formattedStart}
|
|
232
|
+
</Text>
|
|
233
|
+
</TouchableOpacity>
|
|
234
|
+
|
|
235
|
+
{/* Center Arrow Connector */}
|
|
236
|
+
<View
|
|
237
|
+
style={[
|
|
238
|
+
styles.arrowBadge,
|
|
239
|
+
{
|
|
240
|
+
backgroundColor: `${theme.primaryColor}12`,
|
|
241
|
+
borderColor: `${theme.primaryColor}30`,
|
|
242
|
+
},
|
|
243
|
+
]}
|
|
244
|
+
>
|
|
245
|
+
<Text style={[styles.arrowText, { color: theme.primaryColor }]}>→</Text>
|
|
246
|
+
</View>
|
|
247
|
+
|
|
248
|
+
{/* End Date Card Box */}
|
|
249
|
+
<TouchableOpacity
|
|
250
|
+
activeOpacity={0.8}
|
|
251
|
+
style={[
|
|
252
|
+
styles.dateCard,
|
|
253
|
+
{
|
|
254
|
+
backgroundColor: isSelectingEnd
|
|
255
|
+
? `${theme.primaryColor}0C`
|
|
256
|
+
: (theme.cardColor || theme.surfaceColor),
|
|
257
|
+
borderColor: isSelectingEnd
|
|
258
|
+
? theme.primaryColor
|
|
259
|
+
: (range.endDate ? `${theme.primaryColor}80` : defaultBorderColor),
|
|
260
|
+
},
|
|
261
|
+
]}
|
|
262
|
+
>
|
|
263
|
+
<View style={styles.dateCardHeader}>
|
|
264
|
+
<View
|
|
265
|
+
style={[
|
|
266
|
+
styles.statusDot,
|
|
267
|
+
{
|
|
268
|
+
backgroundColor: range.endDate
|
|
269
|
+
? theme.primaryColor
|
|
270
|
+
: (isSelectingEnd ? theme.primaryColor : theme.disabledTextColor),
|
|
271
|
+
},
|
|
272
|
+
]}
|
|
273
|
+
/>
|
|
274
|
+
<Text
|
|
275
|
+
style={[
|
|
276
|
+
styles.dateCardLabel,
|
|
277
|
+
{
|
|
278
|
+
color: range.endDate || isSelectingEnd
|
|
279
|
+
? theme.primaryColor
|
|
280
|
+
: theme.secondaryTextColor,
|
|
281
|
+
},
|
|
282
|
+
]}
|
|
283
|
+
numberOfLines={1}
|
|
284
|
+
>
|
|
285
|
+
{locale.endDate}
|
|
286
|
+
</Text>
|
|
287
|
+
</View>
|
|
288
|
+
<Text
|
|
289
|
+
style={[
|
|
290
|
+
styles.dateCardValue,
|
|
291
|
+
{
|
|
292
|
+
color: range.endDate
|
|
293
|
+
? theme.textColor
|
|
294
|
+
: (isSelectingEnd ? theme.primaryColor : theme.disabledTextColor),
|
|
295
|
+
fontSize: theme.fontSize.medium,
|
|
296
|
+
fontWeight: isSelectingEnd ? '600' : '700',
|
|
297
|
+
},
|
|
298
|
+
]}
|
|
299
|
+
numberOfLines={1}
|
|
300
|
+
>
|
|
301
|
+
{isSelectingEnd ? locale.selectDate : formattedEnd}
|
|
302
|
+
</Text>
|
|
303
|
+
</TouchableOpacity>
|
|
304
|
+
</View>
|
|
305
|
+
|
|
306
|
+
<CalendarHeader
|
|
307
|
+
currentYear={currentYear}
|
|
308
|
+
currentMonth={currentMonth}
|
|
309
|
+
currentMonthName={currentMonthName}
|
|
310
|
+
theme={theme}
|
|
311
|
+
locale={locale}
|
|
312
|
+
canGoPrevMonth={canGoPrevMonth}
|
|
313
|
+
canGoNextMonth={canGoNextMonth}
|
|
314
|
+
onPrevMonth={goToPrevMonth}
|
|
315
|
+
onNextMonth={goToNextMonth}
|
|
316
|
+
onSelectMonth={setMonth}
|
|
317
|
+
onSelectYear={setYear}
|
|
318
|
+
onOpenMonthYearSelector={onOpenMonthYearSelector}
|
|
319
|
+
/>
|
|
320
|
+
|
|
321
|
+
<WeekDays weekdays={weekdays} theme={theme} />
|
|
322
|
+
|
|
323
|
+
<View style={styles.grid}>
|
|
324
|
+
{days.map((cell) => {
|
|
325
|
+
const key = `${cell.date.getFullYear()}-${cell.date.getMonth()}-${cell.date.getDate()}`;
|
|
326
|
+
return (
|
|
327
|
+
<RangeDateCell
|
|
328
|
+
key={key}
|
|
329
|
+
cell={cell}
|
|
330
|
+
theme={theme}
|
|
331
|
+
locale={locale}
|
|
332
|
+
onPress={selectDate}
|
|
333
|
+
/>
|
|
334
|
+
);
|
|
335
|
+
})}
|
|
336
|
+
</View>
|
|
337
|
+
|
|
338
|
+
<DateValidationMessage validation={validationResult} theme={theme} />
|
|
339
|
+
|
|
340
|
+
{showActionButtons && (
|
|
341
|
+
<View style={styles.actionsFooter}>
|
|
342
|
+
<View style={styles.leftActions}>
|
|
343
|
+
<Button
|
|
344
|
+
title={locale.today}
|
|
345
|
+
variant="text"
|
|
346
|
+
size="small"
|
|
347
|
+
theme={theme}
|
|
348
|
+
onPress={() => {
|
|
349
|
+
const today = new Date();
|
|
350
|
+
selectDate(today);
|
|
351
|
+
}}
|
|
352
|
+
/>
|
|
353
|
+
<Button
|
|
354
|
+
title={locale.clear}
|
|
355
|
+
variant="text"
|
|
356
|
+
size="small"
|
|
357
|
+
theme={theme}
|
|
358
|
+
onPress={clearRange}
|
|
359
|
+
/>
|
|
360
|
+
</View>
|
|
361
|
+
|
|
362
|
+
<View style={styles.rightActions}>
|
|
363
|
+
{onCancel && (
|
|
364
|
+
<Button
|
|
365
|
+
title={locale.cancel}
|
|
366
|
+
variant="outline"
|
|
367
|
+
size="small"
|
|
368
|
+
theme={theme}
|
|
369
|
+
onPress={onCancel}
|
|
370
|
+
style={styles.actionBtn}
|
|
371
|
+
/>
|
|
372
|
+
)}
|
|
373
|
+
{onConfirm && (
|
|
374
|
+
<Button
|
|
375
|
+
title={locale.apply}
|
|
376
|
+
variant="primary"
|
|
377
|
+
size="small"
|
|
378
|
+
theme={theme}
|
|
379
|
+
disabled={!range.startDate || !range.endDate || !validationResult.isValid}
|
|
380
|
+
onPress={() => onConfirm(range)}
|
|
381
|
+
style={styles.actionBtn}
|
|
382
|
+
/>
|
|
383
|
+
)}
|
|
384
|
+
</View>
|
|
385
|
+
</View>
|
|
386
|
+
)}
|
|
387
|
+
</View>
|
|
388
|
+
);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const styles = StyleSheet.create({
|
|
392
|
+
container: {
|
|
393
|
+
padding: 12,
|
|
394
|
+
borderWidth: 1,
|
|
395
|
+
overflow: 'hidden',
|
|
396
|
+
flexGrow: 1,
|
|
397
|
+
justifyContent: 'space-between',
|
|
398
|
+
},
|
|
399
|
+
rangeHeaderContainer: {
|
|
400
|
+
flexDirection: 'row',
|
|
401
|
+
alignItems: 'center',
|
|
402
|
+
justifyContent: 'space-between',
|
|
403
|
+
width: '100%',
|
|
404
|
+
paddingTop: 4,
|
|
405
|
+
paddingBottom: 2,
|
|
406
|
+
marginBottom: 10,
|
|
407
|
+
},
|
|
408
|
+
dateCard: {
|
|
409
|
+
flex: 1,
|
|
410
|
+
paddingVertical: 9,
|
|
411
|
+
paddingHorizontal: 11,
|
|
412
|
+
borderRadius: 12,
|
|
413
|
+
borderWidth: 1.5,
|
|
414
|
+
justifyContent: 'center',
|
|
415
|
+
shadowColor: '#000',
|
|
416
|
+
shadowOffset: { width: 0, height: 1 },
|
|
417
|
+
shadowOpacity: 0.04,
|
|
418
|
+
shadowRadius: 3,
|
|
419
|
+
|
|
420
|
+
},
|
|
421
|
+
dateCardHeader: {
|
|
422
|
+
flexDirection: 'row',
|
|
423
|
+
alignItems: 'center',
|
|
424
|
+
marginBottom: 4,
|
|
425
|
+
gap: 5,
|
|
426
|
+
},
|
|
427
|
+
statusDot: {
|
|
428
|
+
width: 6,
|
|
429
|
+
height: 6,
|
|
430
|
+
borderRadius: 3,
|
|
431
|
+
},
|
|
432
|
+
dateCardLabel: {
|
|
433
|
+
fontSize: 10,
|
|
434
|
+
fontWeight: '800',
|
|
435
|
+
textTransform: 'uppercase',
|
|
436
|
+
letterSpacing: 0.5,
|
|
437
|
+
},
|
|
438
|
+
dateCardValue: {
|
|
439
|
+
fontWeight: '700',
|
|
440
|
+
letterSpacing: 0.2,
|
|
441
|
+
},
|
|
442
|
+
arrowBadge: {
|
|
443
|
+
width: 28,
|
|
444
|
+
height: 28,
|
|
445
|
+
borderRadius: 14,
|
|
446
|
+
borderWidth: 1,
|
|
447
|
+
alignItems: 'center',
|
|
448
|
+
justifyContent: 'center',
|
|
449
|
+
marginHorizontal: 6,
|
|
450
|
+
},
|
|
451
|
+
arrowText: {
|
|
452
|
+
fontSize: 14,
|
|
453
|
+
fontWeight: '700',
|
|
454
|
+
},
|
|
455
|
+
grid: {
|
|
456
|
+
flexDirection: 'row',
|
|
457
|
+
flexWrap: 'wrap',
|
|
458
|
+
width: '100%',
|
|
459
|
+
paddingVertical: 6,
|
|
460
|
+
},
|
|
461
|
+
actionsFooter: {
|
|
462
|
+
flexDirection: 'row',
|
|
463
|
+
alignItems: 'center',
|
|
464
|
+
justifyContent: 'space-between',
|
|
465
|
+
paddingTop: 10,
|
|
466
|
+
paddingBottom: 2,
|
|
467
|
+
marginTop: 'auto',
|
|
468
|
+
borderTopWidth: 1,
|
|
469
|
+
borderTopColor: 'rgba(0,0,0,0.06)',
|
|
470
|
+
},
|
|
471
|
+
leftActions: {
|
|
472
|
+
flexDirection: 'row',
|
|
473
|
+
alignItems: 'center',
|
|
474
|
+
gap: 8,
|
|
475
|
+
},
|
|
476
|
+
rightActions: {
|
|
477
|
+
flexDirection: 'row',
|
|
478
|
+
alignItems: 'center',
|
|
479
|
+
gap: 8,
|
|
480
|
+
},
|
|
481
|
+
actionBtn: {
|
|
482
|
+
marginLeft: 0,
|
|
483
|
+
},
|
|
484
|
+
});
|