@momo-kits/calendar 0.79.4 → 0.79.6
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.tsx +3 -0
- package/package.json +8 -10
- package/src/{Calendar.js → Calendar.tsx} +50 -89
- package/src/{CalendarPro.js → CalendarPro.tsx} +100 -100
- package/src/Day/{index.js → index.tsx} +50 -35
- package/src/Day/{style.js → style.ts} +6 -20
- package/src/{HeaderControl.js → HeaderControl.tsx} +8 -22
- package/src/Month/{index.js → index.tsx} +4 -5
- package/src/{MonthList.js → MonthList.tsx} +5 -3
- package/src/{TabHeader.js → TabHeader.tsx} +12 -14
- package/src/{holidayData.js → holidayData.ts} +17 -19
- package/types.ts +70 -0
- package/index.js +0 -4
- 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/src/{LunarDateConverter.js → LunarDateConverter.ts} +0 -0
- /package/src/{LunarService.js → LunarService.ts} +0 -0
- /package/src/Month/{style.js → style.ts} +0 -0
- /package/src/{Util.js → Util.ts} +0 -0
package/index.tsx
ADDED
package/package.json
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/calendar",
|
|
3
|
-
"version": "0.79.
|
|
3
|
+
"version": "0.79.6",
|
|
4
4
|
"private": false,
|
|
5
|
-
"main": "index.
|
|
6
|
-
"dependencies": {
|
|
7
|
-
"@momo-kits/date-picker": "latest",
|
|
8
|
-
"moment": "^2.24.0",
|
|
9
|
-
"@momo-platform/versions": "4.0.2"
|
|
10
|
-
},
|
|
5
|
+
"main": "index.tsx",
|
|
11
6
|
"peerDependencies": {
|
|
7
|
+
"@momo-kits/foundation": "latest",
|
|
12
8
|
"react": "16.9.0",
|
|
13
9
|
"react-native": ">=0.55",
|
|
14
|
-
"prop-types": "^15.7.2"
|
|
15
|
-
"@momo-kits/core-v2": ">=0.0.5-beta"
|
|
10
|
+
"prop-types": "^15.7.2"
|
|
16
11
|
},
|
|
17
12
|
"devDependencies": {},
|
|
18
|
-
"license": "MoMo"
|
|
13
|
+
"license": "MoMo",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"moment": "^2.24.0"
|
|
16
|
+
}
|
|
19
17
|
}
|
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import React, {Component, useCallback} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Dimensions,
|
|
4
|
+
LayoutChangeEvent,
|
|
5
|
+
ScrollView,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
View,
|
|
8
|
+
} from 'react-native';
|
|
4
9
|
import moment from 'moment';
|
|
5
10
|
import {
|
|
11
|
+
ApplicationContext,
|
|
6
12
|
Colors,
|
|
7
13
|
Radius,
|
|
8
|
-
|
|
9
|
-
SwitchLanguage,
|
|
14
|
+
Switch,
|
|
10
15
|
Text,
|
|
11
|
-
} from '@momo-kits/
|
|
12
|
-
import Switch from '@momo-kits/switch';
|
|
16
|
+
} from '@momo-kits/foundation';
|
|
13
17
|
import CalendarPro from './CalendarPro';
|
|
14
18
|
import TabHeader from './TabHeader';
|
|
19
|
+
import {CalendarProps, CalendarState} from '../types';
|
|
15
20
|
|
|
16
21
|
const DOUBLE = 'doubleDate';
|
|
22
|
+
const SINGLE = 'singleDate';
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
class Calendar extends Component<CalendarProps, CalendarState> {
|
|
25
|
+
static contextType = ApplicationContext;
|
|
26
|
+
doubleDate;
|
|
27
|
+
tabSelected;
|
|
28
|
+
selectedDate;
|
|
29
|
+
calendarPicker;
|
|
30
|
+
cellHeader1;
|
|
31
|
+
cellHeader2;
|
|
32
|
+
cellHeaderSingle;
|
|
33
|
+
constructor(props: CalendarProps) {
|
|
21
34
|
super(props);
|
|
22
35
|
this.doubleDate = props.doubleDate
|
|
23
36
|
? {
|
|
@@ -35,6 +48,7 @@ class Calendar extends Component {
|
|
|
35
48
|
|
|
36
49
|
this.state = {
|
|
37
50
|
isDoubleDateMode: props.mode === DOUBLE,
|
|
51
|
+
containerWidth: 0,
|
|
38
52
|
};
|
|
39
53
|
this.calendarPicker = React.createRef();
|
|
40
54
|
this.cellHeader1 = React.createRef();
|
|
@@ -71,7 +85,7 @@ class Calendar extends Component {
|
|
|
71
85
|
}
|
|
72
86
|
}
|
|
73
87
|
|
|
74
|
-
onChangeTab = idTab => {
|
|
88
|
+
onChangeTab = (idTab: number) => {
|
|
75
89
|
this.props.onChangeTab && this.props.onChangeTab(idTab);
|
|
76
90
|
|
|
77
91
|
this.tabSelected = idTab;
|
|
@@ -122,12 +136,6 @@ class Calendar extends Component {
|
|
|
122
136
|
this.tabSelected,
|
|
123
137
|
);
|
|
124
138
|
if (onDateChange) {
|
|
125
|
-
// const cloned = {
|
|
126
|
-
// first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
|
|
127
|
-
// this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
|
|
128
|
-
// second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
|
|
129
|
-
// this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
|
|
130
|
-
// };
|
|
131
139
|
onDateChange({
|
|
132
140
|
first: this.doubleDate.first
|
|
133
141
|
? this.doubleDate.first.toDate()
|
|
@@ -157,11 +165,6 @@ class Calendar extends Component {
|
|
|
157
165
|
? this.doubleDate.second.toDate()
|
|
158
166
|
: null,
|
|
159
167
|
});
|
|
160
|
-
// const cloned = {
|
|
161
|
-
// first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
|
|
162
|
-
// second: this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
|
|
163
|
-
// };
|
|
164
|
-
// onDateChange(cloned);
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
170
|
}
|
|
@@ -195,11 +198,6 @@ class Calendar extends Component {
|
|
|
195
198
|
? this.doubleDate.second.toDate()
|
|
196
199
|
: null,
|
|
197
200
|
});
|
|
198
|
-
// const cloned = {
|
|
199
|
-
// first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
|
|
200
|
-
// second: this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
|
|
201
|
-
// };
|
|
202
|
-
// onDateChange(cloned);
|
|
203
201
|
}
|
|
204
202
|
} else {
|
|
205
203
|
this.doubleDate.first = this.selectedDate;
|
|
@@ -235,7 +233,7 @@ class Calendar extends Component {
|
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
235
|
|
|
238
|
-
onDateChange = date => {
|
|
236
|
+
onDateChange = (date: moment.Moment) => {
|
|
239
237
|
this.selectedDate = date;
|
|
240
238
|
this.updateView();
|
|
241
239
|
};
|
|
@@ -268,11 +266,6 @@ class Calendar extends Component {
|
|
|
268
266
|
? this.doubleDate.second.toDate()
|
|
269
267
|
: null,
|
|
270
268
|
});
|
|
271
|
-
// const cloned = {
|
|
272
|
-
// first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
|
|
273
|
-
// second: this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
|
|
274
|
-
// };
|
|
275
|
-
// onDateChange(cloned);
|
|
276
269
|
}
|
|
277
270
|
}
|
|
278
271
|
} else {
|
|
@@ -286,10 +279,7 @@ class Calendar extends Component {
|
|
|
286
279
|
} else {
|
|
287
280
|
this.cellHeaderSingle.current.updateView(this.selectedDate, true);
|
|
288
281
|
}
|
|
289
|
-
|
|
290
282
|
if (onDateChange) {
|
|
291
|
-
// const clone = moment(this.selectedDate);
|
|
292
|
-
// const cloned = new Date(clone.year(), clone.month(), clone.date());
|
|
293
283
|
onDateChange(this.selectedDate.toDate());
|
|
294
284
|
}
|
|
295
285
|
}
|
|
@@ -312,20 +302,16 @@ class Calendar extends Component {
|
|
|
312
302
|
|
|
313
303
|
renderSwitchReturnSelection = () => {
|
|
314
304
|
const {isDoubleDateMode} = this.state;
|
|
305
|
+
const {translate} = this.context;
|
|
315
306
|
return (
|
|
316
307
|
<View style={styles.headerContainer}>
|
|
317
308
|
<View style={styles.viewSwitch}>
|
|
318
|
-
<Text
|
|
319
|
-
{
|
|
320
|
-
</Text
|
|
309
|
+
<Text typography={'label_default'} style={styles.textSwitch}>
|
|
310
|
+
{translate('chooseRoundtrip')}
|
|
311
|
+
</Text>
|
|
321
312
|
<Switch
|
|
322
313
|
value={isDoubleDateMode}
|
|
323
314
|
onChange={this.toggleSelectionDateMode}
|
|
324
|
-
thumbColor={isDoubleDateMode ? '#78ca32' : 'white'}
|
|
325
|
-
trackColor={{
|
|
326
|
-
false: '#e5e7ec',
|
|
327
|
-
true: '#e5e7ec',
|
|
328
|
-
}}
|
|
329
315
|
/>
|
|
330
316
|
</View>
|
|
331
317
|
<View style={styles.seperator} />
|
|
@@ -342,7 +328,7 @@ class Calendar extends Component {
|
|
|
342
328
|
id={0}
|
|
343
329
|
ref={this.cellHeader1}
|
|
344
330
|
onChangeTab={this.onChangeTab}
|
|
345
|
-
label={headerFrom ||
|
|
331
|
+
label={headerFrom || 'depart'}
|
|
346
332
|
activeTab
|
|
347
333
|
date={this.doubleDate.first}
|
|
348
334
|
/>
|
|
@@ -351,7 +337,7 @@ class Calendar extends Component {
|
|
|
351
337
|
id={1}
|
|
352
338
|
ref={this.cellHeader2}
|
|
353
339
|
onChangeTab={this.onChangeTab}
|
|
354
|
-
label={headerTo ||
|
|
340
|
+
label={headerTo || 'return'}
|
|
355
341
|
activeTab={false}
|
|
356
342
|
date=""
|
|
357
343
|
/>
|
|
@@ -362,7 +348,7 @@ class Calendar extends Component {
|
|
|
362
348
|
id={1}
|
|
363
349
|
disabled
|
|
364
350
|
ref={this.cellHeaderSingle}
|
|
365
|
-
label={headerFrom ||
|
|
351
|
+
label={headerFrom || 'depart'}
|
|
366
352
|
activeTab
|
|
367
353
|
date={this.selectedDate}
|
|
368
354
|
/>
|
|
@@ -370,7 +356,13 @@ class Calendar extends Component {
|
|
|
370
356
|
);
|
|
371
357
|
};
|
|
372
358
|
|
|
373
|
-
setDateRange = (
|
|
359
|
+
setDateRange = (
|
|
360
|
+
dateRange: {
|
|
361
|
+
startDate: moment.MomentInput | undefined;
|
|
362
|
+
endDate: moment.MomentInput | undefined;
|
|
363
|
+
},
|
|
364
|
+
isScrollToStartDate: any,
|
|
365
|
+
) => {
|
|
374
366
|
const {mode, doubleDate = {}} = this.props;
|
|
375
367
|
if (mode === 'doubleDate') {
|
|
376
368
|
this.cellHeader1.current.updateView(
|
|
@@ -394,6 +386,10 @@ class Calendar extends Component {
|
|
|
394
386
|
}
|
|
395
387
|
};
|
|
396
388
|
|
|
389
|
+
onLayout = (e: LayoutChangeEvent) => {
|
|
390
|
+
this.setState({containerWidth: e.nativeEvent.layout.width});
|
|
391
|
+
};
|
|
392
|
+
|
|
397
393
|
render() {
|
|
398
394
|
const {
|
|
399
395
|
isOffLunar,
|
|
@@ -412,17 +408,10 @@ class Calendar extends Component {
|
|
|
412
408
|
disabledWeekend,
|
|
413
409
|
style,
|
|
414
410
|
} = this.props;
|
|
415
|
-
|
|
416
|
-
const {
|
|
411
|
+
|
|
412
|
+
const {isDoubleDateMode, containerWidth} = this.state;
|
|
417
413
|
return (
|
|
418
|
-
<ScrollView
|
|
419
|
-
style={[
|
|
420
|
-
styles.scrollView,
|
|
421
|
-
{
|
|
422
|
-
width: width - ScaleSize(24),
|
|
423
|
-
},
|
|
424
|
-
style,
|
|
425
|
-
]}>
|
|
414
|
+
<ScrollView onLayout={this.onLayout} style={[styles.scrollView, style]}>
|
|
426
415
|
<View
|
|
427
416
|
style={{
|
|
428
417
|
backgroundColor: Colors.black_01,
|
|
@@ -432,6 +421,7 @@ class Calendar extends Component {
|
|
|
432
421
|
{!isHideHeaderPanel && this.renderHeaderPanel()}
|
|
433
422
|
</View>
|
|
434
423
|
<CalendarPro
|
|
424
|
+
containerWidth={containerWidth}
|
|
435
425
|
disabledWeekend={disabledWeekend}
|
|
436
426
|
priceList={priceList}
|
|
437
427
|
ref={this.calendarPicker}
|
|
@@ -457,36 +447,6 @@ class Calendar extends Component {
|
|
|
457
447
|
|
|
458
448
|
export default Calendar;
|
|
459
449
|
|
|
460
|
-
Calendar.propTypes = {
|
|
461
|
-
doubleDate: PropTypes.shape({
|
|
462
|
-
first: PropTypes.any,
|
|
463
|
-
second: PropTypes.any,
|
|
464
|
-
}),
|
|
465
|
-
id: PropTypes.any,
|
|
466
|
-
isHiddenSwitch: PropTypes.bool,
|
|
467
|
-
isShowLunar: PropTypes.bool,
|
|
468
|
-
mode: PropTypes.string,
|
|
469
|
-
onCTAStateChange: PropTypes.func,
|
|
470
|
-
onCallbackCalendar: PropTypes.func,
|
|
471
|
-
onDateChange: PropTypes.func,
|
|
472
|
-
selectedDate: PropTypes.any,
|
|
473
|
-
priceList: PropTypes.any,
|
|
474
|
-
labelFrom: PropTypes.string,
|
|
475
|
-
labelTo: PropTypes.string,
|
|
476
|
-
headerFrom: PropTypes.string,
|
|
477
|
-
headerTo: PropTypes.string,
|
|
478
|
-
isHideLabel: PropTypes.bool,
|
|
479
|
-
isHideHoliday: PropTypes.bool,
|
|
480
|
-
minDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
|
|
481
|
-
maxDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
|
|
482
|
-
style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
Calendar.defaultProps = {
|
|
486
|
-
mode: 'single',
|
|
487
|
-
isHiddenSwitch: false,
|
|
488
|
-
};
|
|
489
|
-
|
|
490
450
|
const styles = StyleSheet.create({
|
|
491
451
|
viewPanel_2: {
|
|
492
452
|
height: 50,
|
|
@@ -507,7 +467,7 @@ const styles = StyleSheet.create({
|
|
|
507
467
|
flexDirection: 'row',
|
|
508
468
|
justifyContent: 'space-between',
|
|
509
469
|
alignItems: 'center',
|
|
510
|
-
backgroundColor: Colors.
|
|
470
|
+
backgroundColor: Colors.black_01,
|
|
511
471
|
height: 42,
|
|
512
472
|
},
|
|
513
473
|
seperator: {
|
|
@@ -523,5 +483,6 @@ const styles = StyleSheet.create({
|
|
|
523
483
|
flex: 1,
|
|
524
484
|
backgroundColor: 'transparent',
|
|
525
485
|
alignSelf: 'center',
|
|
486
|
+
width: '100%',
|
|
526
487
|
},
|
|
527
488
|
});
|
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
/* eslint-disable no-bitwise */
|
|
2
1
|
import React, {Component} from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
Dimensions,
|
|
7
|
-
ScrollView,
|
|
8
|
-
StyleSheet,
|
|
9
|
-
TouchableWithoutFeedback,
|
|
10
|
-
View,
|
|
11
|
-
} from 'react-native';
|
|
3
|
+
import {Dimensions, ScrollView, StyleSheet, View} from 'react-native';
|
|
12
4
|
import Moment from 'moment';
|
|
13
5
|
import {
|
|
6
|
+
ApplicationContext,
|
|
7
|
+
CheckBox,
|
|
14
8
|
Colors,
|
|
15
|
-
IconSource,
|
|
16
|
-
Image,
|
|
17
9
|
Radius,
|
|
18
10
|
Spacing,
|
|
19
|
-
SwitchLanguage,
|
|
20
11
|
Text,
|
|
21
|
-
} from '@momo-kits/
|
|
12
|
+
} from '@momo-kits/foundation';
|
|
22
13
|
import MonthList from './MonthList';
|
|
23
14
|
import HeaderControl from './HeaderControl';
|
|
24
15
|
import LunarDateConverter from './LunarDateConverter';
|
|
25
16
|
import Util from './Util';
|
|
17
|
+
import {CalendarProProps, CalendarProState} from '../types';
|
|
26
18
|
|
|
27
19
|
const widthScreen = Dimensions.get('window').width;
|
|
28
20
|
|
|
29
|
-
export default class CalendarPro extends Component
|
|
30
|
-
|
|
21
|
+
export default class CalendarPro extends Component<
|
|
22
|
+
CalendarProProps,
|
|
23
|
+
CalendarProState
|
|
24
|
+
> {
|
|
25
|
+
static contextType = ApplicationContext;
|
|
26
|
+
today: Moment.Moment;
|
|
27
|
+
year: number;
|
|
28
|
+
header: Moment.Moment;
|
|
29
|
+
selectedDate: Date;
|
|
30
|
+
converter: typeof LunarDateConverter;
|
|
31
|
+
minDate?: Moment.Moment;
|
|
32
|
+
maxDate?: Moment.Moment;
|
|
33
|
+
|
|
34
|
+
constructor(props: CalendarProProps) {
|
|
31
35
|
super(props);
|
|
32
36
|
this.today = Moment();
|
|
33
37
|
this.year = this.today.year();
|
|
@@ -45,7 +49,10 @@ export default class CalendarPro extends Component {
|
|
|
45
49
|
this.converter = new LunarDateConverter();
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
static getDerivedStateFromProps(
|
|
52
|
+
static getDerivedStateFromProps(
|
|
53
|
+
nextProps: {isShowLunar: any},
|
|
54
|
+
prevState: {ownUpdate: any; showLunar: any},
|
|
55
|
+
) {
|
|
49
56
|
if (prevState.ownUpdate) {
|
|
50
57
|
return {
|
|
51
58
|
ownUpdate: false,
|
|
@@ -57,7 +64,10 @@ export default class CalendarPro extends Component {
|
|
|
57
64
|
return null;
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
setDateRange = (
|
|
67
|
+
setDateRange = (
|
|
68
|
+
dateRange: {startDate: any; endDate: any},
|
|
69
|
+
isScrollToStartDate: any,
|
|
70
|
+
) => {
|
|
61
71
|
if (dateRange && dateRange.startDate && dateRange.endDate) {
|
|
62
72
|
this.setState(
|
|
63
73
|
{
|
|
@@ -74,23 +84,13 @@ export default class CalendarPro extends Component {
|
|
|
74
84
|
}
|
|
75
85
|
};
|
|
76
86
|
|
|
77
|
-
ownSetState(state) {
|
|
87
|
+
ownSetState(state: CalendarProState) {
|
|
78
88
|
this.setState({
|
|
79
89
|
...state,
|
|
80
90
|
ownUpdate: true,
|
|
81
91
|
});
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
loadLabel = (data, type) => {
|
|
85
|
-
const {i18n, customI18n} = this.props;
|
|
86
|
-
if (~['w', 'weekday', 'text'].indexOf(type)) {
|
|
87
|
-
return (customI18n[type] || {})[data] || Util.I18N_MAP[i18n][type][data];
|
|
88
|
-
}
|
|
89
|
-
if (type === 'date') {
|
|
90
|
-
return data.format(customI18n[type] || Util.I18N_MAP[i18n][type]);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
94
|
getDateRange = () => {
|
|
95
95
|
const {maxDate, minDate, format} = this.props;
|
|
96
96
|
let max = Moment(maxDate, format);
|
|
@@ -112,7 +112,7 @@ export default class CalendarPro extends Component {
|
|
|
112
112
|
this.maxDate = max;
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
-
onChoose = day => {
|
|
115
|
+
onChoose = (day: number) => {
|
|
116
116
|
const {startDate, tabSelected} = this.state;
|
|
117
117
|
const {isDoubleDateMode, onDateChange} = this.props;
|
|
118
118
|
if (isDoubleDateMode) {
|
|
@@ -143,7 +143,10 @@ export default class CalendarPro extends Component {
|
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
-
executeProcessAfterScrollCalendar = (
|
|
146
|
+
executeProcessAfterScrollCalendar = (
|
|
147
|
+
date: Moment.MomentInput | undefined,
|
|
148
|
+
key: any,
|
|
149
|
+
) => {
|
|
147
150
|
const holidays = Object.values(Util.getHolidaysInMonth(Moment(date)));
|
|
148
151
|
const {showLunar} = this.state;
|
|
149
152
|
if (this.refs && this.refs.HeaderControl) {
|
|
@@ -163,7 +166,10 @@ export default class CalendarPro extends Component {
|
|
|
163
166
|
});
|
|
164
167
|
};
|
|
165
168
|
|
|
166
|
-
onScrollCalendar = data
|
|
169
|
+
onScrollCalendar = (data: {
|
|
170
|
+
key: any;
|
|
171
|
+
date: Moment.MomentInput | undefined;
|
|
172
|
+
}) => {
|
|
167
173
|
const {headerKey} = this.state;
|
|
168
174
|
if (data) {
|
|
169
175
|
if (data.key !== headerKey) {
|
|
@@ -172,7 +178,11 @@ export default class CalendarPro extends Component {
|
|
|
172
178
|
}
|
|
173
179
|
};
|
|
174
180
|
|
|
175
|
-
setDoubleDateAndTabIndex = (
|
|
181
|
+
setDoubleDateAndTabIndex = (
|
|
182
|
+
firstDate: Moment.MomentInput | undefined,
|
|
183
|
+
secondDate: Moment.MomentInput | undefined,
|
|
184
|
+
tabSelected: any,
|
|
185
|
+
) => {
|
|
176
186
|
this.ownSetState({
|
|
177
187
|
startDate: firstDate ? Moment(firstDate) : null,
|
|
178
188
|
endDate: secondDate ? Moment(secondDate) : null,
|
|
@@ -230,8 +240,14 @@ export default class CalendarPro extends Component {
|
|
|
230
240
|
};
|
|
231
241
|
|
|
232
242
|
render() {
|
|
233
|
-
const {
|
|
234
|
-
|
|
243
|
+
const {
|
|
244
|
+
startDate,
|
|
245
|
+
endDate,
|
|
246
|
+
showLunar = false,
|
|
247
|
+
tabSelected,
|
|
248
|
+
holidays,
|
|
249
|
+
temp,
|
|
250
|
+
} = this.state;
|
|
235
251
|
const {
|
|
236
252
|
i18n,
|
|
237
253
|
isDoubleDateMode,
|
|
@@ -243,6 +259,7 @@ export default class CalendarPro extends Component {
|
|
|
243
259
|
isOffLunar,
|
|
244
260
|
disabledWeekend,
|
|
245
261
|
isShowLunar,
|
|
262
|
+
containerWidth,
|
|
246
263
|
} = this.props;
|
|
247
264
|
let priceListFormat = priceList?.outbound;
|
|
248
265
|
if (isDoubleDateMode) {
|
|
@@ -252,12 +269,13 @@ export default class CalendarPro extends Component {
|
|
|
252
269
|
const isDisabledWeekend =
|
|
253
270
|
disabledWeekend && !priceList && !isShowLunar && !isDoubleDateMode;
|
|
254
271
|
|
|
272
|
+
const {theme, translate} = this.context;
|
|
273
|
+
|
|
255
274
|
return (
|
|
256
275
|
<View style={styles.container}>
|
|
257
276
|
<View style={styles.viewDate}>
|
|
258
277
|
<HeaderControl
|
|
259
278
|
ref="HeaderControl"
|
|
260
|
-
// selectedDate={this.selectedDate}
|
|
261
279
|
onPressBackArrow={this.onPressBackArrow}
|
|
262
280
|
onPressNextArrow={this.onPressNextArrow}
|
|
263
281
|
/>
|
|
@@ -265,25 +283,22 @@ export default class CalendarPro extends Component {
|
|
|
265
283
|
<View>
|
|
266
284
|
<View style={styles.viewDay}>
|
|
267
285
|
{[1, 2, 3, 4, 5, 6, 7].map(item => (
|
|
268
|
-
<Text
|
|
269
|
-
|
|
286
|
+
<Text
|
|
287
|
+
color={
|
|
288
|
+
item === 6 || item === 7 ? Colors.red_03 : Colors.black_17
|
|
289
|
+
}
|
|
290
|
+
typography={'label_s'}
|
|
270
291
|
style={[
|
|
271
292
|
styles.textDay,
|
|
272
|
-
{
|
|
273
|
-
color:
|
|
274
|
-
item === 6 || item === 7
|
|
275
|
-
? isDisabledWeekend
|
|
276
|
-
? Colors.red_07
|
|
277
|
-
: Colors.red_03
|
|
278
|
-
: Colors.black_17,
|
|
279
|
-
},
|
|
293
|
+
{width: (containerWidth - Spacing.M) / 7},
|
|
280
294
|
]}
|
|
281
295
|
key={item}>
|
|
282
296
|
{Util.mapWeeKDate(item)}
|
|
283
|
-
</Text
|
|
297
|
+
</Text>
|
|
284
298
|
))}
|
|
285
299
|
</View>
|
|
286
300
|
<MonthList
|
|
301
|
+
containerWidth={containerWidth}
|
|
287
302
|
disabledWeekend={isDisabledWeekend}
|
|
288
303
|
ref="MonthList"
|
|
289
304
|
today={this.today}
|
|
@@ -309,22 +324,11 @@ export default class CalendarPro extends Component {
|
|
|
309
324
|
</View>
|
|
310
325
|
{!isOffLunar && (
|
|
311
326
|
<View style={[styles.viewLunar]}>
|
|
312
|
-
<
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
? IconSource.ic_checkbox_checked_24
|
|
318
|
-
: IconSource.ic_checkbox_unchecked_24
|
|
319
|
-
}
|
|
320
|
-
style={styles.iconSelected}
|
|
321
|
-
/>
|
|
322
|
-
</TouchableWithoutFeedback>
|
|
323
|
-
<Text.Description1
|
|
324
|
-
style={styles.txtLunar}
|
|
325
|
-
onPress={this.toggleLunarDate}>
|
|
326
|
-
{SwitchLanguage.showLunar}
|
|
327
|
-
</Text.Description1>
|
|
327
|
+
<CheckBox
|
|
328
|
+
onChange={this.toggleLunarDate}
|
|
329
|
+
value={showLunar}
|
|
330
|
+
label={translate('showLunar')}
|
|
331
|
+
/>
|
|
328
332
|
</View>
|
|
329
333
|
)}
|
|
330
334
|
|
|
@@ -332,28 +336,42 @@ export default class CalendarPro extends Component {
|
|
|
332
336
|
<ScrollView
|
|
333
337
|
contentContainerStyle={styles.contentScroll}
|
|
334
338
|
showsVerticalScrollIndicator={false}
|
|
335
|
-
|
|
339
|
+
nestedScrollEnabled>
|
|
336
340
|
{temp &&
|
|
337
341
|
temp.length > 0 &&
|
|
338
|
-
temp.map(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
342
|
+
temp.map(
|
|
343
|
+
(
|
|
344
|
+
item: {
|
|
345
|
+
mixedLabel: any;
|
|
346
|
+
label: any;
|
|
347
|
+
day: number;
|
|
348
|
+
month: number;
|
|
349
|
+
},
|
|
350
|
+
idx: {toString: () => React.Key | null | undefined},
|
|
351
|
+
) => {
|
|
352
|
+
const labelHoliday = showLunar
|
|
353
|
+
? item.mixedLabel || item.label || ''
|
|
354
|
+
: item.label || '';
|
|
355
|
+
const labelDate = `${
|
|
356
|
+
item.day > 9 ? item.day : `0${item.day}`
|
|
357
|
+
}/${item.month > 9 ? item.month : `0${item.month}`}`;
|
|
358
|
+
return (
|
|
359
|
+
<View style={styles.row} key={idx.toString()}>
|
|
360
|
+
<Text
|
|
361
|
+
color={theme.colors.error.primary}
|
|
362
|
+
typography={'description_s'}
|
|
363
|
+
style={styles.txtMonthLunar}>
|
|
364
|
+
{labelDate}
|
|
365
|
+
</Text>
|
|
366
|
+
<Text
|
|
367
|
+
typography={'description_s'}
|
|
368
|
+
style={styles.subTextLunar}>
|
|
369
|
+
{`${translate(labelHoliday)}`}
|
|
370
|
+
</Text>
|
|
371
|
+
</View>
|
|
372
|
+
);
|
|
373
|
+
},
|
|
374
|
+
)}
|
|
357
375
|
</ScrollView>
|
|
358
376
|
)}
|
|
359
377
|
</View>
|
|
@@ -361,23 +379,6 @@ export default class CalendarPro extends Component {
|
|
|
361
379
|
}
|
|
362
380
|
}
|
|
363
381
|
|
|
364
|
-
CalendarPro.propTypes = {
|
|
365
|
-
i18n: PropTypes.string,
|
|
366
|
-
format: PropTypes.string,
|
|
367
|
-
customI18n: PropTypes.object,
|
|
368
|
-
isShowLunar: PropTypes.bool,
|
|
369
|
-
onCallbackCalendar: PropTypes.func,
|
|
370
|
-
minDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
|
|
371
|
-
maxDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
CalendarPro.defaultProps = {
|
|
375
|
-
format: 'YYYY-MM-DD',
|
|
376
|
-
i18n: 'vi',
|
|
377
|
-
customI18n: {},
|
|
378
|
-
isShowLunar: true,
|
|
379
|
-
};
|
|
380
|
-
|
|
381
382
|
const styles = StyleSheet.create({
|
|
382
383
|
row: {flexDirection: 'row'},
|
|
383
384
|
txtMonthLunar: {
|
|
@@ -412,7 +413,6 @@ const styles = StyleSheet.create({
|
|
|
412
413
|
},
|
|
413
414
|
viewDate: {},
|
|
414
415
|
textDay: {
|
|
415
|
-
width: (widthScreen - 38) / 7,
|
|
416
416
|
textAlign: 'center',
|
|
417
417
|
},
|
|
418
418
|
viewDay: {
|