@momo-kits/calendar 0.73.3-beta.5 → 0.74.2-react-native.2
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
package/TabHeader.tsx
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {TouchableWithoutFeedback, View} from 'react-native';
|
|
3
|
+
import Moment from 'moment';
|
|
4
|
+
import Util from './Util';
|
|
5
|
+
import {
|
|
6
|
+
ApplicationContext,
|
|
7
|
+
Colors,
|
|
8
|
+
Radius,
|
|
9
|
+
Spacing,
|
|
10
|
+
Text,
|
|
11
|
+
} from '@momo-kits/foundation';
|
|
12
|
+
import {TabHeaderProps, TabHeaderState} from './types';
|
|
13
|
+
|
|
14
|
+
export default class TabHeader extends React.Component<
|
|
15
|
+
TabHeaderProps,
|
|
16
|
+
TabHeaderState
|
|
17
|
+
> {
|
|
18
|
+
label;
|
|
19
|
+
defaultDate: Moment.Moment;
|
|
20
|
+
|
|
21
|
+
static contextType = ApplicationContext;
|
|
22
|
+
constructor(props: TabHeaderProps) {
|
|
23
|
+
super(props);
|
|
24
|
+
this.state = {
|
|
25
|
+
active: props.activeTab,
|
|
26
|
+
};
|
|
27
|
+
this.label = props.label;
|
|
28
|
+
this.defaultDate = props.date ? Moment(props.date) : Moment();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
onChangeTab = () => {
|
|
32
|
+
const {onChangeTab, id} = this.props;
|
|
33
|
+
onChangeTab?.(id);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
updateView = (date?: Moment.Moment | Date | null, activeTab?: boolean) => {
|
|
37
|
+
this.setState({
|
|
38
|
+
date: date ? Moment(date) : Moment(),
|
|
39
|
+
active: activeTab,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
setActiveTab = (active: boolean) => {
|
|
44
|
+
this.setState({active});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
render() {
|
|
48
|
+
const {label, disabled} = this.props;
|
|
49
|
+
const {date, active} = this.state;
|
|
50
|
+
const {theme, translate} = this.context;
|
|
51
|
+
|
|
52
|
+
const formattedDateFromState = date ? date.format('DD/MM/YYYY') : '';
|
|
53
|
+
const formattedDateFromDefault = this.defaultDate
|
|
54
|
+
? this.defaultDate.format('DD/MM/YYYY')
|
|
55
|
+
: '';
|
|
56
|
+
const dayOfWeekFromState = date
|
|
57
|
+
? `${translate(Util.WEEKDAYSFROMMOMENT[date.day()])} -`
|
|
58
|
+
: '';
|
|
59
|
+
const dayOfWeekFromDefault = this.defaultDate
|
|
60
|
+
? `${translate(Util.WEEKDAYSFROMMOMENT[this.defaultDate.day()])} -`
|
|
61
|
+
: '';
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<TouchableWithoutFeedback disabled={disabled} onPress={this.onChangeTab}>
|
|
65
|
+
<View
|
|
66
|
+
style={[
|
|
67
|
+
{
|
|
68
|
+
flex: 1,
|
|
69
|
+
padding: Spacing.S,
|
|
70
|
+
borderRadius: Radius.S,
|
|
71
|
+
},
|
|
72
|
+
active &&
|
|
73
|
+
!disabled && {
|
|
74
|
+
backgroundColor: theme.colors.background.surface,
|
|
75
|
+
},
|
|
76
|
+
]}>
|
|
77
|
+
<Text
|
|
78
|
+
typography={'description_default_regular'}
|
|
79
|
+
color={Colors.black_12}>
|
|
80
|
+
{translate(label)}
|
|
81
|
+
</Text>
|
|
82
|
+
<Text typography={'header_s_semibold'}>
|
|
83
|
+
{`${dayOfWeekFromState || dayOfWeekFromDefault || '--'} `}
|
|
84
|
+
{formattedDateFromState || formattedDateFromDefault || '--/--/----'}
|
|
85
|
+
</Text>
|
|
86
|
+
</View>
|
|
87
|
+
</TouchableWithoutFeedback>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
package/{src/Util.js → Util.ts}
RENAMED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
|
-
|
|
3
|
-
import {SwitchLanguage} from '@momo-kits/core';
|
|
4
2
|
import LunarDateConverter from './LunarDateConverter';
|
|
5
3
|
import holiday from './holidayData';
|
|
6
4
|
|
|
@@ -49,20 +47,20 @@ const I18N_MAP = {
|
|
|
49
47
|
},
|
|
50
48
|
};
|
|
51
49
|
|
|
52
|
-
const Solar = momentDate => ({
|
|
50
|
+
const Solar = (momentDate: moment.Moment) => ({
|
|
53
51
|
solarDay: momentDate.date(),
|
|
54
52
|
solarMonth: momentDate.month() + 1,
|
|
55
53
|
solarYear: momentDate.year(),
|
|
56
54
|
});
|
|
57
55
|
|
|
58
|
-
const formatYYYYMMDD = (dd, mm, yyyy) =>
|
|
56
|
+
const formatYYYYMMDD = (dd: number, mm: number, yyyy: any) =>
|
|
59
57
|
`${yyyy}-${mm < 10 ? `0${mm}` : mm}-${dd < 10 ? `0${dd}` : dd}`;
|
|
60
58
|
|
|
61
|
-
const formatDDMM = (dd, mm) =>
|
|
59
|
+
const formatDDMM = (dd: number, mm: number) =>
|
|
62
60
|
`${dd < 10 ? `0${dd}` : dd}/${mm < 10 ? `0${mm}` : mm}`;
|
|
63
61
|
|
|
64
|
-
const groupHolidaysByDate = holidays => {
|
|
65
|
-
const groupedHolidays = {};
|
|
62
|
+
const groupHolidaysByDate = (holidays: any[]) => {
|
|
63
|
+
const groupedHolidays: {[key: string]: string[]} = {};
|
|
66
64
|
if (holidays && holidays.length > 0) {
|
|
67
65
|
holidays.forEach(item => {
|
|
68
66
|
const {day, month, lunar, label} = item;
|
|
@@ -92,7 +90,7 @@ const groupHolidaysByDate = holidays => {
|
|
|
92
90
|
return groupedHolidays;
|
|
93
91
|
};
|
|
94
92
|
|
|
95
|
-
const sortByDate = arr => {
|
|
93
|
+
const sortByDate = (arr: any[]) => {
|
|
96
94
|
if (arr && arr.length > 1) {
|
|
97
95
|
arr.sort((a, b) => {
|
|
98
96
|
if (a.month > b.month || (a.month === b.month && a.day > b.day)) {
|
|
@@ -105,18 +103,10 @@ const sortByDate = arr => {
|
|
|
105
103
|
return groupHolidaysByDate(arr);
|
|
106
104
|
};
|
|
107
105
|
|
|
108
|
-
|
|
106
|
+
const Utils = {
|
|
109
107
|
WEEKDAYS: ['T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'CN'],
|
|
110
108
|
|
|
111
|
-
WEEKDAYSFROMMOMENT: [
|
|
112
|
-
SwitchLanguage.sun,
|
|
113
|
-
SwitchLanguage.mon,
|
|
114
|
-
SwitchLanguage.tue,
|
|
115
|
-
SwitchLanguage.wed,
|
|
116
|
-
SwitchLanguage.thu,
|
|
117
|
-
SwitchLanguage.fri,
|
|
118
|
-
SwitchLanguage.sat,
|
|
119
|
-
],
|
|
109
|
+
WEEKDAYSFROMMOMENT: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
|
|
120
110
|
|
|
121
111
|
WEEKDAYSNAME: [
|
|
122
112
|
'Thứ 2',
|
|
@@ -147,39 +137,30 @@ module.exports = {
|
|
|
147
137
|
|
|
148
138
|
MAX_COLUMNS: 7,
|
|
149
139
|
|
|
150
|
-
mapWeeKDate(i) {
|
|
151
|
-
const date = [
|
|
152
|
-
'',
|
|
153
|
-
SwitchLanguage.mon,
|
|
154
|
-
SwitchLanguage.tue,
|
|
155
|
-
SwitchLanguage.wed,
|
|
156
|
-
SwitchLanguage.thu,
|
|
157
|
-
SwitchLanguage.fri,
|
|
158
|
-
SwitchLanguage.sat,
|
|
159
|
-
SwitchLanguage.sun,
|
|
160
|
-
];
|
|
140
|
+
mapWeeKDate(i: number) {
|
|
141
|
+
const date = ['', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
161
142
|
return date[i];
|
|
162
143
|
},
|
|
163
144
|
|
|
164
|
-
mapMonth(i) {
|
|
145
|
+
mapMonth(i: number) {
|
|
165
146
|
const month = new Map([
|
|
166
|
-
[1,
|
|
167
|
-
[2,
|
|
168
|
-
[3,
|
|
169
|
-
[4,
|
|
170
|
-
[5,
|
|
171
|
-
[6,
|
|
172
|
-
[7,
|
|
173
|
-
[8,
|
|
174
|
-
[9,
|
|
175
|
-
[10,
|
|
176
|
-
[11,
|
|
177
|
-
[12,
|
|
147
|
+
[1, 'jan'],
|
|
148
|
+
[2, 'feb'],
|
|
149
|
+
[3, 'mar'],
|
|
150
|
+
[4, 'apr'],
|
|
151
|
+
[5, 'may'],
|
|
152
|
+
[6, 'jun'],
|
|
153
|
+
[7, 'jul'],
|
|
154
|
+
[8, 'aug'],
|
|
155
|
+
[9, 'sep'],
|
|
156
|
+
[10, 'oct'],
|
|
157
|
+
[11, 'nov'],
|
|
158
|
+
[12, 'dec'],
|
|
178
159
|
]);
|
|
179
160
|
return month.get(i);
|
|
180
161
|
},
|
|
181
162
|
|
|
182
|
-
mapMonthShorten(i) {
|
|
163
|
+
mapMonthShorten(i: number) {
|
|
183
164
|
const month = new Map([
|
|
184
165
|
[1, 'Jan'],
|
|
185
166
|
[2, 'Feb'],
|
|
@@ -197,40 +178,45 @@ module.exports = {
|
|
|
197
178
|
return month.get(i);
|
|
198
179
|
},
|
|
199
180
|
|
|
200
|
-
getDaysInMonth(month, year) {
|
|
181
|
+
getDaysInMonth(month: number, year: number) {
|
|
201
182
|
const lastDayOfMonth = new Date(year, month + 1, 0);
|
|
202
183
|
return lastDayOfMonth.getDate();
|
|
203
184
|
},
|
|
204
185
|
|
|
205
|
-
getHolidaysInMonth(headerInfo) {
|
|
186
|
+
getHolidaysInMonth(headerInfo: moment.Moment) {
|
|
206
187
|
if (headerInfo) {
|
|
207
188
|
const today = moment();
|
|
189
|
+
// @ts-ignore
|
|
208
190
|
const converter = new LunarDateConverter();
|
|
209
191
|
const startDate = moment(headerInfo).startOf('month');
|
|
210
192
|
const endDate = moment(headerInfo).endOf('month');
|
|
211
193
|
const minLunarDate = converter.SolarToLunar(Solar(startDate));
|
|
212
194
|
const maxLunarDate = converter.SolarToLunar(Solar(endDate));
|
|
213
|
-
const holidays = [];
|
|
195
|
+
const holidays: any[] = [];
|
|
214
196
|
const currentYear =
|
|
215
197
|
minLunarDate.lunarYear !== maxLunarDate.lunarYear
|
|
216
198
|
? [minLunarDate.lunarYear, maxLunarDate.lunarYear]
|
|
217
199
|
: minLunarDate.lunarYear;
|
|
218
200
|
|
|
219
201
|
// Handle Solar holidays
|
|
202
|
+
// @ts-ignore
|
|
220
203
|
if (holiday.solar[headerInfo.month() + 1]) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
holiday.solar[headerInfo.month() + 1].forEach(
|
|
206
|
+
(date: {month: number; day: any}) => {
|
|
207
|
+
const dateAsMoment = moment({
|
|
208
|
+
year: headerInfo.year(),
|
|
209
|
+
month: date.month - 1,
|
|
210
|
+
date: date.day,
|
|
211
|
+
});
|
|
212
|
+
if (dateAsMoment.isSameOrAfter(today, 'date')) {
|
|
213
|
+
holidays.push(date);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
);
|
|
231
217
|
}
|
|
232
218
|
|
|
233
|
-
holiday.lunar.forEach(item => {
|
|
219
|
+
holiday.lunar.forEach((item: {lunarDay: any; lunarMonth: any}) => {
|
|
234
220
|
if (currentYear instanceof Array) {
|
|
235
221
|
const solar1 = converter.LunarToSolar({
|
|
236
222
|
lunarDay: item.lunarDay,
|
|
@@ -303,3 +289,5 @@ module.exports = {
|
|
|
303
289
|
},
|
|
304
290
|
I18N_MAP,
|
|
305
291
|
};
|
|
292
|
+
|
|
293
|
+
export default Utils;
|
|
@@ -1,80 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
1
|
+
const holidayData = {
|
|
4
2
|
solar: {
|
|
5
3
|
1: [
|
|
6
4
|
{
|
|
7
5
|
day: 1,
|
|
8
6
|
month: 1,
|
|
9
|
-
label:
|
|
7
|
+
label: 'newYear',
|
|
10
8
|
},
|
|
11
9
|
],
|
|
12
10
|
2: [
|
|
13
11
|
{
|
|
14
12
|
day: 14,
|
|
15
13
|
month: 2,
|
|
16
|
-
label:
|
|
14
|
+
label: 'valentine',
|
|
17
15
|
},
|
|
18
16
|
],
|
|
19
17
|
3: [
|
|
20
18
|
{
|
|
21
19
|
day: 8,
|
|
22
20
|
month: 3,
|
|
23
|
-
label:
|
|
21
|
+
label: 'womenDay',
|
|
24
22
|
},
|
|
25
23
|
],
|
|
26
24
|
4: [
|
|
27
25
|
{
|
|
28
26
|
day: 30,
|
|
29
27
|
month: 4,
|
|
30
|
-
label:
|
|
28
|
+
label: 'liberationDay',
|
|
31
29
|
},
|
|
32
30
|
],
|
|
33
31
|
5: [
|
|
34
32
|
{
|
|
35
33
|
day: 1,
|
|
36
34
|
month: 5,
|
|
37
|
-
label:
|
|
35
|
+
label: 'laborDay',
|
|
38
36
|
},
|
|
39
37
|
],
|
|
40
38
|
6: [
|
|
41
39
|
{
|
|
42
40
|
day: 1,
|
|
43
41
|
month: 6,
|
|
44
|
-
label:
|
|
42
|
+
label: 'childrenDay',
|
|
45
43
|
},
|
|
46
44
|
],
|
|
47
45
|
9: [
|
|
48
46
|
{
|
|
49
47
|
day: 2,
|
|
50
48
|
month: 9,
|
|
51
|
-
label:
|
|
49
|
+
label: 'nationalDay',
|
|
52
50
|
},
|
|
53
51
|
],
|
|
54
52
|
10: [
|
|
55
53
|
{
|
|
56
54
|
day: 20,
|
|
57
55
|
month: 10,
|
|
58
|
-
label:
|
|
56
|
+
label: 'womenDayVN',
|
|
59
57
|
},
|
|
60
58
|
],
|
|
61
59
|
11: [
|
|
62
60
|
{
|
|
63
61
|
day: 20,
|
|
64
62
|
month: 11,
|
|
65
|
-
label:
|
|
63
|
+
label: 'teacherDay',
|
|
66
64
|
},
|
|
67
65
|
],
|
|
68
66
|
12: [
|
|
69
67
|
{
|
|
70
68
|
day: 24,
|
|
71
69
|
month: 12,
|
|
72
|
-
label:
|
|
70
|
+
label: 'christmasEve',
|
|
73
71
|
},
|
|
74
72
|
{
|
|
75
73
|
day: 25,
|
|
76
74
|
month: 12,
|
|
77
|
-
label:
|
|
75
|
+
label: 'christmas',
|
|
78
76
|
},
|
|
79
77
|
],
|
|
80
78
|
},
|
|
@@ -83,43 +81,45 @@ module.exports = {
|
|
|
83
81
|
lunarDay: 30,
|
|
84
82
|
lunarMonth: 12,
|
|
85
83
|
lunar: true,
|
|
86
|
-
label:
|
|
84
|
+
label: 'lunarNewYear',
|
|
87
85
|
highlight: '(30/12)',
|
|
88
86
|
},
|
|
89
87
|
{
|
|
90
88
|
lunarDay: 1,
|
|
91
89
|
lunarMonth: 1,
|
|
92
90
|
lunar: true,
|
|
93
|
-
label:
|
|
91
|
+
label: 'lunarNewYear',
|
|
94
92
|
highlight: '(1/1)',
|
|
95
93
|
},
|
|
96
94
|
{
|
|
97
95
|
lunarDay: 2,
|
|
98
96
|
lunarMonth: 1,
|
|
99
97
|
lunar: true,
|
|
100
|
-
label:
|
|
98
|
+
label: 'lunarNewYear',
|
|
101
99
|
highlight: '(2/1)',
|
|
102
100
|
},
|
|
103
101
|
{
|
|
104
102
|
lunarDay: 3,
|
|
105
103
|
lunarMonth: 1,
|
|
106
104
|
lunar: true,
|
|
107
|
-
label:
|
|
105
|
+
label: 'lunarNewYear',
|
|
108
106
|
highlight: '(3/1)',
|
|
109
107
|
},
|
|
110
108
|
{
|
|
111
109
|
lunarDay: 4,
|
|
112
110
|
lunarMonth: 1,
|
|
113
111
|
lunar: true,
|
|
114
|
-
label:
|
|
112
|
+
label: 'lunarNewYear',
|
|
115
113
|
highlight: '(4/1)',
|
|
116
114
|
},
|
|
117
115
|
{
|
|
118
116
|
lunarDay: 10,
|
|
119
117
|
lunarMonth: 3,
|
|
120
118
|
lunar: true,
|
|
121
|
-
label:
|
|
119
|
+
label: 'hungKingDay',
|
|
122
120
|
highlight: '(10/3)',
|
|
123
121
|
},
|
|
124
122
|
],
|
|
125
123
|
};
|
|
124
|
+
|
|
125
|
+
export default holidayData;
|