@momo-kits/calendar 0.73.3-beta.4 → 0.74.2-react-native.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/CalendarPro.tsx +390 -0
- package/Day.tsx +221 -0
- package/HeaderControl.tsx +55 -0
- package/{src/LunarDateConverter.js → LunarDateConverter.ts} +43 -27
- package/{src/LunarService.js → LunarService.ts} +16 -10
- package/Month.tsx +114 -0
- package/{src/MonthList.js → MonthList.tsx} +96 -62
- package/TabHeader.tsx +90 -0
- package/{src/Util.js → Util.ts} +45 -57
- package/{src/holidayData.js → holidayData.ts} +20 -20
- package/{src/Calendar.js → index.tsx} +133 -182
- package/package.json +13 -13
- package/styles.ts +123 -0
- package/types.ts +200 -0
- package/index.js +0 -4
- package/src/CalendarPro.js +0 -436
- package/src/Day/index.js +0 -233
- package/src/Day/style.js +0 -127
- package/src/HeaderControl.js +0 -83
- package/src/Month/index.js +0 -89
- package/src/Month/style.js +0 -0
- package/src/TabHeader.js +0 -72
- package/src/calendarPicker/Day.js +0 -146
- package/src/calendarPicker/Days.js +0 -230
- package/src/calendarPicker/HeaderControls.js +0 -167
- package/src/calendarPicker/WeekDaysLabels.js +0 -27
- package/src/calendarPicker/index.js +0 -125
- package/src/calendarPicker/styles.js +0 -183
- package/src/calendarPicker/util.js +0 -84
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import React, {Component} from 'react';
|
|
2
|
-
import {TouchableOpacity, View, Text} from 'react-native';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import styles from './styles';
|
|
5
|
-
|
|
6
|
-
export default class Day extends Component {
|
|
7
|
-
processMinDate() {
|
|
8
|
-
const {minDate} = this.props;
|
|
9
|
-
if (minDate) {
|
|
10
|
-
minDate.setHours(0, 0, 0, 0);
|
|
11
|
-
if (this.date < minDate) {
|
|
12
|
-
this.disableTouch = true;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
processMaxDate() {
|
|
18
|
-
const {maxDate} = this.props;
|
|
19
|
-
if (maxDate) {
|
|
20
|
-
maxDate.setHours(0, 0, 0, 0);
|
|
21
|
-
if (this.date > maxDate) {
|
|
22
|
-
this.disableTouch = true;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
processDoubleDate() {
|
|
28
|
-
const {mode, otherMonth, firstDate, secondDate, tabSelected} = this.props;
|
|
29
|
-
const {date} = this;
|
|
30
|
-
if (mode === 'doubleDate' && !otherMonth) {
|
|
31
|
-
if (firstDate && tabSelected === 1) {
|
|
32
|
-
firstDate.setHours(0, 0, 0, 0);
|
|
33
|
-
if (date < firstDate) {
|
|
34
|
-
this.disableTouch = true;
|
|
35
|
-
this.styleDouble = {};
|
|
36
|
-
} else if (date.getTime() === firstDate.getTime()) {
|
|
37
|
-
this.colorCanTouch = '#2eb3e8';
|
|
38
|
-
this.colorText = 'white';
|
|
39
|
-
this.styleDouble = {};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (secondDate && firstDate) {
|
|
43
|
-
secondDate.setHours(0, 0, 0, 0);
|
|
44
|
-
if (date > firstDate && date < secondDate) {
|
|
45
|
-
this.colorCanTouch = '#90d6f3';
|
|
46
|
-
|
|
47
|
-
this.styleDouble = styles.styleBetween;
|
|
48
|
-
|
|
49
|
-
this.colorText = 'white';
|
|
50
|
-
}
|
|
51
|
-
if (secondDate.getTime() !== firstDate.getTime()) {
|
|
52
|
-
if (date.getTime() === firstDate.getTime()) {
|
|
53
|
-
this.colorCanTouch = '#2eb3e8';
|
|
54
|
-
this.colorText = 'white';
|
|
55
|
-
this.styleDouble = styles.styleFirstDate;
|
|
56
|
-
}
|
|
57
|
-
if (date.getTime() === secondDate.getTime()) {
|
|
58
|
-
this.styleDouble = styles.styleSecondDate;
|
|
59
|
-
this.colorCanTouch = '#2eb3e8';
|
|
60
|
-
this.colorText = 'white';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
processSelected() {
|
|
68
|
-
const {selected} = this.props;
|
|
69
|
-
if (selected && !this.disableTouch) {
|
|
70
|
-
this.colorCanTouch = '#2eb3e8';
|
|
71
|
-
this.colorText = 'white';
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
processDateNow() {
|
|
76
|
-
const {selected} = this.props;
|
|
77
|
-
if (!selected && this.date.getTime() === this.dateNow.getTime()) {
|
|
78
|
-
this.colorCanTouch = '#8F8E94';
|
|
79
|
-
this.colorText = 'white';
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
processOtherMonth() {
|
|
84
|
-
const {otherMonth} = this.props;
|
|
85
|
-
if (otherMonth) {
|
|
86
|
-
this.colorTextDisable = 'white';
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
processRender() {
|
|
91
|
-
this.processMinDate();
|
|
92
|
-
this.processMaxDate();
|
|
93
|
-
// this.processDateNow()
|
|
94
|
-
this.processDoubleDate();
|
|
95
|
-
this.processSelected();
|
|
96
|
-
this.processOtherMonth();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
render() {
|
|
100
|
-
const {day, month, year, otherMonth, onDayChange} = this.props;
|
|
101
|
-
this.colorCanTouch = 'white';
|
|
102
|
-
this.colorText = '#393939';
|
|
103
|
-
this.colorTextDisable = '#DADADA';
|
|
104
|
-
this.styleDouble = {};
|
|
105
|
-
this.disableTouch = false;
|
|
106
|
-
this.dateNow = new Date();
|
|
107
|
-
this.dateNow.setHours(0, 0, 0, 0);
|
|
108
|
-
this.date = new Date(year, month, day);
|
|
109
|
-
this.date.setHours(0, 0, 0, 0);
|
|
110
|
-
this.processRender();
|
|
111
|
-
return (
|
|
112
|
-
<View style={styles.dayWrapper}>
|
|
113
|
-
<View style={this.styleDouble} />
|
|
114
|
-
{this.disableTouch || otherMonth ? (
|
|
115
|
-
<View style={styles.dayButton}>
|
|
116
|
-
<Text.Title
|
|
117
|
-
style={[styles.dayLabel, {color: this.colorTextDisable}]}>
|
|
118
|
-
{day}
|
|
119
|
-
</Text.Title>
|
|
120
|
-
</View>
|
|
121
|
-
) : (
|
|
122
|
-
<View
|
|
123
|
-
style={[
|
|
124
|
-
styles.dayButtonSelected,
|
|
125
|
-
{backgroundColor: this.colorCanTouch},
|
|
126
|
-
]}>
|
|
127
|
-
<TouchableOpacity
|
|
128
|
-
style={styles.dayButton}
|
|
129
|
-
onPress={() => onDayChange(day, month, year)}>
|
|
130
|
-
<Text.Title style={[styles.dayLabel, {color: this.colorText}]}>
|
|
131
|
-
{day}
|
|
132
|
-
</Text.Title>
|
|
133
|
-
</TouchableOpacity>
|
|
134
|
-
</View>
|
|
135
|
-
)}
|
|
136
|
-
</View>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
Day.propTypes = {
|
|
141
|
-
day: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
142
|
-
month: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
143
|
-
year: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
144
|
-
otherMonth: PropTypes.bool,
|
|
145
|
-
onDayChange: PropTypes.func,
|
|
146
|
-
};
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import React, {Component} from 'react';
|
|
2
|
-
import {View} from 'react-native';
|
|
3
|
-
import styles from './styles';
|
|
4
|
-
import {getDaysInMonth, MAX_COLUMNS, MAX_ROWS} from './util';
|
|
5
|
-
import Day from './Day';
|
|
6
|
-
|
|
7
|
-
export default class Days extends Component {
|
|
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
|
-
|
|
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
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
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);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
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
|
-
}
|
|
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);
|
|
66
|
-
};
|
|
67
|
-
|
|
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;
|
|
87
|
-
|
|
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);
|
|
110
|
-
|
|
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
|
-
}
|
|
137
|
-
|
|
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;
|
|
186
|
-
|
|
187
|
-
const selected =
|
|
188
|
-
selectedDay === day &&
|
|
189
|
-
selectedMonth === prevMonth &&
|
|
190
|
-
selectedYear === yearTmp;
|
|
191
|
-
|
|
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
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
slotsAccumulator += 1;
|
|
215
|
-
}
|
|
216
|
-
matrix[i] = [];
|
|
217
|
-
matrix[i].push(
|
|
218
|
-
<View key={i.toString()} style={styles.weekRow}>
|
|
219
|
-
{columns}
|
|
220
|
-
</View>,
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return matrix;
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
render() {
|
|
228
|
-
return <View style={styles.daysWrapper}>{this.getCalendarDays()}</View>;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
import React, {Component} from 'react';
|
|
3
|
-
import {Text, TouchableOpacity, View} from 'react-native';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import {IconSource, Image} from '@momo-kits/core';
|
|
6
|
-
import {DatePicker} from '@momo-kits/date-picker';
|
|
7
|
-
import styles from './styles';
|
|
8
|
-
import {MONTHS} from './util';
|
|
9
|
-
|
|
10
|
-
const padding = input => `${input > 9 ? input : `0${input}`}`;
|
|
11
|
-
|
|
12
|
-
const formatDate = date => {
|
|
13
|
-
if (date && typeof date.getDate === 'function') {
|
|
14
|
-
return `${padding(date.getMonth() + 1)}/${date.getFullYear().toString()}`;
|
|
15
|
-
}
|
|
16
|
-
return null;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const makeRange = (min = 0, max = 9999, step = 1) => {
|
|
20
|
-
const range = [];
|
|
21
|
-
let entry = `${0}`;
|
|
22
|
-
|
|
23
|
-
for (min; min <= max; min += step) {
|
|
24
|
-
entry = `${min}`;
|
|
25
|
-
range.push(entry);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return range;
|
|
29
|
-
};
|
|
30
|
-
export default class HeaderControls extends Component {
|
|
31
|
-
constructor(props) {
|
|
32
|
-
super(props);
|
|
33
|
-
const {month} = this.props;
|
|
34
|
-
this.state = {
|
|
35
|
-
selectedMonth: month,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const minYear = 1900 + new Date().getYear();
|
|
39
|
-
const maxYear = minYear + 5;
|
|
40
|
-
this.months = makeRange(1, 12);
|
|
41
|
-
this.years = makeRange(minYear, maxYear);
|
|
42
|
-
this.momoDatePicker = React.createRef();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
setMonth = month => {
|
|
46
|
-
this.setState({
|
|
47
|
-
selectedMonth: month,
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
getNext = () => {
|
|
52
|
-
const {selectedMonth} = this.state;
|
|
53
|
-
const {getNextYear, onMonthChange} = this.props;
|
|
54
|
-
let next = selectedMonth + 1;
|
|
55
|
-
if (next > 11) {
|
|
56
|
-
next = 0;
|
|
57
|
-
this.setState({selectedMonth: next});
|
|
58
|
-
getNextYear();
|
|
59
|
-
} else {
|
|
60
|
-
this.setState({selectedMonth: next});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
onMonthChange(next);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
getPrevious = () => {
|
|
67
|
-
const {selectedMonth} = this.state;
|
|
68
|
-
const {onMonthChange, year, minDate, getPrevYear} = this.props;
|
|
69
|
-
|
|
70
|
-
let prev = selectedMonth - 1;
|
|
71
|
-
if (prev < 0) {
|
|
72
|
-
prev = 11;
|
|
73
|
-
this.setState({selectedMonth: prev});
|
|
74
|
-
getPrevYear();
|
|
75
|
-
onMonthChange(prev);
|
|
76
|
-
} else if (year <= minDate.getFullYear() && prev < minDate.getMonth()) {
|
|
77
|
-
return null;
|
|
78
|
-
} else {
|
|
79
|
-
this.setState({selectedMonth: prev});
|
|
80
|
-
onMonthChange(prev);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
pickMonthYear = () => {
|
|
85
|
-
const {navigator, minDate, maxDate} = this.props;
|
|
86
|
-
navigator.showBottom({
|
|
87
|
-
screen: DatePicker,
|
|
88
|
-
params: {
|
|
89
|
-
dragDisabled: true,
|
|
90
|
-
onSelected: this.onMonthYearChange,
|
|
91
|
-
onClose: () => {},
|
|
92
|
-
selectedDate: formatDate(minDate),
|
|
93
|
-
minDate: formatDate(minDate),
|
|
94
|
-
maxDate: formatDate(maxDate),
|
|
95
|
-
format: 'MM/YYYY',
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
onMonthYearChange = date => {
|
|
101
|
-
const {onMonthYearChange} = this.props;
|
|
102
|
-
const splitDate = date.split('/');
|
|
103
|
-
const idM = +splitDate[0];
|
|
104
|
-
const idY = +splitDate[1];
|
|
105
|
-
this.setState({
|
|
106
|
-
selectedMonth: idM - 1,
|
|
107
|
-
});
|
|
108
|
-
if (onMonthYearChange) {
|
|
109
|
-
onMonthYearChange(idM - 1, idY);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
render() {
|
|
114
|
-
const {selectedMonth} = this.state;
|
|
115
|
-
const {year, minDate} = this.props;
|
|
116
|
-
const previous = selectedMonth - 1 < 0 ? 11 : selectedMonth - 1;
|
|
117
|
-
const opacity =
|
|
118
|
-
previous < minDate.getMonth() && minDate.getFullYear() === year ? 0.2 : 1;
|
|
119
|
-
// const monthNow = (new Date()).getMonth() + 1;
|
|
120
|
-
// const yearNow = (new Date()).getYear() + 1900;
|
|
121
|
-
return (
|
|
122
|
-
<View style={styles.headerWrapper}>
|
|
123
|
-
<TouchableOpacity
|
|
124
|
-
onPress={() => this.getPrevious()}
|
|
125
|
-
style={{paddingHorizontal: 20}}>
|
|
126
|
-
<Image
|
|
127
|
-
style={{
|
|
128
|
-
width: 20,
|
|
129
|
-
height: 20,
|
|
130
|
-
opacity,
|
|
131
|
-
}}
|
|
132
|
-
source={IconSource.ic_back_arrow}
|
|
133
|
-
/>
|
|
134
|
-
</TouchableOpacity>
|
|
135
|
-
|
|
136
|
-
<TouchableOpacity onPress={this.pickMonthYear}>
|
|
137
|
-
<Text style={styles.monthLabel}>
|
|
138
|
-
{MONTHS[selectedMonth]}/{year}
|
|
139
|
-
</Text>
|
|
140
|
-
</TouchableOpacity>
|
|
141
|
-
|
|
142
|
-
<TouchableOpacity
|
|
143
|
-
onPress={() => this.getNext()}
|
|
144
|
-
style={{paddingHorizontal: 20}}>
|
|
145
|
-
<Image
|
|
146
|
-
style={{
|
|
147
|
-
width: 20,
|
|
148
|
-
height: 20,
|
|
149
|
-
}}
|
|
150
|
-
source={IconSource.ic_arrow_next}
|
|
151
|
-
/>
|
|
152
|
-
</TouchableOpacity>
|
|
153
|
-
</View>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
HeaderControls.propTypes = {
|
|
159
|
-
getNextYear: PropTypes.func,
|
|
160
|
-
onMonthChange: PropTypes.func,
|
|
161
|
-
onMonthYearChange: PropTypes.func,
|
|
162
|
-
getPrevYear: PropTypes.func,
|
|
163
|
-
year: PropTypes.number,
|
|
164
|
-
minDate: PropTypes.any,
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
HeaderControls.defaultProps = {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {View} from 'react-native';
|
|
3
|
-
|
|
4
|
-
import {Text} from '@momo-kits/core';
|
|
5
|
-
import styles from './styles';
|
|
6
|
-
import {WEEKDAYS} from './util';
|
|
7
|
-
|
|
8
|
-
const colorDay = '#9199a2';
|
|
9
|
-
const WeekDaysLabels = () => (
|
|
10
|
-
<View style={styles.dayLabelsWrapper}>
|
|
11
|
-
{WEEKDAYS.map((day, key) => (
|
|
12
|
-
<Text.Title1
|
|
13
|
-
key={key.toString()}
|
|
14
|
-
style={[
|
|
15
|
-
styles.dayLabels,
|
|
16
|
-
{
|
|
17
|
-
color: colorDay,
|
|
18
|
-
fontSize: 16,
|
|
19
|
-
},
|
|
20
|
-
]}>
|
|
21
|
-
{day}
|
|
22
|
-
</Text.Title1>
|
|
23
|
-
))}
|
|
24
|
-
</View>
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
export default WeekDaysLabels;
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/no-typos */
|
|
2
|
-
import React, {Component} from 'react';
|
|
3
|
-
import {View} from 'react-native';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import styles from './styles';
|
|
6
|
-
import HeaderControls from './HeaderControls';
|
|
7
|
-
import Days from './Days';
|
|
8
|
-
import WeekDaysLabels from './WeekDaysLabels';
|
|
9
|
-
|
|
10
|
-
class CalendarPicker extends Component {
|
|
11
|
-
constructor(props) {
|
|
12
|
-
super(props);
|
|
13
|
-
|
|
14
|
-
this.selectedDate = null;
|
|
15
|
-
const temp = props.selectedDate;
|
|
16
|
-
try {
|
|
17
|
-
if (typeof temp.getDate === 'function') {
|
|
18
|
-
this.selectedDate = temp;
|
|
19
|
-
} else {
|
|
20
|
-
this.selectedDate = new Date(temp);
|
|
21
|
-
}
|
|
22
|
-
} catch (e) {
|
|
23
|
-
this.selectedDate = new Date();
|
|
24
|
-
}
|
|
25
|
-
this.state = {
|
|
26
|
-
// date: this.selectedDate,
|
|
27
|
-
month: this.selectedDate.getMonth(),
|
|
28
|
-
day: this.selectedDate.getDate(),
|
|
29
|
-
year: this.selectedDate.getFullYear(),
|
|
30
|
-
// selectedDay: [],
|
|
31
|
-
tabSelected: 0,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
onDayChange = (day, month, year) => {
|
|
36
|
-
const {onDateChange} = this.props;
|
|
37
|
-
const date = new Date(year, month, day);
|
|
38
|
-
if (onDateChange) {
|
|
39
|
-
onDateChange(date);
|
|
40
|
-
}
|
|
41
|
-
if (this.refs.header) {
|
|
42
|
-
this.refs.header.setMonth(month);
|
|
43
|
-
}
|
|
44
|
-
this.setState({
|
|
45
|
-
year,
|
|
46
|
-
month,
|
|
47
|
-
day,
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
onMonthYearChange = (month, year) => {
|
|
52
|
-
this.setState({
|
|
53
|
-
month,
|
|
54
|
-
year,
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
onMonthChange = month => {
|
|
59
|
-
this.setState({month});
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
getNextYear = () => {
|
|
63
|
-
const {year} = this.state;
|
|
64
|
-
this.setState({year: parseInt(year) + 1});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
getPrevYear = () => {
|
|
68
|
-
const {year} = this.state;
|
|
69
|
-
this.setState({year: parseInt(year) - 1});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
setDoubleDateAndTabIndex = (first, second, tabSelected) => {
|
|
73
|
-
this.setState({
|
|
74
|
-
firstDate: first,
|
|
75
|
-
secondDate: second,
|
|
76
|
-
tabSelected,
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
render() {
|
|
81
|
-
const {day, year, month, firstDate, secondDate, tabSelected} = this.state;
|
|
82
|
-
const {minDate, maxDate, mode, navigator} = this.props;
|
|
83
|
-
return (
|
|
84
|
-
<View style={styles.calendar}>
|
|
85
|
-
<HeaderControls
|
|
86
|
-
ref="header"
|
|
87
|
-
year={year}
|
|
88
|
-
month={month}
|
|
89
|
-
navigator={navigator}
|
|
90
|
-
onMonthYearChange={this.onMonthYearChange}
|
|
91
|
-
onMonthChange={this.onMonthChange}
|
|
92
|
-
getNextYear={this.getNextYear}
|
|
93
|
-
getPrevYear={this.getPrevYear}
|
|
94
|
-
minDate={minDate || null}
|
|
95
|
-
/>
|
|
96
|
-
<WeekDaysLabels />
|
|
97
|
-
|
|
98
|
-
<Days
|
|
99
|
-
mode={mode}
|
|
100
|
-
firstDate={firstDate}
|
|
101
|
-
secondDate={secondDate}
|
|
102
|
-
tabSelected={tabSelected}
|
|
103
|
-
month={month}
|
|
104
|
-
year={year}
|
|
105
|
-
day={day}
|
|
106
|
-
minDate={minDate || new Date()}
|
|
107
|
-
maxDate={maxDate}
|
|
108
|
-
selectedDate={this.selectedDate}
|
|
109
|
-
onDayChange={this.onDayChange}
|
|
110
|
-
/>
|
|
111
|
-
</View>
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default CalendarPicker;
|
|
117
|
-
|
|
118
|
-
CalendarPicker.propTypes = {
|
|
119
|
-
navigator: PropTypes.object.isRequired,
|
|
120
|
-
minDate: PropTypes.any,
|
|
121
|
-
maxDate: PropTypes.any,
|
|
122
|
-
mode: PropTypes.oneOf(['doubleDate', 'signleDate']),
|
|
123
|
-
selectedDate: PropTypes.any,
|
|
124
|
-
onDateChange: PropTypes.func,
|
|
125
|
-
};
|