react-native-smart-date-picker 0.1.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/README.md +163 -0
- package/lib/components/DateColumn.d.ts +3 -0
- package/lib/components/DateColumn.d.ts.map +1 -0
- package/lib/components/DateColumn.js +12 -0
- package/lib/components/HourColumn.d.ts +3 -0
- package/lib/components/HourColumn.d.ts.map +1 -0
- package/lib/components/HourColumn.js +12 -0
- package/lib/components/MinuteColumn.d.ts +3 -0
- package/lib/components/MinuteColumn.d.ts.map +1 -0
- package/lib/components/MinuteColumn.js +12 -0
- package/lib/components/MonthColumn.d.ts +3 -0
- package/lib/components/MonthColumn.d.ts.map +1 -0
- package/lib/components/MonthColumn.js +12 -0
- package/lib/components/PickerModal.d.ts +10 -0
- package/lib/components/PickerModal.d.ts.map +1 -0
- package/lib/components/PickerModal.js +27 -0
- package/lib/components/SelectionOverlay.d.ts +10 -0
- package/lib/components/SelectionOverlay.d.ts.map +1 -0
- package/lib/components/SelectionOverlay.js +26 -0
- package/lib/components/SmartDatePicker.d.ts +4 -0
- package/lib/components/SmartDatePicker.d.ts.map +1 -0
- package/lib/components/SmartDatePicker.js +154 -0
- package/lib/components/WheelColumn.d.ts +17 -0
- package/lib/components/WheelColumn.d.ts.map +1 -0
- package/lib/components/WheelColumn.js +126 -0
- package/lib/components/YearColumn.d.ts +3 -0
- package/lib/components/YearColumn.d.ts.map +1 -0
- package/lib/components/YearColumn.js +12 -0
- package/lib/hooks/useDatePicker.d.ts +13 -0
- package/lib/hooks/useDatePicker.d.ts.map +1 -0
- package/lib/hooks/useDatePicker.js +31 -0
- package/lib/hooks/useTheme.d.ts +13 -0
- package/lib/hooks/useTheme.d.ts.map +1 -0
- package/lib/hooks/useTheme.js +7 -0
- package/lib/hooks/useWheel.d.ts +5 -0
- package/lib/hooks/useWheel.d.ts.map +1 -0
- package/lib/hooks/useWheel.js +12 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +23 -0
- package/lib/types/index.d.ts +59 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/constants.d.ts +4 -0
- package/lib/utils/constants.d.ts.map +1 -0
- package/lib/utils/constants.js +19 -0
- package/lib/utils/dateUtils.d.ts +4 -0
- package/lib/utils/dateUtils.d.ts.map +1 -0
- package/lib/utils/dateUtils.js +21 -0
- package/lib/utils/generateData.d.ts +21 -0
- package/lib/utils/generateData.d.ts.map +1 -0
- package/lib/utils/generateData.js +95 -0
- package/lib/utils/validateDOB.d.ts +2 -0
- package/lib/utils/validateDOB.d.ts.map +1 -0
- package/lib/utils/validateDOB.js +17 -0
- package/package.json +54 -0
- package/src/components/DateColumn.tsx +14 -0
- package/src/components/HourColumn.tsx +14 -0
- package/src/components/MinuteColumn.tsx +14 -0
- package/src/components/MonthColumn.tsx +14 -0
- package/src/components/PickerModal.tsx +60 -0
- package/src/components/SelectionOverlay.tsx +45 -0
- package/src/components/SmartDatePicker.tsx +318 -0
- package/src/components/WheelColumn.tsx +231 -0
- package/src/components/YearColumn.tsx +14 -0
- package/src/hooks/useDatePicker.ts +47 -0
- package/src/hooks/useTheme.ts +18 -0
- package/src/hooks/useWheel.ts +13 -0
- package/src/index.ts +3 -0
- package/src/types/index.ts +77 -0
- package/src/utils/constants.ts +17 -0
- package/src/utils/dateUtils.ts +38 -0
- package/src/utils/generateData.ts +134 -0
- package/src/utils/validateDOB.ts +24 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { TextStyle, ViewStyle } from "react-native";
|
|
2
|
+
|
|
3
|
+
export interface SmartDatePickerTheme {
|
|
4
|
+
primaryColor?: string;
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
textColor?: string;
|
|
7
|
+
buttonTextColor?: string;
|
|
8
|
+
overlayBorderColor?: string;
|
|
9
|
+
disabledTextColor?: string;
|
|
10
|
+
selectionOverlayColor?: string;
|
|
11
|
+
headerBackgroundColor?: string;
|
|
12
|
+
wheelBackgroundColor?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface SmartDatePickerProps {
|
|
16
|
+
visible: boolean;
|
|
17
|
+
|
|
18
|
+
value?: Date;
|
|
19
|
+
|
|
20
|
+
mode?: "date" | "time" | "datetime";
|
|
21
|
+
|
|
22
|
+
minimumDate?: Date;
|
|
23
|
+
maximumDate?: Date;
|
|
24
|
+
|
|
25
|
+
minYear?: number;
|
|
26
|
+
maxYear?: number;
|
|
27
|
+
|
|
28
|
+
is24Hour?: boolean;
|
|
29
|
+
minuteInterval?: number;
|
|
30
|
+
|
|
31
|
+
showSelectionOverlay?: boolean;
|
|
32
|
+
|
|
33
|
+
infiniteScroll?: boolean;
|
|
34
|
+
|
|
35
|
+
itemHeight?: number;
|
|
36
|
+
visibleRows?: number;
|
|
37
|
+
|
|
38
|
+
modalTitle?: string;
|
|
39
|
+
confirmText?: string;
|
|
40
|
+
cancelText?: string;
|
|
41
|
+
|
|
42
|
+
// `theme` can be a predefined mode or a full partial theme object
|
|
43
|
+
theme?: Partial<SmartDatePickerTheme> | "light" | "dark" | "auto";
|
|
44
|
+
|
|
45
|
+
primaryColor?: string;
|
|
46
|
+
backgroundColor?: string;
|
|
47
|
+
textColor?: string;
|
|
48
|
+
selectedTextColor?: string;
|
|
49
|
+
buttonTextColor?: string;
|
|
50
|
+
overlayBorderColor?: string;
|
|
51
|
+
disabledTextColor?: string;
|
|
52
|
+
selectionOverlayColor?: string;
|
|
53
|
+
headerBackgroundColor?: string;
|
|
54
|
+
wheelBackgroundColor?: string;
|
|
55
|
+
|
|
56
|
+
containerStyle?: ViewStyle;
|
|
57
|
+
wheelStyle?: ViewStyle;
|
|
58
|
+
overlayStyle?: ViewStyle;
|
|
59
|
+
textStyle?: TextStyle;
|
|
60
|
+
selectedTextStyle?: TextStyle;
|
|
61
|
+
|
|
62
|
+
customTheme?: SmartDatePickerTheme;
|
|
63
|
+
minDateTheme?: Partial<SmartDatePickerTheme>;
|
|
64
|
+
maxDateTheme?: Partial<SmartDatePickerTheme>;
|
|
65
|
+
|
|
66
|
+
onConfirm: (date: Date) => void;
|
|
67
|
+
onCancel: () => void;
|
|
68
|
+
|
|
69
|
+
onValueChange?: (date: Date) => void;
|
|
70
|
+
onOpen?: () => void;
|
|
71
|
+
onClose?: () => void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface WheelItem {
|
|
75
|
+
label: string;
|
|
76
|
+
value: number | string;
|
|
77
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const getDaysInMonth = (
|
|
2
|
+
month: number,
|
|
3
|
+
year: number
|
|
4
|
+
) => {
|
|
5
|
+
return new Date(year, month, 0).getDate();
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const buildDate = (
|
|
9
|
+
day: number,
|
|
10
|
+
month: number,
|
|
11
|
+
year: number,
|
|
12
|
+
hour: number,
|
|
13
|
+
minute: number
|
|
14
|
+
) => {
|
|
15
|
+
return new Date(
|
|
16
|
+
year,
|
|
17
|
+
month - 1,
|
|
18
|
+
day,
|
|
19
|
+
hour,
|
|
20
|
+
minute
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const clampDate = (
|
|
25
|
+
date: Date,
|
|
26
|
+
minimumDate?: Date,
|
|
27
|
+
maximumDate?: Date
|
|
28
|
+
) => {
|
|
29
|
+
if (minimumDate && date < minimumDate) {
|
|
30
|
+
return minimumDate;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (maximumDate && date > maximumDate) {
|
|
34
|
+
return maximumDate;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return date;
|
|
38
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { MONTHS } from "./constants";
|
|
2
|
+
|
|
3
|
+
export const generateDays = (
|
|
4
|
+
month: number = 1,
|
|
5
|
+
year: number = 1970
|
|
6
|
+
) => {
|
|
7
|
+
const daysInMonth = new Date(
|
|
8
|
+
year,
|
|
9
|
+
month,
|
|
10
|
+
0
|
|
11
|
+
).getDate();
|
|
12
|
+
|
|
13
|
+
return Array.from(
|
|
14
|
+
{ length: daysInMonth },
|
|
15
|
+
(_, i) => ({
|
|
16
|
+
label: String(i + 1),
|
|
17
|
+
value: i + 1,
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const generateMonths = () =>
|
|
23
|
+
MONTHS.map((month, index) => ({
|
|
24
|
+
label: month,
|
|
25
|
+
value: index + 1,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
export const generateYears = (
|
|
29
|
+
start: number = 1900,
|
|
30
|
+
end: number = new Date().getFullYear() + 50
|
|
31
|
+
) =>
|
|
32
|
+
Array.from(
|
|
33
|
+
{ length: end - start + 1 },
|
|
34
|
+
(_, i) => ({
|
|
35
|
+
label: String(start + i),
|
|
36
|
+
value: start + i,
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const generateHours = (
|
|
41
|
+
is24Hour: boolean = true
|
|
42
|
+
) =>
|
|
43
|
+
Array.from(
|
|
44
|
+
{
|
|
45
|
+
length: is24Hour ? 24 : 12,
|
|
46
|
+
},
|
|
47
|
+
(_, i) => ({
|
|
48
|
+
label: String(
|
|
49
|
+
is24Hour ? i : i + 1
|
|
50
|
+
).padStart(2, "0"),
|
|
51
|
+
value: is24Hour ? i : i + 1,
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const generateMinutes = (
|
|
56
|
+
interval = 1
|
|
57
|
+
) =>
|
|
58
|
+
Array.from(
|
|
59
|
+
{
|
|
60
|
+
length: 60 / interval,
|
|
61
|
+
},
|
|
62
|
+
(_, i) => ({
|
|
63
|
+
label: String(
|
|
64
|
+
i * interval
|
|
65
|
+
).padStart(2, "0"),
|
|
66
|
+
value: i * interval,
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
// import { MONTHS } from "./constants";
|
|
70
|
+
|
|
71
|
+
// export const generateDays = (
|
|
72
|
+
// month?: number,
|
|
73
|
+
// year?: number
|
|
74
|
+
// ) => {
|
|
75
|
+
// let totalDays = 31;
|
|
76
|
+
|
|
77
|
+
// if (month && year) {
|
|
78
|
+
// totalDays = new Date(year, month, 0).getDate();
|
|
79
|
+
// }
|
|
80
|
+
|
|
81
|
+
// return Array.from(
|
|
82
|
+
// { length: totalDays },
|
|
83
|
+
// (_, i) => ({
|
|
84
|
+
// label: String(i + 1),
|
|
85
|
+
// value: i + 1,
|
|
86
|
+
// })
|
|
87
|
+
// );
|
|
88
|
+
// };
|
|
89
|
+
|
|
90
|
+
// export const generateMonths = () =>
|
|
91
|
+
// MONTHS.map((month, index) => ({
|
|
92
|
+
// label: month,
|
|
93
|
+
// value: index + 1,
|
|
94
|
+
// }));
|
|
95
|
+
|
|
96
|
+
// export const generateYears = (
|
|
97
|
+
// start = 1900,
|
|
98
|
+
// end = new Date().getFullYear() + 50
|
|
99
|
+
// ) =>
|
|
100
|
+
// Array.from(
|
|
101
|
+
// { length: end - start + 1 },
|
|
102
|
+
// (_, i) => ({
|
|
103
|
+
// label: String(start + i),
|
|
104
|
+
// value: start + i,
|
|
105
|
+
// })
|
|
106
|
+
// );
|
|
107
|
+
|
|
108
|
+
// export const generateHours = (
|
|
109
|
+
// is24Hour = true
|
|
110
|
+
// ) =>
|
|
111
|
+
// Array.from(
|
|
112
|
+
// {
|
|
113
|
+
// length: is24Hour ? 24 : 12,
|
|
114
|
+
// },
|
|
115
|
+
// (_, i) => ({
|
|
116
|
+
// label: String(
|
|
117
|
+
// is24Hour ? i : i + 1
|
|
118
|
+
// ).padStart(2, "0"),
|
|
119
|
+
// value: is24Hour ? i : i + 1,
|
|
120
|
+
// })
|
|
121
|
+
// );
|
|
122
|
+
|
|
123
|
+
// export const generateMinutes = (
|
|
124
|
+
// step = 1
|
|
125
|
+
// ) =>
|
|
126
|
+
// Array.from(
|
|
127
|
+
// { length: 60 / step },
|
|
128
|
+
// (_, i) => ({
|
|
129
|
+
// label: String(
|
|
130
|
+
// i * step
|
|
131
|
+
// ).padStart(2, "0"),
|
|
132
|
+
// value: i * step,
|
|
133
|
+
// })
|
|
134
|
+
// );
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const validateDOB = (
|
|
2
|
+
date: Date,
|
|
3
|
+
minAge = 18
|
|
4
|
+
) => {
|
|
5
|
+
const today = new Date();
|
|
6
|
+
|
|
7
|
+
let age =
|
|
8
|
+
today.getFullYear() -
|
|
9
|
+
date.getFullYear();
|
|
10
|
+
|
|
11
|
+
const m =
|
|
12
|
+
today.getMonth() -
|
|
13
|
+
date.getMonth();
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
m < 0 ||
|
|
17
|
+
(m === 0 &&
|
|
18
|
+
today.getDate() < date.getDate())
|
|
19
|
+
) {
|
|
20
|
+
age--;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return age >= minAge;
|
|
24
|
+
};
|