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.
Files changed (74) hide show
  1. package/README.md +163 -0
  2. package/lib/components/DateColumn.d.ts +3 -0
  3. package/lib/components/DateColumn.d.ts.map +1 -0
  4. package/lib/components/DateColumn.js +12 -0
  5. package/lib/components/HourColumn.d.ts +3 -0
  6. package/lib/components/HourColumn.d.ts.map +1 -0
  7. package/lib/components/HourColumn.js +12 -0
  8. package/lib/components/MinuteColumn.d.ts +3 -0
  9. package/lib/components/MinuteColumn.d.ts.map +1 -0
  10. package/lib/components/MinuteColumn.js +12 -0
  11. package/lib/components/MonthColumn.d.ts +3 -0
  12. package/lib/components/MonthColumn.d.ts.map +1 -0
  13. package/lib/components/MonthColumn.js +12 -0
  14. package/lib/components/PickerModal.d.ts +10 -0
  15. package/lib/components/PickerModal.d.ts.map +1 -0
  16. package/lib/components/PickerModal.js +27 -0
  17. package/lib/components/SelectionOverlay.d.ts +10 -0
  18. package/lib/components/SelectionOverlay.d.ts.map +1 -0
  19. package/lib/components/SelectionOverlay.js +26 -0
  20. package/lib/components/SmartDatePicker.d.ts +4 -0
  21. package/lib/components/SmartDatePicker.d.ts.map +1 -0
  22. package/lib/components/SmartDatePicker.js +154 -0
  23. package/lib/components/WheelColumn.d.ts +17 -0
  24. package/lib/components/WheelColumn.d.ts.map +1 -0
  25. package/lib/components/WheelColumn.js +126 -0
  26. package/lib/components/YearColumn.d.ts +3 -0
  27. package/lib/components/YearColumn.d.ts.map +1 -0
  28. package/lib/components/YearColumn.js +12 -0
  29. package/lib/hooks/useDatePicker.d.ts +13 -0
  30. package/lib/hooks/useDatePicker.d.ts.map +1 -0
  31. package/lib/hooks/useDatePicker.js +31 -0
  32. package/lib/hooks/useTheme.d.ts +13 -0
  33. package/lib/hooks/useTheme.d.ts.map +1 -0
  34. package/lib/hooks/useTheme.js +7 -0
  35. package/lib/hooks/useWheel.d.ts +5 -0
  36. package/lib/hooks/useWheel.d.ts.map +1 -0
  37. package/lib/hooks/useWheel.js +12 -0
  38. package/lib/index.d.ts +3 -0
  39. package/lib/index.d.ts.map +1 -0
  40. package/lib/index.js +23 -0
  41. package/lib/types/index.d.ts +59 -0
  42. package/lib/types/index.d.ts.map +1 -0
  43. package/lib/types/index.js +2 -0
  44. package/lib/utils/constants.d.ts +4 -0
  45. package/lib/utils/constants.d.ts.map +1 -0
  46. package/lib/utils/constants.js +19 -0
  47. package/lib/utils/dateUtils.d.ts +4 -0
  48. package/lib/utils/dateUtils.d.ts.map +1 -0
  49. package/lib/utils/dateUtils.js +21 -0
  50. package/lib/utils/generateData.d.ts +21 -0
  51. package/lib/utils/generateData.d.ts.map +1 -0
  52. package/lib/utils/generateData.js +95 -0
  53. package/lib/utils/validateDOB.d.ts +2 -0
  54. package/lib/utils/validateDOB.d.ts.map +1 -0
  55. package/lib/utils/validateDOB.js +17 -0
  56. package/package.json +54 -0
  57. package/src/components/DateColumn.tsx +14 -0
  58. package/src/components/HourColumn.tsx +14 -0
  59. package/src/components/MinuteColumn.tsx +14 -0
  60. package/src/components/MonthColumn.tsx +14 -0
  61. package/src/components/PickerModal.tsx +60 -0
  62. package/src/components/SelectionOverlay.tsx +45 -0
  63. package/src/components/SmartDatePicker.tsx +318 -0
  64. package/src/components/WheelColumn.tsx +231 -0
  65. package/src/components/YearColumn.tsx +14 -0
  66. package/src/hooks/useDatePicker.ts +47 -0
  67. package/src/hooks/useTheme.ts +18 -0
  68. package/src/hooks/useWheel.ts +13 -0
  69. package/src/index.ts +3 -0
  70. package/src/types/index.ts +77 -0
  71. package/src/utils/constants.ts +17 -0
  72. package/src/utils/dateUtils.ts +38 -0
  73. package/src/utils/generateData.ts +134 -0
  74. 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,17 @@
1
+ export const ITEM_HEIGHT = 44;
2
+ export const VISIBLE_ITEMS = 5;
3
+
4
+ export const MONTHS = [
5
+ "Jan",
6
+ "Feb",
7
+ "Mar",
8
+ "Apr",
9
+ "May",
10
+ "Jun",
11
+ "Jul",
12
+ "Aug",
13
+ "Sep",
14
+ "Oct",
15
+ "Nov",
16
+ "Dec",
17
+ ];
@@ -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
+ };