@izonnet-web-solution/react-native-date-time-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/DateTimePickerKit.podspec +22 -0
- package/LICENSE +20 -0
- package/README.md +532 -2
- package/android/build.gradle +36 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/datetimepickerkit/DatePickerHelper.kt +185 -0
- package/android/src/main/java/com/datetimepickerkit/DateTimePickerHelper.kt +214 -0
- package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitModule.kt +258 -0
- package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitPackage.kt +30 -0
- package/android/src/main/java/com/datetimepickerkit/TimePickerHelper.kt +208 -0
- package/ios/DateTimePickerKit.h +11 -0
- package/ios/DateTimePickerKit.mm +84 -0
- package/ios/DateTimePickerModule.swift +474 -0
- package/lib/module/NativeDateTimePickerKit.js +5 -0
- package/lib/module/NativeDateTimePickerKit.js.map +1 -0
- package/lib/module/components/CalendarPicker.js +414 -0
- package/lib/module/components/CalendarPicker.js.map +1 -0
- package/lib/module/components/ClockPicker.js +273 -0
- package/lib/module/components/ClockPicker.js.map +1 -0
- package/lib/module/components/DatePicker.js +174 -0
- package/lib/module/components/DatePicker.js.map +1 -0
- package/lib/module/components/DateRangePicker.js +154 -0
- package/lib/module/components/DateRangePicker.js.map +1 -0
- package/lib/module/components/DateTimePicker.js +598 -0
- package/lib/module/components/DateTimePicker.js.map +1 -0
- package/lib/module/components/MonthPicker.js +145 -0
- package/lib/module/components/MonthPicker.js.map +1 -0
- package/lib/module/components/TimePicker.js +140 -0
- package/lib/module/components/TimePicker.js.map +1 -0
- package/lib/module/components/TimeSlotPicker.js +118 -0
- package/lib/module/components/TimeSlotPicker.js.map +1 -0
- package/lib/module/components/WheelPicker.js +138 -0
- package/lib/module/components/WheelPicker.js.map +1 -0
- package/lib/module/components/YearPicker.js +151 -0
- package/lib/module/components/YearPicker.js.map +1 -0
- package/lib/module/components/common/ModalWrapper.js +130 -0
- package/lib/module/components/common/ModalWrapper.js.map +1 -0
- package/lib/module/components/common/PickerHeader.js +82 -0
- package/lib/module/components/common/PickerHeader.js.map +1 -0
- package/lib/module/components/common/PresetsBar.js +66 -0
- package/lib/module/components/common/PresetsBar.js.map +1 -0
- package/lib/module/errors/DateTimePickerError.js +12 -0
- package/lib/module/errors/DateTimePickerError.js.map +1 -0
- package/lib/module/hooks/useDateTimePicker.js +73 -0
- package/lib/module/hooks/useDateTimePicker.js.map +1 -0
- package/lib/module/index.js +40 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/localization/index.js +6 -0
- package/lib/module/localization/index.js.map +1 -0
- package/lib/module/localization/locales.js +186 -0
- package/lib/module/localization/locales.js.map +1 -0
- package/lib/module/localization/types.js +2 -0
- package/lib/module/localization/types.js.map +1 -0
- package/lib/module/localization/useLocale.js +126 -0
- package/lib/module/localization/useLocale.js.map +1 -0
- package/lib/module/native/NativeDateTimePicker.js +110 -0
- package/lib/module/native/NativeDateTimePicker.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/presets/datePresets.js +75 -0
- package/lib/module/presets/datePresets.js.map +1 -0
- package/lib/module/presets/index.js +4 -0
- package/lib/module/presets/index.js.map +1 -0
- package/lib/module/slots/index.js +4 -0
- package/lib/module/slots/index.js.map +1 -0
- package/lib/module/slots/timeSlots.js +59 -0
- package/lib/module/slots/timeSlots.js.map +1 -0
- package/lib/module/theme/defaultTheme.js +91 -0
- package/lib/module/theme/defaultTheme.js.map +1 -0
- package/lib/module/theme/index.js +6 -0
- package/lib/module/theme/index.js.map +1 -0
- package/lib/module/theme/types.js +2 -0
- package/lib/module/theme/types.js.map +1 -0
- package/lib/module/theme/useTheme.js +59 -0
- package/lib/module/theme/useTheme.js.map +1 -0
- package/lib/module/types/events.js +4 -0
- package/lib/module/types/events.js.map +1 -0
- package/lib/module/types/index.js +7 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/native.js +2 -0
- package/lib/module/types/native.js.map +1 -0
- package/lib/module/types/presentation.js +2 -0
- package/lib/module/types/presentation.js.map +1 -0
- package/lib/module/types/props.js +4 -0
- package/lib/module/types/props.js.map +1 -0
- package/lib/module/utils/constants.js +14 -0
- package/lib/module/utils/constants.js.map +1 -0
- package/lib/module/utils/dateConversion.js +115 -0
- package/lib/module/utils/dateConversion.js.map +1 -0
- package/lib/module/utils/dateFormatting.js +102 -0
- package/lib/module/utils/dateFormatting.js.map +1 -0
- package/lib/module/utils/dateValidation.js +161 -0
- package/lib/module/utils/dateValidation.js.map +1 -0
- package/lib/module/utils/index.js +7 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeDateTimePickerKit.d.ts +17 -0
- package/lib/typescript/src/NativeDateTimePickerKit.d.ts.map +1 -0
- package/lib/typescript/src/components/CalendarPicker.d.ts +35 -0
- package/lib/typescript/src/components/CalendarPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/ClockPicker.d.ts +22 -0
- package/lib/typescript/src/components/ClockPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/DatePicker.d.ts +32 -0
- package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/DateRangePicker.d.ts +41 -0
- package/lib/typescript/src/components/DateRangePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/DateTimePicker.d.ts +7 -0
- package/lib/typescript/src/components/DateTimePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/MonthPicker.d.ts +21 -0
- package/lib/typescript/src/components/MonthPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/TimePicker.d.ts +25 -0
- package/lib/typescript/src/components/TimePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/TimeSlotPicker.d.ts +18 -0
- package/lib/typescript/src/components/TimeSlotPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/WheelPicker.d.ts +17 -0
- package/lib/typescript/src/components/WheelPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/YearPicker.d.ts +14 -0
- package/lib/typescript/src/components/YearPicker.d.ts.map +1 -0
- package/lib/typescript/src/components/common/ModalWrapper.d.ts +10 -0
- package/lib/typescript/src/components/common/ModalWrapper.d.ts.map +1 -0
- package/lib/typescript/src/components/common/PickerHeader.d.ts +13 -0
- package/lib/typescript/src/components/common/PickerHeader.d.ts.map +1 -0
- package/lib/typescript/src/components/common/PresetsBar.d.ts +12 -0
- package/lib/typescript/src/components/common/PresetsBar.d.ts.map +1 -0
- package/lib/typescript/src/errors/DateTimePickerError.d.ts +7 -0
- package/lib/typescript/src/errors/DateTimePickerError.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDateTimePicker.d.ts +17 -0
- package/lib/typescript/src/hooks/useDateTimePicker.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +23 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/localization/index.d.ts +4 -0
- package/lib/typescript/src/localization/index.d.ts.map +1 -0
- package/lib/typescript/src/localization/locales.d.ts +12 -0
- package/lib/typescript/src/localization/locales.d.ts.map +1 -0
- package/lib/typescript/src/localization/types.d.ts +23 -0
- package/lib/typescript/src/localization/types.d.ts.map +1 -0
- package/lib/typescript/src/localization/useLocale.d.ts +31 -0
- package/lib/typescript/src/localization/useLocale.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeDateTimePicker.d.ts +14 -0
- package/lib/typescript/src/native/NativeDateTimePicker.d.ts.map +1 -0
- package/lib/typescript/src/presets/datePresets.d.ts +8 -0
- package/lib/typescript/src/presets/datePresets.d.ts.map +1 -0
- package/lib/typescript/src/presets/index.d.ts +2 -0
- package/lib/typescript/src/presets/index.d.ts.map +1 -0
- package/lib/typescript/src/slots/index.d.ts +2 -0
- package/lib/typescript/src/slots/index.d.ts.map +1 -0
- package/lib/typescript/src/slots/timeSlots.d.ts +18 -0
- package/lib/typescript/src/slots/timeSlots.d.ts.map +1 -0
- package/lib/typescript/src/theme/defaultTheme.d.ts +9 -0
- package/lib/typescript/src/theme/defaultTheme.d.ts.map +1 -0
- package/lib/typescript/src/theme/index.d.ts +4 -0
- package/lib/typescript/src/theme/index.d.ts.map +1 -0
- package/lib/typescript/src/theme/types.d.ts +65 -0
- package/lib/typescript/src/theme/types.d.ts.map +1 -0
- package/lib/typescript/src/theme/useTheme.d.ts +4 -0
- package/lib/typescript/src/theme/useTheme.d.ts.map +1 -0
- package/lib/typescript/src/types/events.d.ts +8 -0
- package/lib/typescript/src/types/events.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +5 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/types/native.d.ts +26 -0
- package/lib/typescript/src/types/native.d.ts.map +1 -0
- package/lib/typescript/src/types/presentation.d.ts +19 -0
- package/lib/typescript/src/types/presentation.d.ts.map +1 -0
- package/lib/typescript/src/types/props.d.ts +68 -0
- package/lib/typescript/src/types/props.d.ts.map +1 -0
- package/lib/typescript/src/utils/constants.d.ts +12 -0
- package/lib/typescript/src/utils/constants.d.ts.map +1 -0
- package/lib/typescript/src/utils/dateConversion.d.ts +27 -0
- package/lib/typescript/src/utils/dateConversion.d.ts.map +1 -0
- package/lib/typescript/src/utils/dateFormatting.d.ts +8 -0
- package/lib/typescript/src/utils/dateFormatting.d.ts.map +1 -0
- package/lib/typescript/src/utils/dateValidation.d.ts +46 -0
- package/lib/typescript/src/utils/dateValidation.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +5 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +183 -4
- package/src/NativeDateTimePickerKit.ts +19 -0
- package/src/components/CalendarPicker.tsx +593 -0
- package/src/components/ClockPicker.tsx +403 -0
- package/src/components/DatePicker.tsx +246 -0
- package/src/components/DateRangePicker.tsx +226 -0
- package/src/components/DateTimePicker.tsx +862 -0
- package/src/components/MonthPicker.tsx +216 -0
- package/src/components/TimePicker.tsx +190 -0
- package/src/components/TimeSlotPicker.tsx +163 -0
- package/src/components/WheelPicker.tsx +199 -0
- package/src/components/YearPicker.tsx +228 -0
- package/src/components/common/ModalWrapper.tsx +184 -0
- package/src/components/common/PickerHeader.tsx +121 -0
- package/src/components/common/PresetsBar.tsx +104 -0
- package/src/errors/DateTimePickerError.ts +29 -0
- package/src/hooks/useDateTimePicker.ts +100 -0
- package/src/index.tsx +92 -0
- package/src/localization/index.ts +3 -0
- package/src/localization/locales.ts +499 -0
- package/src/localization/types.ts +21 -0
- package/src/localization/useLocale.ts +137 -0
- package/src/native/NativeDateTimePicker.ts +154 -0
- package/src/presets/datePresets.ts +97 -0
- package/src/presets/index.ts +1 -0
- package/src/slots/index.ts +1 -0
- package/src/slots/timeSlots.ts +89 -0
- package/src/theme/defaultTheme.ts +102 -0
- package/src/theme/index.ts +3 -0
- package/src/theme/types.ts +70 -0
- package/src/theme/useTheme.ts +75 -0
- package/src/types/events.ts +8 -0
- package/src/types/index.ts +4 -0
- package/src/types/native.ts +28 -0
- package/src/types/presentation.ts +21 -0
- package/src/types/props.ts +104 -0
- package/src/utils/constants.ts +15 -0
- package/src/utils/dateConversion.ts +127 -0
- package/src/utils/dateFormatting.ts +166 -0
- package/src/utils/dateValidation.ts +178 -0
- package/src/utils/index.ts +4 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import NativeDateTimePickerKit from '../NativeDateTimePickerKit';
|
|
2
|
+
import {
|
|
3
|
+
DateTimePickerError,
|
|
4
|
+
type DateTimePickerErrorCode,
|
|
5
|
+
} from '../errors/DateTimePickerError';
|
|
6
|
+
import type { NativePickerOptions, NativePickerResult } from '../types/native';
|
|
7
|
+
|
|
8
|
+
function getNativeModule() {
|
|
9
|
+
if (!NativeDateTimePickerKit) {
|
|
10
|
+
throw new DateTimePickerError(
|
|
11
|
+
'NATIVE_MODULE_NOT_FOUND',
|
|
12
|
+
'The native module DateTimePickerKit was not found. Please ensure the library is linked correctly.'
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return NativeDateTimePickerKit;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function normalizeError(error: unknown): DateTimePickerError {
|
|
19
|
+
if (error instanceof DateTimePickerError) {
|
|
20
|
+
return error;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const err = error as { code?: string; message?: string } | null;
|
|
24
|
+
const rawCode = err?.code || 'UNKNOWN_ERROR';
|
|
25
|
+
const message = err?.message || 'An unknown error occurred in DateTimePicker';
|
|
26
|
+
|
|
27
|
+
const validCodes: DateTimePickerErrorCode[] = [
|
|
28
|
+
'NATIVE_MODULE_NOT_FOUND',
|
|
29
|
+
'PICKER_ALREADY_OPEN',
|
|
30
|
+
'PICKER_NOT_OPEN',
|
|
31
|
+
'INVALID_DATE',
|
|
32
|
+
'INVALID_MODE',
|
|
33
|
+
'INVALID_MINUTE_INTERVAL',
|
|
34
|
+
'DATE_OUT_OF_RANGE',
|
|
35
|
+
'UNSUPPORTED_FEATURE',
|
|
36
|
+
'ACTIVITY_UNAVAILABLE',
|
|
37
|
+
'PRESENTATION_FAILED',
|
|
38
|
+
'UNKNOWN_ERROR',
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const code: DateTimePickerErrorCode = validCodes.includes(
|
|
42
|
+
rawCode as DateTimePickerErrorCode
|
|
43
|
+
)
|
|
44
|
+
? (rawCode as DateTimePickerErrorCode)
|
|
45
|
+
: 'UNKNOWN_ERROR';
|
|
46
|
+
|
|
47
|
+
return new DateTimePickerError(code, message, error);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const NativeDateTimePicker = {
|
|
51
|
+
async openDatePicker(
|
|
52
|
+
options: NativePickerOptions
|
|
53
|
+
): Promise<NativePickerResult> {
|
|
54
|
+
try {
|
|
55
|
+
const module = getNativeModule();
|
|
56
|
+
const res = await module.openDatePicker(options as Object);
|
|
57
|
+
return res as unknown as NativePickerResult;
|
|
58
|
+
} catch (err) {
|
|
59
|
+
throw normalizeError(err);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
async openTimePicker(
|
|
64
|
+
options: NativePickerOptions
|
|
65
|
+
): Promise<NativePickerResult> {
|
|
66
|
+
try {
|
|
67
|
+
const module = getNativeModule();
|
|
68
|
+
const res = await module.openTimePicker(options as Object);
|
|
69
|
+
return res as unknown as NativePickerResult;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
throw normalizeError(err);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
async openDateTimePicker(
|
|
76
|
+
options: NativePickerOptions
|
|
77
|
+
): Promise<NativePickerResult> {
|
|
78
|
+
try {
|
|
79
|
+
const module = getNativeModule();
|
|
80
|
+
const res = await module.openDateTimePicker(options as Object);
|
|
81
|
+
return res as unknown as NativePickerResult;
|
|
82
|
+
} catch (err) {
|
|
83
|
+
throw normalizeError(err);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
async openCountdownPicker(
|
|
88
|
+
options: NativePickerOptions
|
|
89
|
+
): Promise<NativePickerResult> {
|
|
90
|
+
try {
|
|
91
|
+
const module = getNativeModule();
|
|
92
|
+
const res = await module.openCountdownPicker(options as Object);
|
|
93
|
+
return res as unknown as NativePickerResult;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
throw normalizeError(err);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
async closePicker(): Promise<boolean> {
|
|
100
|
+
try {
|
|
101
|
+
const module = getNativeModule();
|
|
102
|
+
return await module.closePicker();
|
|
103
|
+
} catch (err) {
|
|
104
|
+
throw normalizeError(err);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
async confirmPicker(): Promise<NativePickerResult> {
|
|
109
|
+
try {
|
|
110
|
+
const module = getNativeModule();
|
|
111
|
+
const res = await module.confirmPicker();
|
|
112
|
+
return res as unknown as NativePickerResult;
|
|
113
|
+
} catch (err) {
|
|
114
|
+
throw normalizeError(err);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
async cancelPicker(): Promise<boolean> {
|
|
119
|
+
try {
|
|
120
|
+
const module = getNativeModule();
|
|
121
|
+
return await module.cancelPicker();
|
|
122
|
+
} catch (err) {
|
|
123
|
+
throw normalizeError(err);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
async setSelectedDate(timestamp: number): Promise<boolean> {
|
|
128
|
+
try {
|
|
129
|
+
const module = getNativeModule();
|
|
130
|
+
return await module.setSelectedDate(timestamp);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
throw normalizeError(err);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
async getSelectedDate(): Promise<NativePickerResult> {
|
|
137
|
+
try {
|
|
138
|
+
const module = getNativeModule();
|
|
139
|
+
const res = await module.getSelectedDate();
|
|
140
|
+
return res as unknown as NativePickerResult;
|
|
141
|
+
} catch (err) {
|
|
142
|
+
throw normalizeError(err);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
async resetPicker(): Promise<boolean> {
|
|
147
|
+
try {
|
|
148
|
+
const module = getNativeModule();
|
|
149
|
+
return await module.resetPicker();
|
|
150
|
+
} catch (err) {
|
|
151
|
+
throw normalizeError(err);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export interface DatePreset {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
getValue: () => [Date, Date] | Date;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getStandardRangePresets(
|
|
8
|
+
today: Date = new Date()
|
|
9
|
+
): DatePreset[] {
|
|
10
|
+
const startOfDay = (d: Date) =>
|
|
11
|
+
new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
|
|
12
|
+
const endOfDay = (d: Date) =>
|
|
13
|
+
new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59, 999);
|
|
14
|
+
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
id: 'today',
|
|
18
|
+
label: 'Today',
|
|
19
|
+
getValue: () => [startOfDay(today), endOfDay(today)],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: 'yesterday',
|
|
23
|
+
label: 'Yesterday',
|
|
24
|
+
getValue: () => {
|
|
25
|
+
const y = new Date(today);
|
|
26
|
+
y.setDate(y.getDate() - 1);
|
|
27
|
+
return [startOfDay(y), endOfDay(y)];
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'last7days',
|
|
32
|
+
label: 'Last 7 Days',
|
|
33
|
+
getValue: () => {
|
|
34
|
+
const past = new Date(today);
|
|
35
|
+
past.setDate(past.getDate() - 6);
|
|
36
|
+
return [startOfDay(past), endOfDay(today)];
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'last30days',
|
|
41
|
+
label: 'Last 30 Days',
|
|
42
|
+
getValue: () => {
|
|
43
|
+
const past = new Date(today);
|
|
44
|
+
past.setDate(past.getDate() - 29);
|
|
45
|
+
return [startOfDay(past), endOfDay(today)];
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'thisMonth',
|
|
50
|
+
label: 'This Month',
|
|
51
|
+
getValue: () => {
|
|
52
|
+
const first = new Date(today.getFullYear(), today.getMonth(), 1);
|
|
53
|
+
const last = new Date(today.getFullYear(), today.getMonth() + 1, 0);
|
|
54
|
+
return [startOfDay(first), endOfDay(last)];
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'nextMonth',
|
|
59
|
+
label: 'Next Month',
|
|
60
|
+
getValue: () => {
|
|
61
|
+
const first = new Date(today.getFullYear(), today.getMonth() + 1, 1);
|
|
62
|
+
const last = new Date(today.getFullYear(), today.getMonth() + 2, 0);
|
|
63
|
+
return [startOfDay(first), endOfDay(last)];
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getStandardSinglePresets(
|
|
70
|
+
today: Date = new Date()
|
|
71
|
+
): DatePreset[] {
|
|
72
|
+
return [
|
|
73
|
+
{
|
|
74
|
+
id: 'today',
|
|
75
|
+
label: 'Today',
|
|
76
|
+
getValue: () => new Date(today),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'tomorrow',
|
|
80
|
+
label: 'Tomorrow',
|
|
81
|
+
getValue: () => {
|
|
82
|
+
const t = new Date(today);
|
|
83
|
+
t.setDate(t.getDate() + 1);
|
|
84
|
+
return t;
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: 'nextWeek',
|
|
89
|
+
label: 'In 1 Week',
|
|
90
|
+
getValue: () => {
|
|
91
|
+
const w = new Date(today);
|
|
92
|
+
w.setDate(w.getDate() + 7);
|
|
93
|
+
return w;
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './datePresets';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './timeSlots';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export interface TimeSlot {
|
|
2
|
+
id: string;
|
|
3
|
+
startTime: string; // "09:00"
|
|
4
|
+
endTime: string; // "09:30"
|
|
5
|
+
formattedStart: string; // "9:00 AM" or "09:00"
|
|
6
|
+
formattedEnd: string; // "9:30 AM" or "09:30"
|
|
7
|
+
available: boolean;
|
|
8
|
+
label?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface GenerateTimeSlotsOptions {
|
|
12
|
+
startTime?: string; // "HH:mm", defaults to "09:00"
|
|
13
|
+
endTime?: string; // "HH:mm", defaults to "18:00"
|
|
14
|
+
intervalMinutes?: number; // defaults to 30
|
|
15
|
+
disabledSlots?: string[]; // IDs or start times like ["12:00", "13:00"]
|
|
16
|
+
is24Hour?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseTimeToMinutes(timeStr: string): number {
|
|
20
|
+
const [hStr, mStr] = timeStr.split(':');
|
|
21
|
+
const h = parseInt(hStr || '0', 10);
|
|
22
|
+
const m = parseInt(mStr || '0', 10);
|
|
23
|
+
return h * 60 + m;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function minutesToTimeString(minutes: number): string {
|
|
27
|
+
const h = Math.floor(minutes / 60) % 24;
|
|
28
|
+
const m = minutes % 60;
|
|
29
|
+
const pad = (n: number) => (n < 10 ? `0${n}` : `${n}`);
|
|
30
|
+
return `${pad(h)}:${pad(m)}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function formatMinutesDisplay(minutes: number, is24Hour: boolean): string {
|
|
34
|
+
const h = Math.floor(minutes / 60) % 24;
|
|
35
|
+
const m = minutes % 60;
|
|
36
|
+
const pad = (n: number) => (n < 10 ? `0${n}` : `${n}`);
|
|
37
|
+
|
|
38
|
+
if (is24Hour) {
|
|
39
|
+
return `${pad(h)}:${pad(m)}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const h12 = h % 12 === 0 ? 12 : h % 12;
|
|
43
|
+
const ampm = h >= 12 ? 'PM' : 'AM';
|
|
44
|
+
return `${h12}:${pad(m)} ${ampm}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function generateTimeSlots(
|
|
48
|
+
options: GenerateTimeSlotsOptions = {}
|
|
49
|
+
): TimeSlot[] {
|
|
50
|
+
const {
|
|
51
|
+
startTime = '09:00',
|
|
52
|
+
endTime = '18:00',
|
|
53
|
+
intervalMinutes = 30,
|
|
54
|
+
disabledSlots = [],
|
|
55
|
+
is24Hour = false,
|
|
56
|
+
} = options;
|
|
57
|
+
|
|
58
|
+
const startMin = parseTimeToMinutes(startTime);
|
|
59
|
+
const endMin = parseTimeToMinutes(endTime);
|
|
60
|
+
|
|
61
|
+
if (startMin >= endMin || intervalMinutes <= 0) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const slots: TimeSlot[] = [];
|
|
66
|
+
const disabledSet = new Set(disabledSlots);
|
|
67
|
+
|
|
68
|
+
let current = startMin;
|
|
69
|
+
while (current + intervalMinutes <= endMin) {
|
|
70
|
+
const slotStartStr = minutesToTimeString(current);
|
|
71
|
+
const slotEndStr = minutesToTimeString(current + intervalMinutes);
|
|
72
|
+
const id = slotStartStr;
|
|
73
|
+
|
|
74
|
+
const isAvailable = !disabledSet.has(id) && !disabledSet.has(slotStartStr);
|
|
75
|
+
|
|
76
|
+
slots.push({
|
|
77
|
+
id,
|
|
78
|
+
startTime: slotStartStr,
|
|
79
|
+
endTime: slotEndStr,
|
|
80
|
+
formattedStart: formatMinutesDisplay(current, is24Hour),
|
|
81
|
+
formattedEnd: formatMinutesDisplay(current + intervalMinutes, is24Hour),
|
|
82
|
+
available: isAvailable,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
current += intervalMinutes;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return slots;
|
|
89
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ResolvedTheme,
|
|
3
|
+
ThemeBorderRadius,
|
|
4
|
+
ThemeColors,
|
|
5
|
+
ThemeSpacing,
|
|
6
|
+
ThemeTypography,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
export const defaultTypography: ThemeTypography = {
|
|
10
|
+
fontSizeSmall: 12,
|
|
11
|
+
fontSizeMedium: 14,
|
|
12
|
+
fontSizeLarge: 16,
|
|
13
|
+
fontSizeTitle: 18,
|
|
14
|
+
fontWeightRegular: '400',
|
|
15
|
+
fontWeightMedium: '600',
|
|
16
|
+
fontWeightBold: '700',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const defaultSpacing: ThemeSpacing = {
|
|
20
|
+
xs: 4,
|
|
21
|
+
sm: 8,
|
|
22
|
+
md: 12,
|
|
23
|
+
lg: 16,
|
|
24
|
+
xl: 24,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const defaultBorderRadius: ThemeBorderRadius = {
|
|
28
|
+
sm: 6,
|
|
29
|
+
md: 10,
|
|
30
|
+
lg: 16,
|
|
31
|
+
full: 9999,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const lightColors: ThemeColors = {
|
|
35
|
+
background: '#FFFFFF',
|
|
36
|
+
card: '#F8FAFC',
|
|
37
|
+
modalOverlay: 'rgba(0, 0, 0, 0.45)',
|
|
38
|
+
modalBackground: '#FFFFFF',
|
|
39
|
+
modalHandle: '#CBD5E1',
|
|
40
|
+
text: '#0F172A',
|
|
41
|
+
textSecondary: '#475569',
|
|
42
|
+
textMuted: '#94A3B8',
|
|
43
|
+
primary: '#2563EB',
|
|
44
|
+
primaryText: '#FFFFFF',
|
|
45
|
+
accent: '#3B82F6',
|
|
46
|
+
border: '#E2E8F0',
|
|
47
|
+
divider: '#F1F5F9',
|
|
48
|
+
selected: '#2563EB',
|
|
49
|
+
selectedText: '#FFFFFF',
|
|
50
|
+
rangeHighlight: '#DBEAFE',
|
|
51
|
+
rangeHighlightText: '#1D4ED8',
|
|
52
|
+
todayIndicator: '#2563EB',
|
|
53
|
+
disabled: '#F1F5F9',
|
|
54
|
+
disabledText: '#CBD5E1',
|
|
55
|
+
error: '#EF4444',
|
|
56
|
+
errorText: '#FFFFFF',
|
|
57
|
+
headerBackground: '#FFFFFF',
|
|
58
|
+
footerBackground: '#F8FAFC',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const darkColors: ThemeColors = {
|
|
62
|
+
background: '#0F172A',
|
|
63
|
+
card: '#1E293B',
|
|
64
|
+
modalOverlay: 'rgba(0, 0, 0, 0.7)',
|
|
65
|
+
modalBackground: '#1E293B',
|
|
66
|
+
modalHandle: '#475569',
|
|
67
|
+
text: '#F8FAFC',
|
|
68
|
+
textSecondary: '#CBD5E1',
|
|
69
|
+
textMuted: '#64748B',
|
|
70
|
+
primary: '#3B82F6',
|
|
71
|
+
primaryText: '#FFFFFF',
|
|
72
|
+
accent: '#60A5FA',
|
|
73
|
+
border: '#334155',
|
|
74
|
+
divider: '#1E293B',
|
|
75
|
+
selected: '#3B82F6',
|
|
76
|
+
selectedText: '#FFFFFF',
|
|
77
|
+
rangeHighlight: '#1E3A8A',
|
|
78
|
+
rangeHighlightText: '#93C5FD',
|
|
79
|
+
todayIndicator: '#60A5FA',
|
|
80
|
+
disabled: '#1E293B',
|
|
81
|
+
disabledText: '#475569',
|
|
82
|
+
error: '#F87171',
|
|
83
|
+
errorText: '#FFFFFF',
|
|
84
|
+
headerBackground: '#1E293B',
|
|
85
|
+
footerBackground: '#0F172A',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const defaultLightTheme: ResolvedTheme = {
|
|
89
|
+
mode: 'light',
|
|
90
|
+
colors: lightColors,
|
|
91
|
+
typography: defaultTypography,
|
|
92
|
+
spacing: defaultSpacing,
|
|
93
|
+
borderRadius: defaultBorderRadius,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const defaultDarkTheme: ResolvedTheme = {
|
|
97
|
+
mode: 'dark',
|
|
98
|
+
colors: darkColors,
|
|
99
|
+
typography: defaultTypography,
|
|
100
|
+
spacing: defaultSpacing,
|
|
101
|
+
borderRadius: defaultBorderRadius,
|
|
102
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type ThemeMode = 'light' | 'dark' | 'auto';
|
|
2
|
+
|
|
3
|
+
export interface ThemeColors {
|
|
4
|
+
background: string;
|
|
5
|
+
card: string;
|
|
6
|
+
modalOverlay: string;
|
|
7
|
+
modalBackground: string;
|
|
8
|
+
modalHandle: string;
|
|
9
|
+
text: string;
|
|
10
|
+
textSecondary: string;
|
|
11
|
+
textMuted: string;
|
|
12
|
+
primary: string;
|
|
13
|
+
primaryText: string;
|
|
14
|
+
accent: string;
|
|
15
|
+
border: string;
|
|
16
|
+
divider: string;
|
|
17
|
+
selected: string;
|
|
18
|
+
selectedText: string;
|
|
19
|
+
rangeHighlight: string;
|
|
20
|
+
rangeHighlightText: string;
|
|
21
|
+
todayIndicator: string;
|
|
22
|
+
disabled: string;
|
|
23
|
+
disabledText: string;
|
|
24
|
+
error: string;
|
|
25
|
+
errorText: string;
|
|
26
|
+
headerBackground: string;
|
|
27
|
+
footerBackground: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ThemeTypography {
|
|
31
|
+
fontSizeSmall: number;
|
|
32
|
+
fontSizeMedium: number;
|
|
33
|
+
fontSizeLarge: number;
|
|
34
|
+
fontSizeTitle: number;
|
|
35
|
+
fontWeightRegular: '400' | 'normal';
|
|
36
|
+
fontWeightMedium: '500' | '600';
|
|
37
|
+
fontWeightBold: '700' | 'bold';
|
|
38
|
+
fontFamily?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ThemeSpacing {
|
|
42
|
+
xs: number;
|
|
43
|
+
sm: number;
|
|
44
|
+
md: number;
|
|
45
|
+
lg: number;
|
|
46
|
+
xl: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ThemeBorderRadius {
|
|
50
|
+
sm: number;
|
|
51
|
+
md: number;
|
|
52
|
+
lg: number;
|
|
53
|
+
full: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ThemeConfig {
|
|
57
|
+
mode?: ThemeMode;
|
|
58
|
+
colors?: Partial<ThemeColors>;
|
|
59
|
+
typography?: Partial<ThemeTypography>;
|
|
60
|
+
spacing?: Partial<ThemeSpacing>;
|
|
61
|
+
borderRadius?: Partial<ThemeBorderRadius>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ResolvedTheme {
|
|
65
|
+
mode: 'light' | 'dark';
|
|
66
|
+
colors: ThemeColors;
|
|
67
|
+
typography: ThemeTypography;
|
|
68
|
+
spacing: ThemeSpacing;
|
|
69
|
+
borderRadius: ThemeBorderRadius;
|
|
70
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useColorScheme } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
defaultBorderRadius,
|
|
5
|
+
defaultDarkTheme,
|
|
6
|
+
defaultLightTheme,
|
|
7
|
+
defaultSpacing,
|
|
8
|
+
defaultTypography,
|
|
9
|
+
} from './defaultTheme';
|
|
10
|
+
import type { ResolvedTheme, ThemeConfig, ThemeMode } from './types';
|
|
11
|
+
|
|
12
|
+
export function resolveTheme(
|
|
13
|
+
themeInput?: ThemeMode | ThemeConfig | null,
|
|
14
|
+
systemScheme?: 'light' | 'dark' | null
|
|
15
|
+
): ResolvedTheme {
|
|
16
|
+
let mode: 'light' | 'dark' = 'light';
|
|
17
|
+
let config: ThemeConfig | undefined;
|
|
18
|
+
|
|
19
|
+
if (typeof themeInput === 'string') {
|
|
20
|
+
if (themeInput === 'dark') {
|
|
21
|
+
mode = 'dark';
|
|
22
|
+
} else if (themeInput === 'light') {
|
|
23
|
+
mode = 'light';
|
|
24
|
+
} else {
|
|
25
|
+
mode = systemScheme === 'dark' ? 'dark' : 'light';
|
|
26
|
+
}
|
|
27
|
+
} else if (themeInput && typeof themeInput === 'object') {
|
|
28
|
+
config = themeInput;
|
|
29
|
+
if (config.mode === 'dark') {
|
|
30
|
+
mode = 'dark';
|
|
31
|
+
} else if (config.mode === 'light') {
|
|
32
|
+
mode = 'light';
|
|
33
|
+
} else {
|
|
34
|
+
mode = systemScheme === 'dark' ? 'dark' : 'light';
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
mode = systemScheme === 'dark' ? 'dark' : 'light';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const baseTheme = mode === 'dark' ? defaultDarkTheme : defaultLightTheme;
|
|
41
|
+
|
|
42
|
+
if (!config) {
|
|
43
|
+
return baseTheme;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
mode,
|
|
48
|
+
colors: {
|
|
49
|
+
...baseTheme.colors,
|
|
50
|
+
...config.colors,
|
|
51
|
+
},
|
|
52
|
+
typography: {
|
|
53
|
+
...defaultTypography,
|
|
54
|
+
...config.typography,
|
|
55
|
+
},
|
|
56
|
+
spacing: {
|
|
57
|
+
...defaultSpacing,
|
|
58
|
+
...config.spacing,
|
|
59
|
+
},
|
|
60
|
+
borderRadius: {
|
|
61
|
+
...defaultBorderRadius,
|
|
62
|
+
...config.borderRadius,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function useTheme(
|
|
68
|
+
themeInput?: ThemeMode | ThemeConfig | null
|
|
69
|
+
): ResolvedTheme {
|
|
70
|
+
const systemScheme = useColorScheme();
|
|
71
|
+
|
|
72
|
+
return useMemo(() => {
|
|
73
|
+
return resolveTheme(themeInput, systemScheme);
|
|
74
|
+
}, [themeInput, systemScheme]);
|
|
75
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DateTimePickerError } from '../errors/DateTimePickerError';
|
|
2
|
+
|
|
3
|
+
export type DateTimePickerChangeEvent = (date: Date) => void;
|
|
4
|
+
export type DateTimePickerConfirmEvent = (date: Date) => void;
|
|
5
|
+
export type DateTimePickerCancelEvent = () => void;
|
|
6
|
+
export type DateTimePickerDismissEvent = () => void;
|
|
7
|
+
export type DateTimePickerOpenEvent = () => void;
|
|
8
|
+
export type DateTimePickerErrorEvent = (error: DateTimePickerError) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type NativePickerMode = 'date' | 'time' | 'datetime' | 'countdown';
|
|
2
|
+
export type NativePickerDisplay =
|
|
3
|
+
'default' | 'spinner' | 'calendar' | 'clock' | 'compact' | 'inline';
|
|
4
|
+
export type NativePickerTheme = 'light' | 'dark' | 'auto';
|
|
5
|
+
export type NativePickerAction = 'confirmed' | 'cancelled' | 'dismissed';
|
|
6
|
+
|
|
7
|
+
export interface NativePickerOptions {
|
|
8
|
+
value?: number;
|
|
9
|
+
minimumDate?: number;
|
|
10
|
+
maximumDate?: number;
|
|
11
|
+
display?: NativePickerDisplay;
|
|
12
|
+
locale?: string;
|
|
13
|
+
timeZoneOffsetInMinutes?: number;
|
|
14
|
+
is24Hour?: boolean;
|
|
15
|
+
minuteInterval?: number;
|
|
16
|
+
title?: string;
|
|
17
|
+
confirmText?: string;
|
|
18
|
+
cancelText?: string;
|
|
19
|
+
theme?: NativePickerTheme;
|
|
20
|
+
accentColor?: string;
|
|
21
|
+
textColor?: string;
|
|
22
|
+
backgroundColor?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface NativePickerResult {
|
|
26
|
+
action: NativePickerAction;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type PresentationMode =
|
|
2
|
+
'native' | 'inline' | 'modal' | 'bottom-sheet' | 'fullscreen';
|
|
3
|
+
|
|
4
|
+
export type ModalAnimationType = 'slide' | 'fade' | 'none';
|
|
5
|
+
|
|
6
|
+
export interface BaseModalProps {
|
|
7
|
+
visible?: boolean;
|
|
8
|
+
onClose?: () => void;
|
|
9
|
+
title?: string;
|
|
10
|
+
confirmText?: string;
|
|
11
|
+
cancelText?: string;
|
|
12
|
+
onConfirm?: () => void;
|
|
13
|
+
onCancel?: () => void;
|
|
14
|
+
backdropOpacity?: number;
|
|
15
|
+
animationType?: ModalAnimationType;
|
|
16
|
+
showHandle?: boolean; // For bottom-sheet
|
|
17
|
+
closeOnBackdropPress?: boolean;
|
|
18
|
+
customHeader?: React.ReactNode;
|
|
19
|
+
customFooter?: React.ReactNode;
|
|
20
|
+
testID?: string;
|
|
21
|
+
}
|