@momo-kits/calendar 0.0.73-beta → 0.72.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/index.js +1 -1
- package/package.json +17 -16
- package/publish.sh +2 -2
- package/src/Calendar.js +476 -343
- package/src/CalendarPro.js +391 -318
- package/src/Day/index.js +215 -175
- package/src/Day/style.js +114 -116
- package/src/HeaderControl.js +65 -61
- package/src/LunarDateConverter.js +186 -179
- package/src/LunarService.js +76 -40
- package/src/Month/index.js +74 -65
- package/src/MonthList.js +232 -237
- package/src/TabHeader.js +60 -67
- package/src/Util.js +273 -193
- package/src/calendarPicker/Day.js +120 -128
- package/src/calendarPicker/Days.js +208 -181
- package/src/calendarPicker/HeaderControls.js +145 -136
- package/src/calendarPicker/WeekDaysLabels.js +18 -13
- package/src/calendarPicker/index.js +100 -100
- package/src/calendarPicker/styles.js +175 -176
- package/src/calendarPicker/util.js +75 -41
- package/src/holidayData.js +121 -123
|
@@ -1,203 +1,230 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {
|
|
1
|
+
import React, {Component} from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
3
|
import styles from './styles';
|
|
4
|
-
import {
|
|
4
|
+
import {getDaysInMonth, MAX_COLUMNS, MAX_ROWS} from './util';
|
|
5
5
|
import Day from './Day';
|
|
6
6
|
|
|
7
7
|
export default class Days extends Component {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.state = {
|
|
11
|
+
selectedDay: 0,
|
|
12
|
+
selectedMonth: 0,
|
|
13
|
+
selectedYear: 0,
|
|
14
|
+
};
|
|
15
|
+
this.selectedDate = null;
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
18
|
+
componentDidMount() {
|
|
19
|
+
const {selectedDate} = this.props;
|
|
20
|
+
if (selectedDate) {
|
|
21
|
+
const temp = selectedDate;
|
|
22
|
+
if (typeof temp.getDate === 'function') {
|
|
23
|
+
this.selectedDate = temp;
|
|
24
|
+
} else {
|
|
25
|
+
this.selectedDate = new Date(temp);
|
|
26
|
+
}
|
|
27
|
+
this.updateSelectedStates(
|
|
28
|
+
this.selectedDate.getDate(),
|
|
29
|
+
this.selectedDate.getMonth(),
|
|
30
|
+
this.selectedDate.getFullYear(),
|
|
31
|
+
);
|
|
33
32
|
}
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
35
|
+
updateSelectedStates = (day, month, year) => {
|
|
36
|
+
const {onDayChange} = this.props;
|
|
37
|
+
// const monthTmp = month + 1;
|
|
38
|
+
this.setState({
|
|
39
|
+
selectedDay: day,
|
|
40
|
+
selectedMonth: month,
|
|
41
|
+
selectedYear: year,
|
|
42
|
+
});
|
|
43
|
+
if (onDayChange) {
|
|
44
|
+
onDayChange(day, month, year);
|
|
46
45
|
}
|
|
46
|
+
};
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (maxDate) {
|
|
60
|
-
maxDate.setHours(0, 0, 0, 0);
|
|
61
|
-
if (selectDate > maxDate) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
this.updateSelectedStates(day, month, year);
|
|
48
|
+
onPressDay = (day, month, year) => {
|
|
49
|
+
const {minDate, maxDate} = this.props;
|
|
50
|
+
const selectDate = new Date(year, month, day);
|
|
51
|
+
selectDate.setHours(0, 0, 0, 0);
|
|
52
|
+
if (minDate) {
|
|
53
|
+
minDate.setHours(0, 0, 0, 0);
|
|
54
|
+
if (selectDate < minDate) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
66
57
|
}
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
let j;
|
|
77
|
-
let currentDay = 0;
|
|
78
|
-
const thisMonthFirstDay = new Date(year, month, 1);
|
|
79
|
-
let slotsAccumulator = 1;
|
|
80
|
-
|
|
81
|
-
let goNextMonth = false;
|
|
82
|
-
for (i = 0; i < MAX_ROWS; i += 1) { // Week rows
|
|
83
|
-
columns = [];
|
|
84
|
-
if (goNextMonth) { break; }
|
|
85
|
-
for (j = 0; j < MAX_COLUMNS; j += 1) { // Day columns
|
|
86
|
-
// HungHC: getDay() Sunday is 0, Monday is 1, and so on.
|
|
87
|
-
let tmp = thisMonthFirstDay.getDay();
|
|
88
|
-
if (tmp === 0) { tmp = 7; }
|
|
89
|
-
if (slotsAccumulator >= tmp) {
|
|
90
|
-
if (currentDay < getDaysInMonth(month, year)) {
|
|
91
|
-
const day = currentDay + 1;
|
|
92
|
-
const selected = (selectedDay === day
|
|
93
|
-
&& selectedMonth === month
|
|
94
|
-
&& selectedYear === year);
|
|
95
|
-
const date = Date(year, month, day);
|
|
59
|
+
if (maxDate) {
|
|
60
|
+
maxDate.setHours(0, 0, 0, 0);
|
|
61
|
+
if (selectDate > maxDate) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this.updateSelectedStates(day, month, year);
|
|
66
|
+
};
|
|
96
67
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
68
|
+
getCalendarDays = () => {
|
|
69
|
+
const {
|
|
70
|
+
month,
|
|
71
|
+
year,
|
|
72
|
+
mode,
|
|
73
|
+
minDate,
|
|
74
|
+
maxDate,
|
|
75
|
+
firstDate,
|
|
76
|
+
secondDate,
|
|
77
|
+
tabSelected,
|
|
78
|
+
} = this.props;
|
|
79
|
+
const {selectedMonth, selectedDay, selectedYear} = this.state;
|
|
80
|
+
let columns;
|
|
81
|
+
const matrix = [];
|
|
82
|
+
let i;
|
|
83
|
+
let j;
|
|
84
|
+
let currentDay = 0;
|
|
85
|
+
const thisMonthFirstDay = new Date(year, month, 1);
|
|
86
|
+
let slotsAccumulator = 1;
|
|
111
87
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
88
|
+
let goNextMonth = false;
|
|
89
|
+
for (i = 0; i < MAX_ROWS; i += 1) {
|
|
90
|
+
// Week rows
|
|
91
|
+
columns = [];
|
|
92
|
+
if (goNextMonth) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
for (j = 0; j < MAX_COLUMNS; j += 1) {
|
|
96
|
+
// Day columns
|
|
97
|
+
// HungHC: getDay() Sunday is 0, Monday is 1, and so on.
|
|
98
|
+
let tmp = thisMonthFirstDay.getDay();
|
|
99
|
+
if (tmp === 0) {
|
|
100
|
+
tmp = 7;
|
|
101
|
+
}
|
|
102
|
+
if (slotsAccumulator >= tmp) {
|
|
103
|
+
if (currentDay < getDaysInMonth(month, year)) {
|
|
104
|
+
const day = currentDay + 1;
|
|
105
|
+
const selected =
|
|
106
|
+
selectedDay === day &&
|
|
107
|
+
selectedMonth === month &&
|
|
108
|
+
selectedYear === year;
|
|
109
|
+
const date = Date(year, month, day);
|
|
122
110
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
onDayChange={this.onPressDay}
|
|
150
|
-
/>);
|
|
151
|
-
currentDay += 1;
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
// HungHC: show prev month
|
|
155
|
-
let prevMonth = month - 1;
|
|
156
|
-
let yearTmp = year;
|
|
157
|
-
if (prevMonth < 0) {
|
|
158
|
-
prevMonth = 11;
|
|
159
|
-
yearTmp = year - 1;
|
|
160
|
-
}
|
|
161
|
-
const daysPrev = getDaysInMonth(prevMonth, yearTmp);
|
|
162
|
-
let tmpDay = thisMonthFirstDay.getDay();
|
|
163
|
-
if (tmpDay === 0) { tmpDay = 7; }
|
|
164
|
-
const delta = (slotsAccumulator - tmpDay + 1);
|
|
165
|
-
const day = daysPrev + delta;
|
|
111
|
+
columns.push(
|
|
112
|
+
<Day
|
|
113
|
+
mode={mode}
|
|
114
|
+
key={j.toString()}
|
|
115
|
+
column={j}
|
|
116
|
+
day={day}
|
|
117
|
+
month={month}
|
|
118
|
+
year={year}
|
|
119
|
+
selected={selected}
|
|
120
|
+
date={date}
|
|
121
|
+
minDate={minDate}
|
|
122
|
+
maxDate={maxDate}
|
|
123
|
+
firstDate={firstDate}
|
|
124
|
+
secondDate={secondDate}
|
|
125
|
+
tabSelected={tabSelected}
|
|
126
|
+
otherMonth={false}
|
|
127
|
+
onDayChange={this.onPressDay}
|
|
128
|
+
/>,
|
|
129
|
+
);
|
|
130
|
+
currentDay += 1;
|
|
131
|
+
} else {
|
|
132
|
+
// HungHC: show next month
|
|
133
|
+
goNextMonth = true;
|
|
134
|
+
if (j === 0) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
166
137
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
138
|
+
let nextMonth = month + 1;
|
|
139
|
+
const day = currentDay + 1 - getDaysInMonth(month, year);
|
|
140
|
+
let yearTmp = year;
|
|
141
|
+
if (nextMonth > 11) {
|
|
142
|
+
nextMonth = 0;
|
|
143
|
+
yearTmp = year + 1;
|
|
144
|
+
}
|
|
145
|
+
const date = Date(yearTmp, nextMonth, day);
|
|
146
|
+
const selected =
|
|
147
|
+
selectedDay === day &&
|
|
148
|
+
selectedMonth === nextMonth &&
|
|
149
|
+
selectedYear === yearTmp;
|
|
150
|
+
columns.push(
|
|
151
|
+
<Day
|
|
152
|
+
mode={mode}
|
|
153
|
+
key={j.toString()}
|
|
154
|
+
column={j}
|
|
155
|
+
day={day}
|
|
156
|
+
month={nextMonth}
|
|
157
|
+
year={yearTmp}
|
|
158
|
+
selected={selected}
|
|
159
|
+
date={date}
|
|
160
|
+
minDate={minDate}
|
|
161
|
+
maxDate={maxDate}
|
|
162
|
+
firstDate={firstDate}
|
|
163
|
+
secondDate={secondDate}
|
|
164
|
+
tabSelected={tabSelected}
|
|
165
|
+
otherMonth
|
|
166
|
+
onDayChange={this.onPressDay}
|
|
167
|
+
/>,
|
|
168
|
+
);
|
|
169
|
+
currentDay += 1;
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
// HungHC: show prev month
|
|
173
|
+
let prevMonth = month - 1;
|
|
174
|
+
let yearTmp = year;
|
|
175
|
+
if (prevMonth < 0) {
|
|
176
|
+
prevMonth = 11;
|
|
177
|
+
yearTmp = year - 1;
|
|
178
|
+
}
|
|
179
|
+
const daysPrev = getDaysInMonth(prevMonth, yearTmp);
|
|
180
|
+
let tmpDay = thisMonthFirstDay.getDay();
|
|
181
|
+
if (tmpDay === 0) {
|
|
182
|
+
tmpDay = 7;
|
|
183
|
+
}
|
|
184
|
+
const delta = slotsAccumulator - tmpDay + 1;
|
|
185
|
+
const day = daysPrev + delta;
|
|
170
186
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
column={j}
|
|
176
|
-
day={day}
|
|
177
|
-
month={prevMonth}
|
|
178
|
-
year={yearTmp}
|
|
179
|
-
selected={selected}
|
|
180
|
-
date={date}
|
|
181
|
-
minDate={minDate}
|
|
182
|
-
maxDate={maxDate}
|
|
183
|
-
firstDate={firstDate}
|
|
184
|
-
secondDate={secondDate}
|
|
185
|
-
tabSelected={tabSelected}
|
|
186
|
-
otherMonth
|
|
187
|
-
onDayChange={this.onPressDay}
|
|
188
|
-
/>);
|
|
189
|
-
}
|
|
187
|
+
const selected =
|
|
188
|
+
selectedDay === day &&
|
|
189
|
+
selectedMonth === prevMonth &&
|
|
190
|
+
selectedYear === yearTmp;
|
|
190
191
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
const date = Date(yearTmp, prevMonth, day);
|
|
193
|
+
columns.push(
|
|
194
|
+
<Day
|
|
195
|
+
mode={mode}
|
|
196
|
+
key={j.toString()}
|
|
197
|
+
column={j}
|
|
198
|
+
day={day}
|
|
199
|
+
month={prevMonth}
|
|
200
|
+
year={yearTmp}
|
|
201
|
+
selected={selected}
|
|
202
|
+
date={date}
|
|
203
|
+
minDate={minDate}
|
|
204
|
+
maxDate={maxDate}
|
|
205
|
+
firstDate={firstDate}
|
|
206
|
+
secondDate={secondDate}
|
|
207
|
+
tabSelected={tabSelected}
|
|
208
|
+
otherMonth
|
|
209
|
+
onDayChange={this.onPressDay}
|
|
210
|
+
/>,
|
|
211
|
+
);
|
|
195
212
|
}
|
|
196
213
|
|
|
197
|
-
|
|
214
|
+
slotsAccumulator += 1;
|
|
215
|
+
}
|
|
216
|
+
matrix[i] = [];
|
|
217
|
+
matrix[i].push(
|
|
218
|
+
<View key={i.toString()} style={styles.weekRow}>
|
|
219
|
+
{columns}
|
|
220
|
+
</View>,
|
|
221
|
+
);
|
|
198
222
|
}
|
|
199
223
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
224
|
+
return matrix;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
render() {
|
|
228
|
+
return <View style={styles.daysWrapper}>{this.getCalendarDays()}</View>;
|
|
229
|
+
}
|
|
203
230
|
}
|