@izonnet-web-solution/react-native-date-time-picker-kit 0.0.0-stage → 1.0.1
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 +652 -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 +419 -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 +181 -0
- package/lib/module/components/DatePicker.js.map +1 -0
- package/lib/module/components/DateRangePicker.js +158 -0
- package/lib/module/components/DateRangePicker.js.map +1 -0
- package/lib/module/components/DateTimePicker.js +674 -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 +142 -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 +159 -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 +136 -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 +176 -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 +81 -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 +224 -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 +51 -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 +44 -0
- package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
- package/lib/typescript/src/components/DateRangePicker.d.ts +56 -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 +31 -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 +11 -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 +76 -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 +26 -0
- package/lib/typescript/src/types/presentation.d.ts.map +1 -0
- package/lib/typescript/src/types/props.d.ts +221 -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 +46 -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 +191 -4
- package/src/NativeDateTimePickerKit.ts +19 -0
- package/src/components/CalendarPicker.tsx +623 -0
- package/src/components/ClockPicker.tsx +403 -0
- package/src/components/DatePicker.tsx +276 -0
- package/src/components/DateRangePicker.tsx +251 -0
- package/src/components/DateTimePicker.tsx +1028 -0
- package/src/components/MonthPicker.tsx +216 -0
- package/src/components/TimePicker.tsx +203 -0
- package/src/components/TimeSlotPicker.tsx +163 -0
- package/src/components/WheelPicker.tsx +229 -0
- package/src/components/YearPicker.tsx +228 -0
- package/src/components/common/ModalWrapper.tsx +192 -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 +197 -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 +82 -0
- package/src/theme/useTheme.ts +98 -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 +28 -0
- package/src/types/props.ts +291 -0
- package/src/utils/constants.ts +15 -0
- package/src/utils/dateConversion.ts +273 -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,121 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import type { ResolvedTheme } from '../../theme';
|
|
4
|
+
|
|
5
|
+
export interface PickerHeaderProps {
|
|
6
|
+
title?: string;
|
|
7
|
+
cancelText?: string;
|
|
8
|
+
confirmText?: string;
|
|
9
|
+
onCancel?: () => void;
|
|
10
|
+
onConfirm?: () => void;
|
|
11
|
+
theme: ResolvedTheme;
|
|
12
|
+
isRTL?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const PickerHeader: React.FC<PickerHeaderProps> = React.memo(
|
|
16
|
+
({
|
|
17
|
+
title,
|
|
18
|
+
cancelText = 'Cancel',
|
|
19
|
+
confirmText = 'Confirm',
|
|
20
|
+
onCancel,
|
|
21
|
+
onConfirm,
|
|
22
|
+
theme,
|
|
23
|
+
isRTL = false,
|
|
24
|
+
}) => {
|
|
25
|
+
return (
|
|
26
|
+
<View
|
|
27
|
+
style={[
|
|
28
|
+
styles.container,
|
|
29
|
+
{
|
|
30
|
+
borderBottomColor: theme.colors.border,
|
|
31
|
+
flexDirection: isRTL ? 'row-reverse' : 'row',
|
|
32
|
+
backgroundColor: theme.colors.headerBackground,
|
|
33
|
+
},
|
|
34
|
+
]}
|
|
35
|
+
>
|
|
36
|
+
{onCancel ? (
|
|
37
|
+
<TouchableOpacity
|
|
38
|
+
accessibilityRole="button"
|
|
39
|
+
accessibilityLabel={cancelText}
|
|
40
|
+
onPress={onCancel}
|
|
41
|
+
style={styles.actionButton}
|
|
42
|
+
>
|
|
43
|
+
<Text
|
|
44
|
+
style={[
|
|
45
|
+
styles.cancelText,
|
|
46
|
+
{
|
|
47
|
+
color: theme.colors.textSecondary,
|
|
48
|
+
fontSize: theme.typography.fontSizeMedium,
|
|
49
|
+
},
|
|
50
|
+
]}
|
|
51
|
+
>
|
|
52
|
+
{cancelText}
|
|
53
|
+
</Text>
|
|
54
|
+
</TouchableOpacity>
|
|
55
|
+
) : (
|
|
56
|
+
<View style={styles.actionButton} />
|
|
57
|
+
)}
|
|
58
|
+
|
|
59
|
+
<Text
|
|
60
|
+
numberOfLines={1}
|
|
61
|
+
style={[
|
|
62
|
+
styles.titleText,
|
|
63
|
+
{
|
|
64
|
+
color: theme.colors.text,
|
|
65
|
+
fontSize: theme.typography.fontSizeLarge,
|
|
66
|
+
fontWeight: theme.typography.fontWeightMedium,
|
|
67
|
+
},
|
|
68
|
+
]}
|
|
69
|
+
>
|
|
70
|
+
{title || ''}
|
|
71
|
+
</Text>
|
|
72
|
+
|
|
73
|
+
{onConfirm ? (
|
|
74
|
+
<TouchableOpacity
|
|
75
|
+
accessibilityRole="button"
|
|
76
|
+
accessibilityLabel={confirmText}
|
|
77
|
+
onPress={onConfirm}
|
|
78
|
+
style={styles.actionButton}
|
|
79
|
+
>
|
|
80
|
+
<Text
|
|
81
|
+
style={[
|
|
82
|
+
styles.confirmText,
|
|
83
|
+
{
|
|
84
|
+
color: theme.colors.primary,
|
|
85
|
+
fontSize: theme.typography.fontSizeMedium,
|
|
86
|
+
fontWeight: theme.typography.fontWeightMedium,
|
|
87
|
+
},
|
|
88
|
+
]}
|
|
89
|
+
>
|
|
90
|
+
{confirmText}
|
|
91
|
+
</Text>
|
|
92
|
+
</TouchableOpacity>
|
|
93
|
+
) : (
|
|
94
|
+
<View style={styles.actionButton} />
|
|
95
|
+
)}
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const styles = StyleSheet.create({
|
|
102
|
+
container: {
|
|
103
|
+
height: 54,
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
justifyContent: 'space-between',
|
|
106
|
+
paddingHorizontal: 16,
|
|
107
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
108
|
+
},
|
|
109
|
+
actionButton: {
|
|
110
|
+
minWidth: 64,
|
|
111
|
+
height: 40,
|
|
112
|
+
justifyContent: 'center',
|
|
113
|
+
alignItems: 'center',
|
|
114
|
+
},
|
|
115
|
+
titleText: {
|
|
116
|
+
flex: 1,
|
|
117
|
+
textAlign: 'center',
|
|
118
|
+
},
|
|
119
|
+
cancelText: {},
|
|
120
|
+
confirmText: {},
|
|
121
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ScrollView,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Text,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
View,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import type { DatePreset } from '../../presets';
|
|
10
|
+
import type { ResolvedTheme } from '../../theme';
|
|
11
|
+
|
|
12
|
+
export interface PresetsBarProps {
|
|
13
|
+
presets: DatePreset[];
|
|
14
|
+
activePresetId?: string;
|
|
15
|
+
onSelectPreset: (preset: DatePreset) => void;
|
|
16
|
+
theme: ResolvedTheme;
|
|
17
|
+
isRTL?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const PresetsBar: React.FC<PresetsBarProps> = React.memo(
|
|
21
|
+
({ presets, activePresetId, onSelectPreset, theme, isRTL = false }) => {
|
|
22
|
+
if (!presets || presets.length === 0) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<View
|
|
28
|
+
style={[
|
|
29
|
+
styles.container,
|
|
30
|
+
{
|
|
31
|
+
borderBottomColor: theme.colors.border,
|
|
32
|
+
backgroundColor: theme.colors.card,
|
|
33
|
+
},
|
|
34
|
+
]}
|
|
35
|
+
>
|
|
36
|
+
<ScrollView
|
|
37
|
+
horizontal
|
|
38
|
+
showsHorizontalScrollIndicator={false}
|
|
39
|
+
contentContainerStyle={[
|
|
40
|
+
styles.scrollContent,
|
|
41
|
+
{ flexDirection: isRTL ? 'row-reverse' : 'row' },
|
|
42
|
+
]}
|
|
43
|
+
>
|
|
44
|
+
{presets.map((preset) => {
|
|
45
|
+
const isActive = preset.id === activePresetId;
|
|
46
|
+
return (
|
|
47
|
+
<TouchableOpacity
|
|
48
|
+
key={preset.id}
|
|
49
|
+
onPress={() => onSelectPreset(preset)}
|
|
50
|
+
style={[
|
|
51
|
+
styles.chip,
|
|
52
|
+
{
|
|
53
|
+
backgroundColor: isActive
|
|
54
|
+
? theme.colors.primary
|
|
55
|
+
: theme.colors.background,
|
|
56
|
+
borderColor: isActive
|
|
57
|
+
? theme.colors.primary
|
|
58
|
+
: theme.colors.border,
|
|
59
|
+
borderRadius: theme.borderRadius.full,
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
>
|
|
63
|
+
<Text
|
|
64
|
+
style={[
|
|
65
|
+
styles.chipText,
|
|
66
|
+
{
|
|
67
|
+
color: isActive
|
|
68
|
+
? theme.colors.primaryText
|
|
69
|
+
: theme.colors.textSecondary,
|
|
70
|
+
fontSize: theme.typography.fontSizeSmall,
|
|
71
|
+
fontWeight: isActive
|
|
72
|
+
? theme.typography.fontWeightMedium
|
|
73
|
+
: theme.typography.fontWeightRegular,
|
|
74
|
+
},
|
|
75
|
+
]}
|
|
76
|
+
>
|
|
77
|
+
{preset.label}
|
|
78
|
+
</Text>
|
|
79
|
+
</TouchableOpacity>
|
|
80
|
+
);
|
|
81
|
+
})}
|
|
82
|
+
</ScrollView>
|
|
83
|
+
</View>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const styles = StyleSheet.create({
|
|
89
|
+
container: {
|
|
90
|
+
paddingVertical: 8,
|
|
91
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
92
|
+
},
|
|
93
|
+
scrollContent: {
|
|
94
|
+
paddingHorizontal: 12,
|
|
95
|
+
alignItems: 'center',
|
|
96
|
+
gap: 8,
|
|
97
|
+
},
|
|
98
|
+
chip: {
|
|
99
|
+
paddingHorizontal: 14,
|
|
100
|
+
paddingVertical: 6,
|
|
101
|
+
borderWidth: 1,
|
|
102
|
+
},
|
|
103
|
+
chipText: {},
|
|
104
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type DateTimePickerErrorCode =
|
|
2
|
+
| 'NATIVE_MODULE_NOT_FOUND'
|
|
3
|
+
| 'PICKER_ALREADY_OPEN'
|
|
4
|
+
| 'PICKER_NOT_OPEN'
|
|
5
|
+
| 'INVALID_DATE'
|
|
6
|
+
| 'INVALID_MODE'
|
|
7
|
+
| 'INVALID_MINUTE_INTERVAL'
|
|
8
|
+
| 'DATE_OUT_OF_RANGE'
|
|
9
|
+
| 'UNSUPPORTED_FEATURE'
|
|
10
|
+
| 'ACTIVITY_UNAVAILABLE'
|
|
11
|
+
| 'PRESENTATION_FAILED'
|
|
12
|
+
| 'UNKNOWN_ERROR';
|
|
13
|
+
|
|
14
|
+
export class DateTimePickerError extends Error {
|
|
15
|
+
readonly code: DateTimePickerErrorCode;
|
|
16
|
+
readonly details?: unknown;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
code: DateTimePickerErrorCode,
|
|
20
|
+
message: string,
|
|
21
|
+
details?: unknown
|
|
22
|
+
) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'DateTimePickerError';
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.details = details;
|
|
27
|
+
Object.setPrototypeOf(this, DateTimePickerError.prototype);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
import type { DateTimePickerProps, DateTimePickerRef } from '../types';
|
|
3
|
+
import type { DateTimePickerError } from '../errors/DateTimePickerError';
|
|
4
|
+
import { parseDate } from '../utils/dateConversion';
|
|
5
|
+
|
|
6
|
+
export interface UseDateTimePickerResult {
|
|
7
|
+
ref: React.RefObject<DateTimePickerRef | null>;
|
|
8
|
+
isOpen: boolean;
|
|
9
|
+
value: Date;
|
|
10
|
+
error: DateTimePickerError | null;
|
|
11
|
+
open: () => Promise<Date | null>;
|
|
12
|
+
close: () => Promise<boolean>;
|
|
13
|
+
confirm: () => Promise<Date | null>;
|
|
14
|
+
cancel: () => Promise<boolean>;
|
|
15
|
+
reset: () => void;
|
|
16
|
+
getValue: () => Date | null;
|
|
17
|
+
setValue: (date: Date | number | string) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useDateTimePicker(
|
|
21
|
+
options: Partial<DateTimePickerProps> = {}
|
|
22
|
+
): UseDateTimePickerResult {
|
|
23
|
+
const pickerRef = useRef<DateTimePickerRef>(null);
|
|
24
|
+
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
25
|
+
const [value, setValueState] = useState<Date>(
|
|
26
|
+
() =>
|
|
27
|
+
parseDate(options.value) || parseDate(options.defaultValue) || new Date()
|
|
28
|
+
);
|
|
29
|
+
const [error, setError] = useState<DateTimePickerError | null>(null);
|
|
30
|
+
|
|
31
|
+
const open = useCallback(async (): Promise<Date | null> => {
|
|
32
|
+
setIsOpen(true);
|
|
33
|
+
setError(null);
|
|
34
|
+
try {
|
|
35
|
+
const selected = await pickerRef.current?.open();
|
|
36
|
+
if (selected) {
|
|
37
|
+
setValueState(selected);
|
|
38
|
+
}
|
|
39
|
+
return selected ?? null;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
setError(err as DateTimePickerError);
|
|
42
|
+
return null;
|
|
43
|
+
} finally {
|
|
44
|
+
setIsOpen(false);
|
|
45
|
+
}
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
48
|
+
const close = useCallback(async (): Promise<boolean> => {
|
|
49
|
+
const closed = (await pickerRef.current?.close()) ?? false;
|
|
50
|
+
setIsOpen(false);
|
|
51
|
+
return closed;
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
const confirm = useCallback(async (): Promise<Date | null> => {
|
|
55
|
+
const confirmed = await pickerRef.current?.confirm();
|
|
56
|
+
if (confirmed) {
|
|
57
|
+
setValueState(confirmed);
|
|
58
|
+
setIsOpen(false);
|
|
59
|
+
}
|
|
60
|
+
return confirmed ?? null;
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
const cancel = useCallback(async (): Promise<boolean> => {
|
|
64
|
+
const cancelled = (await pickerRef.current?.cancel()) ?? false;
|
|
65
|
+
setIsOpen(false);
|
|
66
|
+
return cancelled;
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
const reset = useCallback(() => {
|
|
70
|
+
pickerRef.current?.reset();
|
|
71
|
+
const resetDate = parseDate(options.defaultValue) || new Date();
|
|
72
|
+
setValueState(resetDate);
|
|
73
|
+
}, [options.defaultValue]);
|
|
74
|
+
|
|
75
|
+
const getValue = useCallback((): Date | null => {
|
|
76
|
+
return pickerRef.current?.getValue() ?? value;
|
|
77
|
+
}, [value]);
|
|
78
|
+
|
|
79
|
+
const setValue = useCallback((newDate: Date | number | string) => {
|
|
80
|
+
pickerRef.current?.setValue(newDate);
|
|
81
|
+
const parsed = parseDate(newDate);
|
|
82
|
+
if (parsed) {
|
|
83
|
+
setValueState(parsed);
|
|
84
|
+
}
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
ref: pickerRef,
|
|
89
|
+
isOpen,
|
|
90
|
+
value,
|
|
91
|
+
error,
|
|
92
|
+
open,
|
|
93
|
+
close,
|
|
94
|
+
confirm,
|
|
95
|
+
cancel,
|
|
96
|
+
reset,
|
|
97
|
+
getValue,
|
|
98
|
+
setValue,
|
|
99
|
+
};
|
|
100
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Public Components
|
|
2
|
+
export {
|
|
3
|
+
DateTimePicker,
|
|
4
|
+
openDateTimePickerModal,
|
|
5
|
+
} from './components/DateTimePicker';
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
DatePicker,
|
|
9
|
+
type DatePickerProps,
|
|
10
|
+
type DatePickerRef,
|
|
11
|
+
} from './components/DatePicker';
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
TimePicker,
|
|
15
|
+
type TimePickerProps,
|
|
16
|
+
type TimePickerRef,
|
|
17
|
+
} from './components/TimePicker';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
DateRangePicker,
|
|
21
|
+
type DateRange,
|
|
22
|
+
type DateRangePickerProps,
|
|
23
|
+
type DateRangePickerRef,
|
|
24
|
+
} from './components/DateRangePicker';
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
CalendarPicker,
|
|
28
|
+
type CalendarPickerProps,
|
|
29
|
+
type MarkedDateConfig,
|
|
30
|
+
type MarkedDatesMap,
|
|
31
|
+
} from './components/CalendarPicker';
|
|
32
|
+
|
|
33
|
+
export { MonthPicker, type MonthPickerProps } from './components/MonthPicker';
|
|
34
|
+
|
|
35
|
+
export { YearPicker, type YearPickerProps } from './components/YearPicker';
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
WheelPicker,
|
|
39
|
+
type WheelPickerItem,
|
|
40
|
+
type WheelPickerProps,
|
|
41
|
+
} from './components/WheelPicker';
|
|
42
|
+
|
|
43
|
+
export { ClockPicker, type ClockPickerProps } from './components/ClockPicker';
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
TimeSlotPicker,
|
|
47
|
+
type TimeSlotPickerProps,
|
|
48
|
+
} from './components/TimeSlotPicker';
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
ModalWrapper,
|
|
52
|
+
type ModalWrapperProps,
|
|
53
|
+
} from './components/common/ModalWrapper';
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
PickerHeader,
|
|
57
|
+
type PickerHeaderProps,
|
|
58
|
+
} from './components/common/PickerHeader';
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
PresetsBar,
|
|
62
|
+
type PresetsBarProps,
|
|
63
|
+
} from './components/common/PresetsBar';
|
|
64
|
+
|
|
65
|
+
// Custom Hooks
|
|
66
|
+
export {
|
|
67
|
+
useDateTimePicker,
|
|
68
|
+
type UseDateTimePickerResult,
|
|
69
|
+
} from './hooks/useDateTimePicker';
|
|
70
|
+
|
|
71
|
+
// Theme System
|
|
72
|
+
export * from './theme';
|
|
73
|
+
|
|
74
|
+
// Localization System
|
|
75
|
+
export * from './localization';
|
|
76
|
+
|
|
77
|
+
// Presets & Appointment Time Slots
|
|
78
|
+
export * from './presets';
|
|
79
|
+
export * from './slots';
|
|
80
|
+
|
|
81
|
+
// Native Bridge & TurboModule
|
|
82
|
+
export { NativeDateTimePicker } from './native/NativeDateTimePicker';
|
|
83
|
+
|
|
84
|
+
// Error System
|
|
85
|
+
export {
|
|
86
|
+
DateTimePickerError,
|
|
87
|
+
type DateTimePickerErrorCode,
|
|
88
|
+
} from './errors/DateTimePickerError';
|
|
89
|
+
|
|
90
|
+
// Types & Utilities
|
|
91
|
+
export * from './types';
|
|
92
|
+
export * from './utils';
|