@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,265 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
DatePickerTheme,
|
|
5
|
+
DatePickerLocale,
|
|
6
|
+
ValidationResult,
|
|
7
|
+
DisabledDateCheck,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
import { getDaysInMonth, createLocalDate } from '../../utils/dateUtils';
|
|
10
|
+
import { validateDate } from '../../utils/dateValidation';
|
|
11
|
+
import { WheelColumn, WheelItem } from './WheelColumn';
|
|
12
|
+
import { Button } from '../common/Button';
|
|
13
|
+
import { DateValidationMessage } from '../ManualDateInput/DateValidationMessage';
|
|
14
|
+
|
|
15
|
+
export interface WheelPickerProps {
|
|
16
|
+
value: Date | null;
|
|
17
|
+
onChange: (date: Date | null) => void;
|
|
18
|
+
theme: DatePickerTheme;
|
|
19
|
+
locale: DatePickerLocale;
|
|
20
|
+
minimumDate?: Date;
|
|
21
|
+
maximumDate?: Date;
|
|
22
|
+
disabledDates?: (Date | string)[] | DisabledDateCheck;
|
|
23
|
+
disabledWeekdays?: number[];
|
|
24
|
+
minYear?: number;
|
|
25
|
+
maxYear?: number;
|
|
26
|
+
itemHeight?: number;
|
|
27
|
+
visibleItems?: number;
|
|
28
|
+
showActionButtons?: boolean;
|
|
29
|
+
showTodayButton?: boolean;
|
|
30
|
+
showClearButton?: boolean;
|
|
31
|
+
onConfirm?: (date: Date | null) => void;
|
|
32
|
+
onCancel?: () => void;
|
|
33
|
+
onClear?: () => void;
|
|
34
|
+
style?: StyleProp<ViewStyle>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const WheelPicker: React.FC<WheelPickerProps> = ({
|
|
38
|
+
value,
|
|
39
|
+
onChange,
|
|
40
|
+
theme,
|
|
41
|
+
locale,
|
|
42
|
+
minimumDate,
|
|
43
|
+
maximumDate,
|
|
44
|
+
disabledDates,
|
|
45
|
+
disabledWeekdays,
|
|
46
|
+
minYear = 1950,
|
|
47
|
+
maxYear = 2050,
|
|
48
|
+
itemHeight = 44,
|
|
49
|
+
visibleItems = 5,
|
|
50
|
+
showActionButtons = true,
|
|
51
|
+
showTodayButton = true,
|
|
52
|
+
showClearButton = true,
|
|
53
|
+
onConfirm,
|
|
54
|
+
onCancel,
|
|
55
|
+
onClear,
|
|
56
|
+
style,
|
|
57
|
+
}) => {
|
|
58
|
+
const currentDate = value || new Date();
|
|
59
|
+
const currentYear = currentDate.getFullYear();
|
|
60
|
+
const currentMonth = currentDate.getMonth(); // 0-indexed
|
|
61
|
+
const currentDay = currentDate.getDate();
|
|
62
|
+
|
|
63
|
+
// 1. Months column items
|
|
64
|
+
const monthItems: WheelItem[] = useMemo(() => {
|
|
65
|
+
return locale.months.map((name, index) => ({
|
|
66
|
+
label: name,
|
|
67
|
+
value: index,
|
|
68
|
+
}));
|
|
69
|
+
}, [locale.months]);
|
|
70
|
+
|
|
71
|
+
// 2. Years column items
|
|
72
|
+
const yearItems: WheelItem[] = useMemo(() => {
|
|
73
|
+
const list: WheelItem[] = [];
|
|
74
|
+
const min = minimumDate ? Math.max(minYear, minimumDate.getFullYear()) : minYear;
|
|
75
|
+
const max = maximumDate ? Math.min(maxYear, maximumDate.getFullYear()) : maxYear;
|
|
76
|
+
for (let y = min; y <= max; y++) {
|
|
77
|
+
list.push({ label: String(y), value: y });
|
|
78
|
+
}
|
|
79
|
+
return list;
|
|
80
|
+
}, [minYear, maxYear, minimumDate, maximumDate]);
|
|
81
|
+
|
|
82
|
+
// 3. Days column items dynamically computed based on selected Year and Month
|
|
83
|
+
const dayItems: WheelItem[] = useMemo(() => {
|
|
84
|
+
const daysCount = getDaysInMonth(currentYear, currentMonth);
|
|
85
|
+
const list: WheelItem[] = [];
|
|
86
|
+
for (let d = 1; d <= daysCount; d++) {
|
|
87
|
+
list.push({ label: String(d).padStart(2, '0'), value: d });
|
|
88
|
+
}
|
|
89
|
+
return list;
|
|
90
|
+
}, [currentYear, currentMonth]);
|
|
91
|
+
|
|
92
|
+
// Update date safely with day clamping
|
|
93
|
+
const updateDateComponents = (y: number, m: number, d: number) => {
|
|
94
|
+
const maxDays = getDaysInMonth(y, m);
|
|
95
|
+
const clampedDay = Math.min(d, maxDays);
|
|
96
|
+
const newDate = createLocalDate(y, m, clampedDay);
|
|
97
|
+
onChange(newDate);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const handleYearChange = (newYear: number) => {
|
|
101
|
+
updateDateComponents(newYear, currentMonth, currentDay);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const handleMonthChange = (newMonth: number) => {
|
|
105
|
+
updateDateComponents(currentYear, newMonth, currentDay);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handleDayChange = (newDay: number) => {
|
|
109
|
+
updateDateComponents(currentYear, currentMonth, newDay);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const validationResult: ValidationResult = useMemo(() => {
|
|
113
|
+
if (!value) return { isValid: true };
|
|
114
|
+
return validateDate(value, {
|
|
115
|
+
minimumDate,
|
|
116
|
+
maximumDate,
|
|
117
|
+
disabledDates,
|
|
118
|
+
disabledWeekdays,
|
|
119
|
+
locale,
|
|
120
|
+
});
|
|
121
|
+
}, [value, minimumDate, maximumDate, disabledDates, disabledWeekdays, locale]);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<View
|
|
125
|
+
style={[
|
|
126
|
+
styles.container,
|
|
127
|
+
{
|
|
128
|
+
backgroundColor: theme.cardColor,
|
|
129
|
+
borderColor: theme.borderColor,
|
|
130
|
+
borderRadius: theme.borderRadius,
|
|
131
|
+
},
|
|
132
|
+
style,
|
|
133
|
+
]}
|
|
134
|
+
>
|
|
135
|
+
<View style={styles.columnsRow}>
|
|
136
|
+
{/* Day Column */}
|
|
137
|
+
<WheelColumn
|
|
138
|
+
items={dayItems}
|
|
139
|
+
selectedValue={currentDay}
|
|
140
|
+
onValueChange={handleDayChange}
|
|
141
|
+
theme={theme}
|
|
142
|
+
itemHeight={itemHeight}
|
|
143
|
+
visibleItems={visibleItems}
|
|
144
|
+
accessibilityLabel={locale.dayLabel}
|
|
145
|
+
/>
|
|
146
|
+
|
|
147
|
+
{/* Month Column */}
|
|
148
|
+
<WheelColumn
|
|
149
|
+
items={monthItems}
|
|
150
|
+
selectedValue={currentMonth}
|
|
151
|
+
onValueChange={handleMonthChange}
|
|
152
|
+
theme={theme}
|
|
153
|
+
itemHeight={itemHeight}
|
|
154
|
+
visibleItems={visibleItems}
|
|
155
|
+
accessibilityLabel={locale.monthLabel}
|
|
156
|
+
/>
|
|
157
|
+
|
|
158
|
+
{/* Year Column */}
|
|
159
|
+
<WheelColumn
|
|
160
|
+
items={yearItems}
|
|
161
|
+
selectedValue={currentYear}
|
|
162
|
+
onValueChange={handleYearChange}
|
|
163
|
+
theme={theme}
|
|
164
|
+
itemHeight={itemHeight}
|
|
165
|
+
visibleItems={visibleItems}
|
|
166
|
+
accessibilityLabel={locale.yearLabel}
|
|
167
|
+
/>
|
|
168
|
+
</View>
|
|
169
|
+
|
|
170
|
+
<DateValidationMessage validation={validationResult} theme={theme} />
|
|
171
|
+
|
|
172
|
+
{showActionButtons && (
|
|
173
|
+
<View style={styles.actionsFooter}>
|
|
174
|
+
<View style={styles.leftActions}>
|
|
175
|
+
{showTodayButton && (
|
|
176
|
+
<Button
|
|
177
|
+
title={locale.today}
|
|
178
|
+
variant="text"
|
|
179
|
+
size="small"
|
|
180
|
+
theme={theme}
|
|
181
|
+
onPress={() => onChange(new Date())}
|
|
182
|
+
/>
|
|
183
|
+
)}
|
|
184
|
+
{showClearButton && (
|
|
185
|
+
<Button
|
|
186
|
+
title={locale.clear}
|
|
187
|
+
variant="text"
|
|
188
|
+
size="small"
|
|
189
|
+
theme={theme}
|
|
190
|
+
onPress={() => {
|
|
191
|
+
onChange(null);
|
|
192
|
+
onClear?.();
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
)}
|
|
196
|
+
</View>
|
|
197
|
+
|
|
198
|
+
<View style={styles.rightActions}>
|
|
199
|
+
{onCancel && (
|
|
200
|
+
<Button
|
|
201
|
+
title={locale.cancel}
|
|
202
|
+
variant="outline"
|
|
203
|
+
size="small"
|
|
204
|
+
theme={theme}
|
|
205
|
+
onPress={onCancel}
|
|
206
|
+
style={styles.actionBtn}
|
|
207
|
+
/>
|
|
208
|
+
)}
|
|
209
|
+
{onConfirm && (
|
|
210
|
+
<Button
|
|
211
|
+
title={locale.confirm}
|
|
212
|
+
variant="primary"
|
|
213
|
+
size="small"
|
|
214
|
+
theme={theme}
|
|
215
|
+
disabled={!validationResult.isValid}
|
|
216
|
+
onPress={() => onConfirm(value)}
|
|
217
|
+
style={styles.actionBtn}
|
|
218
|
+
/>
|
|
219
|
+
)}
|
|
220
|
+
</View>
|
|
221
|
+
</View>
|
|
222
|
+
)}
|
|
223
|
+
</View>
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const styles = StyleSheet.create({
|
|
228
|
+
container: {
|
|
229
|
+
padding: 12,
|
|
230
|
+
borderWidth: 1,
|
|
231
|
+
overflow: 'hidden',
|
|
232
|
+
flexGrow: 1,
|
|
233
|
+
justifyContent: 'space-between',
|
|
234
|
+
},
|
|
235
|
+
columnsRow: {
|
|
236
|
+
flexDirection: 'row',
|
|
237
|
+
justifyContent: 'space-between',
|
|
238
|
+
width: '100%',
|
|
239
|
+
flex: 1,
|
|
240
|
+
alignItems: 'center',
|
|
241
|
+
paddingVertical: 12,
|
|
242
|
+
},
|
|
243
|
+
actionsFooter: {
|
|
244
|
+
flexDirection: 'row',
|
|
245
|
+
alignItems: 'center',
|
|
246
|
+
justifyContent: 'space-between',
|
|
247
|
+
paddingTop: 12,
|
|
248
|
+
marginTop: 'auto',
|
|
249
|
+
borderTopWidth: 1,
|
|
250
|
+
borderTopColor: 'rgba(0,0,0,0.06)',
|
|
251
|
+
},
|
|
252
|
+
leftActions: {
|
|
253
|
+
flexDirection: 'row',
|
|
254
|
+
alignItems: 'center',
|
|
255
|
+
gap: 8,
|
|
256
|
+
},
|
|
257
|
+
rightActions: {
|
|
258
|
+
flexDirection: 'row',
|
|
259
|
+
alignItems: 'center',
|
|
260
|
+
gap: 8,
|
|
261
|
+
},
|
|
262
|
+
actionBtn: {
|
|
263
|
+
marginLeft: 0,
|
|
264
|
+
},
|
|
265
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
TouchableOpacity,
|
|
4
|
+
Text,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
StyleProp,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
TextStyle,
|
|
9
|
+
AccessibilityRole,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import type { DatePickerTheme } from '../../types';
|
|
12
|
+
|
|
13
|
+
export interface ButtonProps {
|
|
14
|
+
title: string;
|
|
15
|
+
onPress: () => void;
|
|
16
|
+
theme: DatePickerTheme;
|
|
17
|
+
variant?: 'primary' | 'secondary' | 'outline' | 'text';
|
|
18
|
+
size?: 'small' | 'medium';
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
style?: StyleProp<ViewStyle>;
|
|
21
|
+
textStyle?: StyleProp<TextStyle>;
|
|
22
|
+
accessibilityLabel?: string;
|
|
23
|
+
accessibilityRole?: AccessibilityRole;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Button: React.FC<ButtonProps> = ({
|
|
27
|
+
title,
|
|
28
|
+
onPress,
|
|
29
|
+
theme,
|
|
30
|
+
variant = 'primary',
|
|
31
|
+
size = 'medium',
|
|
32
|
+
disabled = false,
|
|
33
|
+
style,
|
|
34
|
+
textStyle,
|
|
35
|
+
accessibilityLabel,
|
|
36
|
+
accessibilityRole = 'button',
|
|
37
|
+
}) => {
|
|
38
|
+
const isSmall = size === 'small';
|
|
39
|
+
|
|
40
|
+
const getContainerStyle = (): ViewStyle => {
|
|
41
|
+
switch (variant) {
|
|
42
|
+
case 'primary':
|
|
43
|
+
return {
|
|
44
|
+
backgroundColor: disabled ? theme.disabledTextColor : theme.primaryColor,
|
|
45
|
+
borderColor: 'transparent',
|
|
46
|
+
};
|
|
47
|
+
case 'secondary':
|
|
48
|
+
return {
|
|
49
|
+
backgroundColor: theme.surfaceColor,
|
|
50
|
+
borderColor: theme.borderColor,
|
|
51
|
+
borderWidth: 1,
|
|
52
|
+
};
|
|
53
|
+
case 'outline':
|
|
54
|
+
return {
|
|
55
|
+
backgroundColor: 'transparent',
|
|
56
|
+
borderColor: disabled ? theme.disabledTextColor : theme.primaryColor,
|
|
57
|
+
borderWidth: 1,
|
|
58
|
+
};
|
|
59
|
+
case 'text':
|
|
60
|
+
return {
|
|
61
|
+
backgroundColor: 'transparent',
|
|
62
|
+
borderColor: 'transparent',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const getTextColor = (): string => {
|
|
68
|
+
if (disabled) return theme.disabledTextColor;
|
|
69
|
+
switch (variant) {
|
|
70
|
+
case 'primary':
|
|
71
|
+
return theme.primaryTextColor;
|
|
72
|
+
case 'secondary':
|
|
73
|
+
return theme.textColor;
|
|
74
|
+
case 'outline':
|
|
75
|
+
case 'text':
|
|
76
|
+
return theme.primaryColor;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<TouchableOpacity
|
|
82
|
+
activeOpacity={0.7}
|
|
83
|
+
disabled={disabled}
|
|
84
|
+
onPress={onPress}
|
|
85
|
+
accessibilityRole={accessibilityRole}
|
|
86
|
+
accessibilityLabel={accessibilityLabel || title}
|
|
87
|
+
accessibilityState={{ disabled }}
|
|
88
|
+
style={[
|
|
89
|
+
styles.base,
|
|
90
|
+
{
|
|
91
|
+
borderRadius: Math.max(theme.borderRadius - 4, 8),
|
|
92
|
+
paddingVertical: isSmall ? 6 : 10,
|
|
93
|
+
paddingHorizontal: isSmall ? 12 : 16,
|
|
94
|
+
},
|
|
95
|
+
getContainerStyle(),
|
|
96
|
+
style,
|
|
97
|
+
]}
|
|
98
|
+
>
|
|
99
|
+
<Text
|
|
100
|
+
style={[
|
|
101
|
+
styles.text,
|
|
102
|
+
{
|
|
103
|
+
color: getTextColor(),
|
|
104
|
+
fontSize: isSmall ? theme.fontSize.small : theme.fontSize.medium,
|
|
105
|
+
},
|
|
106
|
+
textStyle,
|
|
107
|
+
]}
|
|
108
|
+
>
|
|
109
|
+
{title}
|
|
110
|
+
</Text>
|
|
111
|
+
</TouchableOpacity>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const styles = StyleSheet.create({
|
|
116
|
+
base: {
|
|
117
|
+
alignItems: 'center',
|
|
118
|
+
justifyContent: 'center',
|
|
119
|
+
flexDirection: 'row',
|
|
120
|
+
},
|
|
121
|
+
text: {
|
|
122
|
+
fontWeight: '600',
|
|
123
|
+
textAlign: 'center',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
TouchableOpacity,
|
|
4
|
+
View,
|
|
5
|
+
Text,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
StyleProp,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
|
|
11
|
+
export type IconType =
|
|
12
|
+
| 'chevron-left'
|
|
13
|
+
| 'chevron-right'
|
|
14
|
+
| 'close'
|
|
15
|
+
| 'calendar'
|
|
16
|
+
| 'keyboard'
|
|
17
|
+
| 'check';
|
|
18
|
+
|
|
19
|
+
export interface IconButtonProps {
|
|
20
|
+
icon: IconType;
|
|
21
|
+
onPress: () => void;
|
|
22
|
+
size?: number;
|
|
23
|
+
color?: string;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
style?: StyleProp<ViewStyle>;
|
|
26
|
+
accessibilityLabel?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const IconButton: React.FC<IconButtonProps> = ({
|
|
30
|
+
icon,
|
|
31
|
+
onPress,
|
|
32
|
+
size = 20,
|
|
33
|
+
color = '#2563EB',
|
|
34
|
+
disabled = false,
|
|
35
|
+
style,
|
|
36
|
+
accessibilityLabel,
|
|
37
|
+
}) => {
|
|
38
|
+
const renderIcon = () => {
|
|
39
|
+
switch (icon) {
|
|
40
|
+
case 'chevron-left':
|
|
41
|
+
return (
|
|
42
|
+
<View
|
|
43
|
+
style={[
|
|
44
|
+
styles.chevron,
|
|
45
|
+
{
|
|
46
|
+
width: size * 0.45,
|
|
47
|
+
height: size * 0.45,
|
|
48
|
+
borderColor: color,
|
|
49
|
+
borderLeftWidth: 2,
|
|
50
|
+
borderBottomWidth: 2,
|
|
51
|
+
transform: [{ rotate: '45deg' }, { translateX: 1 }],
|
|
52
|
+
},
|
|
53
|
+
]}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
case 'chevron-right':
|
|
57
|
+
return (
|
|
58
|
+
<View
|
|
59
|
+
style={[
|
|
60
|
+
styles.chevron,
|
|
61
|
+
{
|
|
62
|
+
width: size * 0.45,
|
|
63
|
+
height: size * 0.45,
|
|
64
|
+
borderColor: color,
|
|
65
|
+
borderTopWidth: 2,
|
|
66
|
+
borderRightWidth: 2,
|
|
67
|
+
transform: [{ rotate: '45deg' }, { translateX: -1 }],
|
|
68
|
+
},
|
|
69
|
+
]}
|
|
70
|
+
/>
|
|
71
|
+
);
|
|
72
|
+
case 'close':
|
|
73
|
+
return (
|
|
74
|
+
<View style={[styles.center, { width: size, height: size }]}>
|
|
75
|
+
<View
|
|
76
|
+
style={[
|
|
77
|
+
styles.crossLine,
|
|
78
|
+
{
|
|
79
|
+
width: size * 0.7,
|
|
80
|
+
backgroundColor: color,
|
|
81
|
+
transform: [{ rotate: '45deg' }],
|
|
82
|
+
},
|
|
83
|
+
]}
|
|
84
|
+
/>
|
|
85
|
+
<View
|
|
86
|
+
style={[
|
|
87
|
+
styles.crossLine,
|
|
88
|
+
{
|
|
89
|
+
width: size * 0.7,
|
|
90
|
+
backgroundColor: color,
|
|
91
|
+
transform: [{ rotate: '-45deg' }],
|
|
92
|
+
},
|
|
93
|
+
]}
|
|
94
|
+
/>
|
|
95
|
+
</View>
|
|
96
|
+
);
|
|
97
|
+
case 'calendar':
|
|
98
|
+
return (
|
|
99
|
+
<View
|
|
100
|
+
style={[
|
|
101
|
+
styles.calendarBox,
|
|
102
|
+
{
|
|
103
|
+
width: size * 0.9,
|
|
104
|
+
height: size * 0.9,
|
|
105
|
+
borderColor: color,
|
|
106
|
+
},
|
|
107
|
+
]}
|
|
108
|
+
>
|
|
109
|
+
<View style={[styles.calendarTop, { backgroundColor: color }]} />
|
|
110
|
+
<View style={styles.calendarGrid}>
|
|
111
|
+
<View style={[styles.calendarDot, { backgroundColor: color }]} />
|
|
112
|
+
<View style={[styles.calendarDot, { backgroundColor: color }]} />
|
|
113
|
+
<View style={[styles.calendarDot, { backgroundColor: color }]} />
|
|
114
|
+
</View>
|
|
115
|
+
</View>
|
|
116
|
+
);
|
|
117
|
+
case 'keyboard':
|
|
118
|
+
return (
|
|
119
|
+
<View
|
|
120
|
+
style={[
|
|
121
|
+
styles.keyboardBox,
|
|
122
|
+
{
|
|
123
|
+
width: size,
|
|
124
|
+
height: size * 0.7,
|
|
125
|
+
borderColor: color,
|
|
126
|
+
},
|
|
127
|
+
]}
|
|
128
|
+
>
|
|
129
|
+
<View style={styles.keyboardRow}>
|
|
130
|
+
<View style={[styles.keyDot, { backgroundColor: color }]} />
|
|
131
|
+
<View style={[styles.keyDot, { backgroundColor: color }]} />
|
|
132
|
+
<View style={[styles.keyDot, { backgroundColor: color }]} />
|
|
133
|
+
</View>
|
|
134
|
+
<View
|
|
135
|
+
style={[
|
|
136
|
+
styles.spacebar,
|
|
137
|
+
{
|
|
138
|
+
backgroundColor: color,
|
|
139
|
+
width: size * 0.5,
|
|
140
|
+
},
|
|
141
|
+
]}
|
|
142
|
+
/>
|
|
143
|
+
</View>
|
|
144
|
+
);
|
|
145
|
+
case 'check':
|
|
146
|
+
return (
|
|
147
|
+
<Text style={{ color, fontSize: size, fontWeight: '700' }}>✓</Text>
|
|
148
|
+
);
|
|
149
|
+
default:
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<TouchableOpacity
|
|
156
|
+
activeOpacity={0.6}
|
|
157
|
+
disabled={disabled}
|
|
158
|
+
onPress={onPress}
|
|
159
|
+
accessibilityRole="button"
|
|
160
|
+
accessibilityLabel={accessibilityLabel || icon}
|
|
161
|
+
accessibilityState={{ disabled }}
|
|
162
|
+
hitSlop={{ top: 12, bottom: 12, left: 12, right: 12 }}
|
|
163
|
+
style={[
|
|
164
|
+
styles.button,
|
|
165
|
+
{
|
|
166
|
+
width: Math.max(size * 1.6, 36),
|
|
167
|
+
height: Math.max(size * 1.6, 36),
|
|
168
|
+
opacity: disabled ? 0.4 : 1,
|
|
169
|
+
},
|
|
170
|
+
style,
|
|
171
|
+
]}
|
|
172
|
+
>
|
|
173
|
+
{renderIcon()}
|
|
174
|
+
</TouchableOpacity>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const styles = StyleSheet.create({
|
|
179
|
+
button: {
|
|
180
|
+
alignItems: 'center',
|
|
181
|
+
justifyContent: 'center',
|
|
182
|
+
},
|
|
183
|
+
chevron: {
|
|
184
|
+
borderRadius: 1,
|
|
185
|
+
},
|
|
186
|
+
center: {
|
|
187
|
+
alignItems: 'center',
|
|
188
|
+
justifyContent: 'center',
|
|
189
|
+
},
|
|
190
|
+
crossLine: {
|
|
191
|
+
position: 'absolute',
|
|
192
|
+
height: 2,
|
|
193
|
+
borderRadius: 1,
|
|
194
|
+
},
|
|
195
|
+
calendarBox: {
|
|
196
|
+
borderWidth: 1.5,
|
|
197
|
+
borderRadius: 4,
|
|
198
|
+
overflow: 'hidden',
|
|
199
|
+
justifyContent: 'space-between',
|
|
200
|
+
paddingBottom: 2,
|
|
201
|
+
},
|
|
202
|
+
calendarTop: {
|
|
203
|
+
height: '25%',
|
|
204
|
+
width: '100%',
|
|
205
|
+
},
|
|
206
|
+
calendarGrid: {
|
|
207
|
+
flexDirection: 'row',
|
|
208
|
+
justifyContent: 'space-around',
|
|
209
|
+
paddingHorizontal: 2,
|
|
210
|
+
},
|
|
211
|
+
calendarDot: {
|
|
212
|
+
width: 2.5,
|
|
213
|
+
height: 2.5,
|
|
214
|
+
borderRadius: 1,
|
|
215
|
+
},
|
|
216
|
+
keyboardBox: {
|
|
217
|
+
borderWidth: 1.5,
|
|
218
|
+
borderRadius: 3,
|
|
219
|
+
padding: 2,
|
|
220
|
+
justifyContent: 'space-between',
|
|
221
|
+
alignItems: 'center',
|
|
222
|
+
},
|
|
223
|
+
keyboardRow: {
|
|
224
|
+
flexDirection: 'row',
|
|
225
|
+
justifyContent: 'space-around',
|
|
226
|
+
width: '100%',
|
|
227
|
+
},
|
|
228
|
+
keyDot: {
|
|
229
|
+
width: 2.5,
|
|
230
|
+
height: 2.5,
|
|
231
|
+
borderRadius: 1,
|
|
232
|
+
},
|
|
233
|
+
spacebar: {
|
|
234
|
+
height: 1.5,
|
|
235
|
+
borderRadius: 1,
|
|
236
|
+
},
|
|
237
|
+
});
|