react-native-dates-picker 0.0.9 → 0.1.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.
Files changed (156) hide show
  1. package/README.md +27 -28
  2. package/lib/commonjs/CalendarContext.js.map +1 -1
  3. package/lib/commonjs/DateTimePicker.js +15 -8
  4. package/lib/commonjs/DateTimePicker.js.map +1 -1
  5. package/lib/commonjs/components/Calendar.js +14 -12
  6. package/lib/commonjs/components/Calendar.js.map +1 -1
  7. package/lib/commonjs/components/DatePicker.js +46 -58
  8. package/lib/commonjs/components/DatePicker.js.map +1 -1
  9. package/lib/commonjs/components/Day.js +18 -16
  10. package/lib/commonjs/components/Day.js.map +1 -1
  11. package/lib/commonjs/components/DaySelector.js +12 -12
  12. package/lib/commonjs/components/DaySelector.js.map +1 -1
  13. package/lib/commonjs/components/Header.js +27 -25
  14. package/lib/commonjs/components/Header.js.map +1 -1
  15. package/lib/commonjs/components/MonthSelector.js +9 -7
  16. package/lib/commonjs/components/MonthSelector.js.map +1 -1
  17. package/lib/commonjs/components/TimeSelector.js +22 -17
  18. package/lib/commonjs/components/TimeSelector.js.map +1 -1
  19. package/lib/commonjs/components/WheelPicker/Wheel.js +9 -4
  20. package/lib/commonjs/components/WheelPicker/Wheel.js.map +1 -1
  21. package/lib/commonjs/components/WheelPicker/WheelNative.js +14 -47
  22. package/lib/commonjs/components/WheelPicker/WheelNative.js.map +1 -1
  23. package/lib/commonjs/components/WheelPicker/WheelNativePicker/index.js +10 -0
  24. package/lib/commonjs/components/WheelPicker/WheelNativePicker/index.js.map +1 -0
  25. package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker-item.js +130 -0
  26. package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker-item.js.map +1 -0
  27. package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker.js +174 -0
  28. package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker.js.map +1 -0
  29. package/lib/commonjs/components/WheelPicker/WheelWeb.js +51 -38
  30. package/lib/commonjs/components/WheelPicker/WheelWeb.js.map +1 -1
  31. package/lib/commonjs/components/WheelPicker/animated-math.js +26 -0
  32. package/lib/commonjs/components/WheelPicker/animated-math.js.map +1 -0
  33. package/lib/commonjs/components/WheelPicker/period-native.js +36 -0
  34. package/lib/commonjs/components/WheelPicker/period-native.js.map +1 -0
  35. package/lib/commonjs/components/WheelPicker/period-picker.js +19 -0
  36. package/lib/commonjs/components/WheelPicker/period-picker.js.map +1 -0
  37. package/lib/commonjs/components/WheelPicker/period-web.js +34 -0
  38. package/lib/commonjs/components/WheelPicker/period-web.js.map +1 -0
  39. package/lib/commonjs/components/YearSelector.js +10 -8
  40. package/lib/commonjs/components/YearSelector.js.map +1 -1
  41. package/lib/commonjs/enums.js +5 -4
  42. package/lib/commonjs/enums.js.map +1 -1
  43. package/lib/commonjs/utils.js +4 -1
  44. package/lib/commonjs/utils.js.map +1 -1
  45. package/lib/module/CalendarContext.js.map +1 -1
  46. package/lib/module/DateTimePicker.js +11 -6
  47. package/lib/module/DateTimePicker.js.map +1 -1
  48. package/lib/module/components/Calendar.js +4 -4
  49. package/lib/module/components/Calendar.js.map +1 -1
  50. package/lib/module/components/DatePicker.js +36 -50
  51. package/lib/module/components/DatePicker.js.map +1 -1
  52. package/lib/module/components/Day.js +8 -8
  53. package/lib/module/components/Day.js.map +1 -1
  54. package/lib/module/components/DaySelector.js +4 -4
  55. package/lib/module/components/DaySelector.js.map +1 -1
  56. package/lib/module/components/Header.js +3 -3
  57. package/lib/module/components/Header.js.map +1 -1
  58. package/lib/module/components/MonthSelector.js +3 -2
  59. package/lib/module/components/MonthSelector.js.map +1 -1
  60. package/lib/module/components/TimeSelector.js +10 -7
  61. package/lib/module/components/TimeSelector.js.map +1 -1
  62. package/lib/module/components/WheelPicker/Wheel.js +6 -3
  63. package/lib/module/components/WheelPicker/Wheel.js.map +1 -1
  64. package/lib/module/components/WheelPicker/WheelNative.js +10 -45
  65. package/lib/module/components/WheelPicker/WheelNative.js.map +1 -1
  66. package/lib/module/components/WheelPicker/WheelNativePicker/index.js +3 -0
  67. package/lib/module/components/WheelPicker/WheelNativePicker/index.js.map +1 -0
  68. package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker-item.js +122 -0
  69. package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker-item.js.map +1 -0
  70. package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker.js +165 -0
  71. package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker.js.map +1 -0
  72. package/lib/module/components/WheelPicker/WheelWeb.js +48 -37
  73. package/lib/module/components/WheelPicker/WheelWeb.js.map +1 -1
  74. package/lib/module/components/WheelPicker/animated-math.js +20 -0
  75. package/lib/module/components/WheelPicker/animated-math.js.map +1 -0
  76. package/lib/module/components/WheelPicker/period-native.js +27 -0
  77. package/lib/module/components/WheelPicker/period-native.js.map +1 -0
  78. package/lib/module/components/WheelPicker/period-picker.js +10 -0
  79. package/lib/module/components/WheelPicker/period-picker.js.map +1 -0
  80. package/lib/module/components/WheelPicker/period-web.js +26 -0
  81. package/lib/module/components/WheelPicker/period-web.js.map +1 -0
  82. package/lib/module/components/YearSelector.js +3 -3
  83. package/lib/module/components/YearSelector.js.map +1 -1
  84. package/lib/module/enums.js +4 -3
  85. package/lib/module/enums.js.map +1 -1
  86. package/lib/module/utils.js +4 -1
  87. package/lib/module/utils.js.map +1 -1
  88. package/lib/typescript/CalendarContext.d.ts.map +1 -1
  89. package/lib/typescript/DateTimePicker.d.ts +3 -3
  90. package/lib/typescript/DateTimePicker.d.ts.map +1 -1
  91. package/lib/typescript/components/Calendar.d.ts +3 -3
  92. package/lib/typescript/components/Calendar.d.ts.map +1 -1
  93. package/lib/typescript/components/DatePicker.d.ts +2 -2
  94. package/lib/typescript/components/DatePicker.d.ts.map +1 -1
  95. package/lib/typescript/components/Day.d.ts +4 -5
  96. package/lib/typescript/components/Day.d.ts.map +1 -1
  97. package/lib/typescript/components/DaySelector.d.ts +2 -2
  98. package/lib/typescript/components/DaySelector.d.ts.map +1 -1
  99. package/lib/typescript/components/Header.d.ts +3 -3
  100. package/lib/typescript/components/Header.d.ts.map +1 -1
  101. package/lib/typescript/components/MonthSelector.d.ts +2 -2
  102. package/lib/typescript/components/MonthSelector.d.ts.map +1 -1
  103. package/lib/typescript/components/TimeSelector.d.ts +2 -2
  104. package/lib/typescript/components/TimeSelector.d.ts.map +1 -1
  105. package/lib/typescript/components/WheelPicker/Wheel.d.ts +5 -6
  106. package/lib/typescript/components/WheelPicker/Wheel.d.ts.map +1 -1
  107. package/lib/typescript/components/WheelPicker/WheelNative.d.ts +7 -8
  108. package/lib/typescript/components/WheelPicker/WheelNative.d.ts.map +1 -1
  109. package/lib/typescript/components/WheelPicker/WheelNativePicker/index.d.ts +3 -0
  110. package/lib/typescript/components/WheelPicker/WheelNativePicker/index.d.ts.map +1 -0
  111. package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker-item.d.ts +16 -0
  112. package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker-item.d.ts.map +1 -0
  113. package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker.d.ts +19 -0
  114. package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker.d.ts.map +1 -0
  115. package/lib/typescript/components/WheelPicker/WheelWeb.d.ts +6 -5
  116. package/lib/typescript/components/WheelPicker/WheelWeb.d.ts.map +1 -1
  117. package/lib/typescript/components/WheelPicker/animated-math.d.ts +5 -0
  118. package/lib/typescript/components/WheelPicker/animated-math.d.ts.map +1 -0
  119. package/lib/typescript/components/WheelPicker/period-native.d.ts +8 -0
  120. package/lib/typescript/components/WheelPicker/period-native.d.ts.map +1 -0
  121. package/lib/typescript/components/WheelPicker/period-picker.d.ts +8 -0
  122. package/lib/typescript/components/WheelPicker/period-picker.d.ts.map +1 -0
  123. package/lib/typescript/components/WheelPicker/period-web.d.ts +8 -0
  124. package/lib/typescript/components/WheelPicker/period-web.d.ts.map +1 -0
  125. package/lib/typescript/components/YearSelector.d.ts +2 -2
  126. package/lib/typescript/components/YearSelector.d.ts.map +1 -1
  127. package/lib/typescript/enums.d.ts +2 -1
  128. package/lib/typescript/enums.d.ts.map +1 -1
  129. package/lib/typescript/types.d.ts +5 -2
  130. package/lib/typescript/types.d.ts.map +1 -1
  131. package/lib/typescript/utils.d.ts +2 -2
  132. package/lib/typescript/utils.d.ts.map +1 -1
  133. package/package.json +7 -6
  134. package/src/DateTimePicker.tsx +20 -15
  135. package/src/components/Calendar.tsx +8 -8
  136. package/src/components/DatePicker.tsx +38 -66
  137. package/src/components/Day.tsx +9 -9
  138. package/src/components/DaySelector.tsx +6 -6
  139. package/src/components/Header.tsx +5 -5
  140. package/src/components/MonthSelector.tsx +4 -3
  141. package/src/components/TimeSelector.tsx +11 -12
  142. package/src/components/WheelPicker/Wheel.tsx +10 -10
  143. package/src/components/WheelPicker/WheelNative.tsx +13 -47
  144. package/src/components/WheelPicker/WheelNativePicker/index.ts +3 -0
  145. package/src/components/WheelPicker/WheelNativePicker/wheel-picker-item.tsx +140 -0
  146. package/src/components/WheelPicker/WheelNativePicker/wheel-picker.tsx +220 -0
  147. package/src/components/WheelPicker/WheelWeb.tsx +92 -65
  148. package/src/components/WheelPicker/animated-math.ts +33 -0
  149. package/src/components/WheelPicker/period-native.tsx +39 -0
  150. package/src/components/WheelPicker/period-picker.tsx +16 -0
  151. package/src/components/WheelPicker/period-web.tsx +37 -0
  152. package/src/components/YearSelector.tsx +4 -4
  153. package/src/enums.ts +4 -3
  154. package/src/types.ts +6 -2
  155. package/src/utils.ts +3 -3
  156. /package/src/{CalendarContext.tsx → CalendarContext.ts} +0 -0
@@ -1,4 +1,10 @@
1
- import { memo, useCallback, useEffect, useReducer } from 'react';
1
+ import React, { memo, useCallback, useEffect, useReducer } from 'react';
2
+ import dayjs from 'dayjs';
3
+ import utc from 'dayjs/plugin/utc';
4
+ import localeData from 'dayjs/plugin/localeData';
5
+ import relativeTime from 'dayjs/plugin/relativeTime';
6
+ import localizedFormat from 'dayjs/plugin/localizedFormat';
7
+ import 'dayjs/locale/zh-cn';
2
8
  import {
3
9
  getFormatted,
4
10
  getDate,
@@ -21,12 +27,6 @@ import type {
21
27
  MultiChange,
22
28
  } from './types';
23
29
  import Calendar from './components/Calendar';
24
- import dayjs from 'dayjs';
25
- import utc from 'dayjs/plugin/utc';
26
- import localeData from 'dayjs/plugin/localeData';
27
- import relativeTime from 'dayjs/plugin/relativeTime';
28
- import localizedFormat from 'dayjs/plugin/localizedFormat';
29
- import 'dayjs/locale/zh-cn';
30
30
 
31
31
  dayjs.extend(utc);
32
32
  dayjs.extend(localeData);
@@ -73,13 +73,12 @@ export interface DatePickerWheelProps
73
73
  onChange?: SingleChange;
74
74
  }
75
75
 
76
- const DateTimePicker = (
77
- props:
78
- | DatePickerSingleProps
79
- | DatePickerRangeProps
80
- | DatePickerMultipleProps
81
- | DatePickerWheelProps
82
- ) => {
76
+ const DateTimePicker: React.FC<
77
+ | DatePickerSingleProps
78
+ | DatePickerRangeProps
79
+ | DatePickerMultipleProps
80
+ | DatePickerWheelProps
81
+ > = (props) => {
83
82
  const {
84
83
  mode = 'single',
85
84
  locale = 'zh-cn',
@@ -121,6 +120,7 @@ const DateTimePicker = (
121
120
  currentDate = dayjs(dates[0]);
122
121
 
123
122
  if (minDate && currentDate.isBefore(minDate)) currentDate = dayjs(minDate);
123
+ if (maxDate && currentDate.isAfter(maxDate)) currentDate = dayjs(maxDate);
124
124
 
125
125
  let currentYear = currentDate.year();
126
126
 
@@ -201,7 +201,12 @@ const DateTimePicker = (
201
201
  type: CalendarActionKind.CHANGE_SELECTED_DATE,
202
202
  payload: { date },
203
203
  });
204
- }, [mode, date, startDate, endDate, dates, minDate, timePicker]);
204
+
205
+ dispatch({
206
+ type: CalendarActionKind.CHANGE_CURRENT_DATE,
207
+ payload: currentDate,
208
+ });
209
+ }, [mode, date, startDate, endDate, dates, minDate, timePicker, currentDate]);
205
210
 
206
211
  const setCalendarView = useCallback((view: CalendarViews) => {
207
212
  dispatch({ type: CalendarActionKind.SET_CALENDAR_VIEW, payload: view });
@@ -1,15 +1,15 @@
1
- import { ReactNode, memo } from 'react';
1
+ import React, { ReactNode, memo } from 'react';
2
2
  import { View, StyleSheet } from 'react-native';
3
- import { useCalendarContext } from '../CalendarContext';
4
- import type { CalendarViews } from '../enums';
5
- import type { HeaderProps, CalendarThemeProps } from '../types';
3
+ import { CONTAINER_HEIGHT } from 'src/enums';
4
+ import { useCalendarContext } from 'src/CalendarContext';
5
+ import type { CalendarViews } from 'src/enums';
6
+ import type { HeaderProps, CalendarThemeProps } from 'src/types';
6
7
  import Header from './Header';
7
8
  import YearSelector from './YearSelector';
8
9
  import MonthSelector from './MonthSelector';
9
10
  import DaySelector from './DaySelector';
10
11
  import TimeSelector from './TimeSelector';
11
12
  import DatePicker from './DatePicker';
12
- import { CALENDAR_HEIGHT } from '../enums';
13
13
 
14
14
  const CalendarView: Record<CalendarViews, ReactNode> = {
15
15
  year: <YearSelector />,
@@ -23,12 +23,12 @@ interface PropTypes extends HeaderProps {
23
23
  containerStyle?: CalendarThemeProps['containerStyle'];
24
24
  }
25
25
 
26
- const Calendar = ({
26
+ const Calendar: React.FC<PropTypes> = ({
27
27
  buttonPrevIcon,
28
28
  buttonNextIcon,
29
29
  height,
30
30
  containerStyle,
31
- }: PropTypes) => {
31
+ }) => {
32
32
  const { calendarView, mode } = useCalendarContext();
33
33
 
34
34
  const styles = StyleSheet.create({
@@ -36,7 +36,7 @@ const Calendar = ({
36
36
  width: '100%',
37
37
  },
38
38
  calendarContainer: {
39
- height: height || CALENDAR_HEIGHT,
39
+ height: height || CONTAINER_HEIGHT,
40
40
  alignItems: 'center',
41
41
  },
42
42
  });
@@ -1,23 +1,24 @@
1
- import { useCallback, useMemo } from 'react';
1
+ import React, { useCallback, useMemo } from 'react';
2
2
  import { View, StyleSheet } from 'react-native';
3
- import { useCalendarContext } from '../CalendarContext';
4
- import Wheel from './WheelPicker/Wheel';
5
- import { CALENDAR_HEIGHT } from '../enums';
3
+ import { useCalendarContext } from 'src/CalendarContext';
4
+ import { CONTAINER_HEIGHT } from 'src/enums';
6
5
  import {
7
6
  getFormatted,
8
7
  getParsedDate,
9
8
  getDaysNumInMonth,
10
9
  getTimeRange,
11
10
  getDate,
12
- } from '../utils';
11
+ } from 'src/utils';
12
+ import Wheel from './WheelPicker/Wheel';
13
13
 
14
- function createNumberList(start: number, end: number) {
15
- return new Array(end - start)
16
- .fill(0)
17
- .map((_, index) => String(index + 1 + start).padStart(2, '0'));
14
+ function createNumberList(start: number, end: number, first: number = 1) {
15
+ return new Array(end - start).fill(0).map((_, index) => ({
16
+ value: index + first + start,
17
+ text: String(index + first + start).padStart(2, '0'),
18
+ }));
18
19
  }
19
20
 
20
- const DatePicker = () => {
21
+ const DatePicker: React.FC = () => {
21
22
  const {
22
23
  columns,
23
24
  currentDate,
@@ -41,6 +42,7 @@ const DatePicker = () => {
41
42
 
42
43
  const { year: startYear, month: startMonth } = getParsedDate(minDate);
43
44
  const { year: endYear, month: endMonth } = getParsedDate(maxDate);
45
+ const { hour, minute, second } = getParsedDate(currentDate);
44
46
  const years = createNumberList(startYear - 1, endYear);
45
47
  const months = useMemo(
46
48
  () =>
@@ -57,114 +59,82 @@ const DatePicker = () => {
57
59
  );
58
60
  const hours = useMemo(
59
61
  () =>
60
- createNumberList(...getTimeRange(currentDate, minDate, maxDate, 'hour')),
62
+ createNumberList(
63
+ ...getTimeRange(currentDate, minDate, maxDate, 'hour'),
64
+ 0
65
+ ),
61
66
  [currentDate, maxDate, minDate]
62
67
  );
63
68
  const minutes = useMemo(
64
69
  () =>
65
70
  createNumberList(
66
- ...getTimeRange(currentDate, minDate, maxDate, 'minute')
71
+ ...getTimeRange(currentDate, minDate, maxDate, 'minute'),
72
+ 0
67
73
  ),
68
74
  [currentDate, maxDate, minDate]
69
75
  );
70
76
  const seconds = useMemo(
71
77
  () =>
72
78
  createNumberList(
73
- ...getTimeRange(currentDate, minDate, maxDate, 'second')
79
+ ...getTimeRange(currentDate, minDate, maxDate, 'second'),
80
+ 0
74
81
  ),
75
82
  [currentDate, maxDate, minDate]
76
83
  );
77
84
 
78
85
  const handleChangeDate = useCallback(
79
- (
80
- value: number,
81
- data: Array<string>,
82
- type: 'date' | 'hour' | 'minute' | 'second'
83
- ) => {
84
- const newDate = getDate(currentDate)[type](Number(data[value]));
86
+ (value: number, type: 'date' | 'hour' | 'minute' | 'second') => {
87
+ const newDate = getDate(currentDate).set(type, value);
85
88
  onSelectDate(getFormatted(newDate));
86
89
  },
87
90
  [currentDate, onSelectDate]
88
91
  );
89
92
 
90
- const createIndicatorStyle = useCallback(
91
- (index: number) => {
92
- const len = columns?.length || 0;
93
- if (!index && len > 1)
94
- return { borderTopRightRadius: 0, borderBottomRightRadius: 0 };
95
- else if (index === len - 1 && len > 1)
96
- return { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 };
97
- else if (len > 2) return { borderRadius: 0 };
98
- else return undefined;
99
- },
100
- [columns]
101
- );
102
-
103
93
  return (
104
94
  <View style={styles.container}>
105
95
  <View style={styles.datePickerContainer}>
106
- {columns?.map((item, index) => (
96
+ {columns?.map((item) => (
107
97
  <View style={styles.wheelContainer} key={item}>
108
98
  {item === 'year' && (
109
99
  <Wheel
110
- value={years.indexOf(String(year))}
100
+ value={year}
111
101
  items={years}
112
- key={years.length}
113
- setValue={(value) => onSelectYear(Number(years[value]))}
114
- indicatorStyle={createIndicatorStyle(index)}
102
+ setValue={(value) => onSelectYear(value)}
115
103
  />
116
104
  )}
117
105
  {item === 'month' && (
118
106
  <Wheel
119
- value={months.indexOf(String(month + 1).padStart(2, '0'))}
107
+ value={month + 1}
120
108
  items={months}
121
- key={months.length}
122
- setValue={(value) => onSelectMonth(Number(months[value]) - 1)}
123
- indicatorStyle={createIndicatorStyle(index)}
109
+ setValue={(value) => onSelectMonth(value - 1)}
124
110
  />
125
111
  )}
126
112
  {item === 'day' && (
127
113
  <Wheel
128
- value={days.indexOf(
129
- String(getDate(currentDate).date()).padStart(2, '0')
130
- )}
131
- key={days.length}
114
+ value={getDate(currentDate).date()}
132
115
  items={days}
133
- setValue={(value) => handleChangeDate(value, days, 'date')}
134
- indicatorStyle={createIndicatorStyle(index)}
116
+ setValue={(value) => handleChangeDate(value, 'date')}
135
117
  />
136
118
  )}
137
119
  {item === 'hour' && (
138
120
  <Wheel
139
- value={hours.indexOf(
140
- String(getDate(currentDate).hour()).padStart(2, '0')
141
- )}
142
- key={hours.length}
121
+ value={hour}
143
122
  items={hours}
144
- setValue={(value) => handleChangeDate(value, hours, 'hour')}
145
- indicatorStyle={createIndicatorStyle(index)}
123
+ setValue={(value) => handleChangeDate(value, 'hour')}
146
124
  />
147
125
  )}
148
126
  {item === 'minute' && (
149
127
  <Wheel
150
- value={minutes.indexOf(
151
- String(getDate(currentDate).minute()).padStart(2, '0')
152
- )}
153
- key={minutes.length}
128
+ value={minute}
154
129
  items={minutes}
155
- setValue={(value) => handleChangeDate(value, minutes, 'minute')}
156
- indicatorStyle={createIndicatorStyle(index)}
130
+ setValue={(value) => handleChangeDate(value, 'minute')}
157
131
  />
158
132
  )}
159
133
  {item === 'second' && (
160
134
  <Wheel
161
- value={seconds.indexOf(
162
- String(getDate(currentDate).second()).padStart(2, '0')
163
- )}
164
- key={seconds.length}
135
+ value={second}
165
136
  items={seconds}
166
- setValue={(value) => handleChangeDate(value, seconds, 'second')}
167
- indicatorStyle={createIndicatorStyle(index)}
137
+ setValue={(value) => handleChangeDate(value, 'second')}
168
138
  />
169
139
  )}
170
140
  </View>
@@ -179,16 +149,18 @@ const styles = StyleSheet.create({
179
149
  flex: 1,
180
150
  alignItems: 'center',
181
151
  justifyContent: 'center',
152
+ width: '100%',
182
153
  },
183
154
  wheelContainer: {
184
155
  flex: 1,
185
156
  },
186
157
  datePickerContainer: {
158
+ width: '100%',
187
159
  flexDirection: 'row',
188
160
  alignItems: 'center',
189
161
  justifyContent: 'center',
190
162
  paddingHorizontal: 16,
191
- height: CALENDAR_HEIGHT / 2,
163
+ height: CONTAINER_HEIGHT / 2,
192
164
  },
193
165
  });
194
166
 
@@ -1,9 +1,9 @@
1
- import { memo, useCallback } from 'react';
1
+ import React, { memo, useCallback } from 'react';
2
2
  import { View, Text, Pressable, StyleSheet } from 'react-native';
3
- import { CalendarThemeProps, IDayObject } from '../types';
4
- import { CALENDAR_HEIGHT } from '../enums';
5
- import { addColorAlpha } from '../utils';
6
3
  import { isEqual } from 'lodash';
4
+ import { CalendarThemeProps, IDayObject } from 'src/types';
5
+ import { CONTAINER_HEIGHT } from 'src/enums';
6
+ import { addColorAlpha } from 'src/utils';
7
7
 
8
8
  export const daySize = 46;
9
9
 
@@ -16,13 +16,13 @@ interface Props extends Omit<IDayObject, 'day'> {
16
16
  }
17
17
 
18
18
  function EmptyDayPure({ height }: { height?: number }) {
19
- const style = styles(height || CALENDAR_HEIGHT);
19
+ const style = styles(height || CONTAINER_HEIGHT);
20
20
  return <View style={style.dayCell} />;
21
21
  }
22
22
 
23
23
  export const EmptyDay = memo(EmptyDayPure);
24
24
 
25
- function Day({
25
+ const Day: React.FC<Props> = ({
26
26
  date,
27
27
  text,
28
28
  disabled,
@@ -35,7 +35,7 @@ function Day({
35
35
  onSelectDate,
36
36
  theme,
37
37
  height,
38
- }: Props) {
38
+ }) => {
39
39
  const onPress = useCallback(() => {
40
40
  onSelectDate(date);
41
41
  }, [onSelectDate, date]);
@@ -83,7 +83,7 @@ function Day({
83
83
  const rangeRootBackground =
84
84
  selectedRangeBackgroundColor ?? addColorAlpha(selectedItemColor, 0.15);
85
85
 
86
- const style = styles(height || CALENDAR_HEIGHT);
86
+ const style = styles(height || CONTAINER_HEIGHT);
87
87
 
88
88
  return (
89
89
  <View style={style.dayCell}>
@@ -138,7 +138,7 @@ function Day({
138
138
  </Pressable>
139
139
  </View>
140
140
  );
141
- }
141
+ };
142
142
 
143
143
  const styles = (height: number) =>
144
144
  StyleSheet.create({
@@ -1,8 +1,7 @@
1
- import { useMemo, useCallback } from 'react';
1
+ import React, { useMemo, useCallback } from 'react';
2
2
  import { Text, View, StyleSheet } from 'react-native';
3
3
  import dayjs from 'dayjs';
4
- import { useCalendarContext } from '../CalendarContext';
5
- import Day, { EmptyDay } from './Day';
4
+ import { useCalendarContext } from 'src/CalendarContext';
6
5
  import {
7
6
  getParsedDate,
8
7
  getMonthDays,
@@ -12,9 +11,10 @@ import {
12
11
  isDateBetween,
13
12
  getDate,
14
13
  getFormatted,
15
- } from '../utils';
14
+ } from 'src/utils';
15
+ import Day, { EmptyDay } from './Day';
16
16
 
17
- const DaySelector = () => {
17
+ const DaySelector: React.FC = () => {
18
18
  const {
19
19
  mode,
20
20
  date,
@@ -117,7 +117,7 @@ const DaySelector = () => {
117
117
  if (inRange && !leftCrop && !rightCrop) isSelected = false;
118
118
  }
119
119
  } else if (mode === 'single')
120
- isSelected = areDatesOnSameDay(day.date, currentDate);
120
+ isSelected = areDatesOnSameDay(day.date, date);
121
121
 
122
122
  return {
123
123
  ...day,
@@ -1,11 +1,11 @@
1
- import { useCallback } from 'react';
1
+ import React, { useCallback } from 'react';
2
2
  import { View, Text, Pressable, StyleSheet, Image } from 'react-native';
3
- import { useCalendarContext } from '../CalendarContext';
4
3
  import dayjs from 'dayjs';
5
- import type { HeaderProps } from '../types';
6
- import { getDateYear, getYearRange, YEAR_PAGE_SIZE } from '../utils';
4
+ import { useCalendarContext } from 'src/CalendarContext';
5
+ import type { HeaderProps } from 'src/types';
6
+ import { getDateYear, getYearRange, YEAR_PAGE_SIZE } from 'src/utils';
7
7
 
8
- const Header = ({ buttonPrevIcon, buttonNextIcon }: HeaderProps) => {
8
+ const Header: React.FC<HeaderProps> = ({ buttonPrevIcon, buttonNextIcon }) => {
9
9
  const {
10
10
  mode,
11
11
  date,
@@ -1,8 +1,9 @@
1
+ import React from 'react';
1
2
  import { Text, View, Pressable, StyleSheet } from 'react-native';
2
- import { useCalendarContext } from '../CalendarContext';
3
- import { getParsedDate, getMonths } from '../utils';
3
+ import { useCalendarContext } from 'src/CalendarContext';
4
+ import { getParsedDate, getMonths } from 'src/utils';
4
5
 
5
- const MonthSelector = () => {
6
+ const MonthSelector: React.FC = () => {
6
7
  const { currentDate, onSelectMonth, theme } = useCalendarContext();
7
8
  const { month } = getParsedDate(currentDate);
8
9
 
@@ -1,23 +1,22 @@
1
- import { useCallback } from 'react';
1
+ import React, { useCallback } from 'react';
2
2
  import { Text, View, StyleSheet } from 'react-native';
3
- import { useCalendarContext } from '../CalendarContext';
3
+ import { useCalendarContext } from 'src/CalendarContext';
4
+ import { CONTAINER_HEIGHT } from 'src/enums';
5
+ import { getParsedDate, getDate, getFormatted } from 'src/utils';
4
6
  import Wheel from './WheelPicker/Wheel';
5
- import { CALENDAR_HEIGHT } from '../enums';
6
- import { getParsedDate, getDate, getFormatted } from '../utils';
7
7
 
8
8
  function createNumberList(num: number) {
9
- return new Array(num)
10
- .fill(0)
11
- .map((_, index) =>
12
- index < 10 ? `0${index.toString()}` : index.toString()
13
- );
9
+ return new Array(num).fill(0).map((_, index) => ({
10
+ text: index.toString().padStart(2, '0'),
11
+ value: index,
12
+ }));
14
13
  }
15
14
 
16
15
  const hours = createNumberList(24);
17
16
  const minutes = createNumberList(60);
18
17
  const seconds = createNumberList(60);
19
18
 
20
- const TimeSelector = () => {
19
+ const TimeSelector: React.FC = () => {
21
20
  const { date, onSelectDate, theme } = useCalendarContext();
22
21
  const { hour, minute, second } = getParsedDate(date);
23
22
 
@@ -87,8 +86,8 @@ const styles = StyleSheet.create({
87
86
  flexDirection: 'row',
88
87
  alignItems: 'center',
89
88
  justifyContent: 'center',
90
- width: '80%',
91
- height: CALENDAR_HEIGHT / 2,
89
+ width: CONTAINER_HEIGHT / 2,
90
+ height: CONTAINER_HEIGHT / 2,
92
91
  },
93
92
  timePickerText: {
94
93
  fontSize: 24,
@@ -1,18 +1,18 @@
1
- import { Platform, type ViewStyle } from 'react-native';
1
+ import React, { memo } from 'react';
2
+ import { Platform } from 'react-native';
2
3
  import WheelNative from './WheelNative';
3
4
  import WheelWeb from './WheelWeb';
5
+ import { PickerOption } from 'src/types';
4
6
 
5
7
  interface WheelProps {
6
8
  value: number;
7
9
  setValue?: (value: number) => void;
8
- items: string[];
9
- indicatorStyle?: ViewStyle;
10
+ items: Array<PickerOption>;
10
11
  }
11
12
 
12
- export default function Wheel(props: WheelProps) {
13
- return Platform.OS === 'web' ? (
14
- <WheelWeb {...props} />
15
- ) : (
16
- <WheelNative {...props} />
17
- );
18
- }
13
+ const Wheel: React.FC<WheelProps> = (props) => {
14
+ const Component = Platform.OS === 'web' ? WheelWeb : WheelNative;
15
+ return <Component {...props} />;
16
+ };
17
+
18
+ export default memo(Wheel);
@@ -1,61 +1,27 @@
1
- import { StyleSheet, Platform, type ViewStyle } from 'react-native';
2
- import WheelPicker from 'react-native-wheely';
3
- import { useCalendarContext } from '../../CalendarContext';
1
+ import React, { memo } from 'react';
2
+ import WheelPicker from './WheelNativePicker';
3
+ import { PickerOption } from 'src/types';
4
4
 
5
5
  interface WheelProps {
6
- value: number;
7
- setValue?: (value: number) => void;
8
- items: string[];
9
- indicatorStyle?: ViewStyle;
6
+ value: number | string;
7
+ setValue?: (value: any) => void;
8
+ items: PickerOption[];
10
9
  }
11
10
 
12
- export default function WheelNative({
11
+ const WheelNative: React.FC<WheelProps> = ({
13
12
  value,
14
13
  setValue = () => {},
15
14
  items,
16
- indicatorStyle,
17
- }: WheelProps) {
18
- const { theme } = useCalendarContext();
19
-
15
+ }) => {
20
16
  return (
21
17
  <WheelPicker
22
- selectedIndex={value < 0 ? 0 : value}
18
+ value={value}
23
19
  options={items}
24
20
  onChange={setValue}
25
- containerStyle={{
26
- ...styles.container,
27
- ...theme?.wheelPickerContainerStyle,
28
- }}
29
- itemStyle={theme?.wheelPickerItemStyle}
30
- itemTextStyle={{
31
- ...styles.wheelPickerText,
32
- ...theme?.wheelPickerTextStyle,
33
- }}
34
- selectedIndicatorStyle={{
35
- ...styles.wheelSelectedIndicator,
36
- ...indicatorStyle,
37
- ...theme?.wheelPickerIndicatorStyle,
38
- }}
39
- itemHeight={45}
40
- decelerationRate={theme?.wheelPickerDecelerationRate}
21
+ itemHeight={44}
22
+ decelerationRate="fast"
41
23
  />
42
24
  );
43
- }
25
+ };
44
26
 
45
- const styles = StyleSheet.create({
46
- container: {
47
- display: 'flex',
48
- ...Platform.select({
49
- web: {
50
- userSelect: 'none',
51
- },
52
- }),
53
- },
54
- wheelSelectedIndicator: {
55
- borderRadius: 10,
56
- },
57
- wheelPickerText: {
58
- fontSize: 18,
59
- fontWeight: '500',
60
- },
61
- });
27
+ export default memo(WheelNative);
@@ -0,0 +1,3 @@
1
+ import WheelPicker from './wheel-picker';
2
+
3
+ export default WheelPicker;