@momo-kits/calendar 0.121.0-rc.10 → 0.121.0-rc.3
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 +340 -251
- package/Day.tsx +193 -113
- package/LunarDateConverter.ts +0 -14
- package/Month.tsx +93 -96
- package/MonthList.tsx +262 -199
- package/TabHeader.tsx +3 -3
- package/Util.ts +32 -27
- package/index.tsx +383 -266
- package/package.json +1 -1
- package/types.ts +6 -7
package/index.tsx
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useState,
|
|
3
|
-
useRef,
|
|
4
|
-
useEffect,
|
|
5
|
-
useContext,
|
|
6
|
-
createContext,
|
|
7
|
-
} from 'react';
|
|
1
|
+
import React, {Component, createContext, RefObject} from 'react';
|
|
8
2
|
import {Dimensions, LayoutChangeEvent, View} from 'react-native';
|
|
9
3
|
import moment from 'moment';
|
|
10
4
|
import {
|
|
@@ -17,251 +11,308 @@ import {
|
|
|
17
11
|
} from '@momo-kits/foundation';
|
|
18
12
|
import CalendarPro from './CalendarPro';
|
|
19
13
|
import TabHeader from './TabHeader';
|
|
20
|
-
import {CalendarProps,
|
|
14
|
+
import {CalendarProps, CalendarState} from './types';
|
|
21
15
|
import styles from './styles';
|
|
22
16
|
|
|
23
17
|
const DOUBLE = 'doubleDate';
|
|
24
18
|
|
|
25
19
|
export const ContainerContext = createContext({width: 0, height: 0});
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
class Calendar extends Component<CalendarProps, CalendarState> {
|
|
22
|
+
static contextType = ApplicationContext;
|
|
23
|
+
doubleDate: any;
|
|
24
|
+
tabSelected;
|
|
25
|
+
selectedDate: moment.Moment;
|
|
26
|
+
calendarPicker: RefObject<CalendarPro>;
|
|
27
|
+
cellHeader1: RefObject<TabHeader>;
|
|
28
|
+
cellHeader2: RefObject<TabHeader>;
|
|
29
|
+
cellHeaderSingle: RefObject<TabHeader>;
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const maxDateDefault = new Date(currentDate);
|
|
34
|
-
minDateDefault.setFullYear(minDateDefault.getFullYear() - 1);
|
|
35
|
-
maxDateDefault.setFullYear(maxDateDefault.getFullYear() + 1);
|
|
36
|
-
|
|
37
|
-
// destructure all Calendar props
|
|
38
|
-
const {
|
|
39
|
-
mode,
|
|
40
|
-
id,
|
|
41
|
-
doubleDate: initDoubleDate,
|
|
42
|
-
selectedDate: initialSelectedDate,
|
|
43
|
-
onChangeTab: onChangeTabProp,
|
|
44
|
-
onCallbackCalendar,
|
|
45
|
-
isOffLunar,
|
|
46
|
-
isHideHoliday,
|
|
47
|
-
isShowLunar,
|
|
48
|
-
priceList,
|
|
49
|
-
labelFrom,
|
|
50
|
-
labelTo,
|
|
51
|
-
isHideLabel,
|
|
52
|
-
minDate = minDateDefault,
|
|
53
|
-
maxDate = maxDateDefault,
|
|
54
|
-
style,
|
|
55
|
-
disabledDays = [],
|
|
56
|
-
hideHeaderTab = false,
|
|
57
|
-
} = props;
|
|
58
|
-
|
|
59
|
-
const [containerWidth, setContainerWidth] = useState<number>(
|
|
60
|
-
Dimensions.get('window').width
|
|
61
|
-
);
|
|
62
|
-
const [isDoubleDateMode, setIsDoubleDateMode] = useState<boolean>(
|
|
63
|
-
mode === DOUBLE
|
|
64
|
-
);
|
|
65
|
-
const [selectedDate, setSelectedDate] = useState<moment.Moment>(
|
|
66
|
-
initialSelectedDate
|
|
67
|
-
? moment(initialSelectedDate)
|
|
68
|
-
: mode === DOUBLE && initDoubleDate && initDoubleDate.first
|
|
69
|
-
? moment(initDoubleDate.first)
|
|
70
|
-
: moment()
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const doubleDate = useRef<{
|
|
74
|
-
first: moment.Moment | null;
|
|
75
|
-
second: moment.Moment | null;
|
|
76
|
-
}>(
|
|
77
|
-
initDoubleDate
|
|
31
|
+
constructor(props: CalendarProps) {
|
|
32
|
+
super(props);
|
|
33
|
+
this.doubleDate = props.doubleDate
|
|
78
34
|
? {
|
|
79
|
-
first:
|
|
80
|
-
second:
|
|
35
|
+
first: props.doubleDate.first ? moment(props.doubleDate.first) : null,
|
|
36
|
+
second: props.doubleDate.second
|
|
37
|
+
? moment(props.doubleDate.second)
|
|
38
|
+
: null,
|
|
81
39
|
}
|
|
82
|
-
: {
|
|
83
|
-
|
|
84
|
-
|
|
40
|
+
: {};
|
|
41
|
+
this.tabSelected = 0;
|
|
42
|
+
|
|
43
|
+
this.selectedDate = props.selectedDate
|
|
44
|
+
? moment(props.selectedDate)
|
|
45
|
+
: moment();
|
|
46
|
+
|
|
47
|
+
this.state = {
|
|
48
|
+
isDoubleDateMode: props.mode === DOUBLE,
|
|
49
|
+
containerWidth: Dimensions.get('window').width,
|
|
50
|
+
};
|
|
51
|
+
this.calendarPicker = React.createRef<CalendarPro>();
|
|
52
|
+
this.cellHeader1 = React.createRef<TabHeader>();
|
|
53
|
+
this.cellHeader2 = React.createRef<TabHeader>();
|
|
54
|
+
this.cellHeaderSingle = React.createRef<TabHeader>();
|
|
55
|
+
}
|
|
85
56
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
componentDidMount() {
|
|
58
|
+
const {id} = this.props;
|
|
59
|
+
this.tabSelected = id || 0;
|
|
60
|
+
this.viewInit();
|
|
61
|
+
}
|
|
91
62
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
tabSelected.current = id || 0;
|
|
63
|
+
viewInit() {
|
|
64
|
+
const {mode} = this.props;
|
|
95
65
|
if (mode === DOUBLE) {
|
|
96
66
|
if (
|
|
97
|
-
cellHeader1.current &&
|
|
98
|
-
cellHeader2.current &&
|
|
99
|
-
calendarPicker.current
|
|
67
|
+
this.cellHeader1.current &&
|
|
68
|
+
this.cellHeader2.current &&
|
|
69
|
+
this.calendarPicker.current
|
|
100
70
|
) {
|
|
101
|
-
const start = doubleDate.
|
|
102
|
-
const end = doubleDate.
|
|
103
|
-
cellHeader1.current.updateView(start, tabSelected
|
|
104
|
-
cellHeader2.current.updateView(end, tabSelected
|
|
105
|
-
calendarPicker.current.setDoubleDateAndTabIndex(
|
|
106
|
-
doubleDate.
|
|
107
|
-
doubleDate.
|
|
108
|
-
tabSelected
|
|
71
|
+
const start = this.doubleDate.first ? this.doubleDate.first : null;
|
|
72
|
+
const end = this.doubleDate.second ? this.doubleDate.second : null;
|
|
73
|
+
this.cellHeader1.current.updateView(start, this.tabSelected === 0);
|
|
74
|
+
this.cellHeader2.current.updateView(end, this.tabSelected === 1);
|
|
75
|
+
this.calendarPicker.current.setDoubleDateAndTabIndex(
|
|
76
|
+
this.doubleDate.first,
|
|
77
|
+
this.doubleDate.second,
|
|
78
|
+
this.tabSelected
|
|
109
79
|
);
|
|
110
80
|
}
|
|
111
|
-
} else {
|
|
112
|
-
calendarPicker.current
|
|
81
|
+
} else if (this.calendarPicker.current) {
|
|
82
|
+
this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate);
|
|
113
83
|
}
|
|
114
|
-
}
|
|
84
|
+
}
|
|
115
85
|
|
|
116
|
-
|
|
117
|
-
|
|
86
|
+
onChangeTab = (idTab: number) => {
|
|
87
|
+
this.props.onChangeTab?.(idTab);
|
|
88
|
+
this.tabSelected = idTab;
|
|
118
89
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
calendarPicker.current?.setDoubleDateAndTabIndex(
|
|
125
|
-
doubleDate.current.first,
|
|
126
|
-
doubleDate.current.second,
|
|
127
|
-
tabSelected.current
|
|
128
|
-
);
|
|
90
|
+
if (this.cellHeader1.current && this.cellHeader2.current) {
|
|
91
|
+
this.cellHeader1.current.setActiveTab(idTab === 0);
|
|
92
|
+
this.cellHeader2.current.setActiveTab(idTab === 1);
|
|
93
|
+
}
|
|
94
|
+
this.updateViewFlowPicker();
|
|
129
95
|
};
|
|
130
96
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
cellHeader2.current.updateView(null, true);
|
|
141
|
-
// update calendar
|
|
142
|
-
calendarPicker.current.setDoubleDateAndTabIndex(
|
|
143
|
-
doubleDate.current.first,
|
|
144
|
-
doubleDate.current.second,
|
|
145
|
-
tabSelected.current
|
|
146
|
-
);
|
|
147
|
-
// notify parent
|
|
148
|
-
onDateChange?.({ first: doubleDate.current.first!, second: null });
|
|
149
|
-
onCTAStateChange?.(false);
|
|
150
|
-
};
|
|
97
|
+
updateViewFlowPicker() {
|
|
98
|
+
if (this.calendarPicker.current) {
|
|
99
|
+
this.calendarPicker.current.setDoubleDateAndTabIndex(
|
|
100
|
+
this.doubleDate.first,
|
|
101
|
+
this.doubleDate.second,
|
|
102
|
+
this.tabSelected
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
151
106
|
|
|
152
|
-
|
|
153
|
-
const {onDateChange, onCTAStateChange} = props;
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
doubleDate.
|
|
165
|
-
|
|
107
|
+
processDateFirst() {
|
|
108
|
+
const {onDateChange, onCTAStateChange} = this.props;
|
|
109
|
+
if (
|
|
110
|
+
this.cellHeader1.current &&
|
|
111
|
+
this.cellHeader2.current &&
|
|
112
|
+
this.calendarPicker.current
|
|
113
|
+
) {
|
|
114
|
+
if (
|
|
115
|
+
this.doubleDate.first &&
|
|
116
|
+
this.doubleDate.second &&
|
|
117
|
+
this.selectedDate <= this.doubleDate.first
|
|
118
|
+
) {
|
|
119
|
+
this.doubleDate.first = this.selectedDate;
|
|
120
|
+
this.doubleDate.second = null;
|
|
121
|
+
this.tabSelected = 1;
|
|
122
|
+
this.cellHeader1.current.updateView(
|
|
123
|
+
this.selectedDate,
|
|
124
|
+
this.tabSelected === 0
|
|
125
|
+
);
|
|
126
|
+
this.cellHeader2.current.updateView(
|
|
127
|
+
this.doubleDate.second,
|
|
128
|
+
this.tabSelected === 1
|
|
129
|
+
);
|
|
130
|
+
this.cellHeader2.current.setActiveTab(this.tabSelected === 1);
|
|
131
|
+
this.calendarPicker.current.setDoubleDateAndTabIndex(
|
|
132
|
+
this.doubleDate.first,
|
|
133
|
+
this.doubleDate.second,
|
|
134
|
+
this.tabSelected
|
|
135
|
+
);
|
|
136
|
+
if (onDateChange) {
|
|
137
|
+
onDateChange({
|
|
138
|
+
first: this.doubleDate.first
|
|
139
|
+
? this.doubleDate.first.toDate()
|
|
140
|
+
: null,
|
|
141
|
+
second: this.doubleDate.second
|
|
142
|
+
? this.doubleDate.second.toDate()
|
|
143
|
+
: null,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
this.doubleDate.first = this.selectedDate;
|
|
148
|
+
this.doubleDate.second = null;
|
|
149
|
+
this.cellHeader1.current.updateView(this.selectedDate, false);
|
|
150
|
+
this.cellHeader2.current.updateView(null, true);
|
|
151
|
+
this.tabSelected = 1;
|
|
152
|
+
this.calendarPicker.current.setDoubleDateAndTabIndex(
|
|
153
|
+
this.doubleDate.first,
|
|
154
|
+
this.doubleDate.second,
|
|
155
|
+
this.tabSelected
|
|
156
|
+
);
|
|
157
|
+
if (onDateChange) {
|
|
158
|
+
onDateChange({
|
|
159
|
+
first: this.doubleDate.first
|
|
160
|
+
? this.doubleDate.first.toDate()
|
|
161
|
+
: null,
|
|
162
|
+
second: this.doubleDate.second
|
|
163
|
+
? this.doubleDate.second.toDate()
|
|
164
|
+
: null,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (onCTAStateChange) {
|
|
170
|
+
onCTAStateChange(!!this.doubleDate.second);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
processDateSecond() {
|
|
175
|
+
const {onDateChange, onCTAStateChange} = this.props;
|
|
176
|
+
if (
|
|
177
|
+
this.cellHeader2.current &&
|
|
178
|
+
this.selectedDate >= this.doubleDate.first
|
|
179
|
+
) {
|
|
180
|
+
this.doubleDate.second = this.selectedDate;
|
|
181
|
+
this.cellHeader2.current.updateView(this.selectedDate, false);
|
|
182
|
+
this.cellHeader1?.current?.setActiveTab(true);
|
|
183
|
+
this.tabSelected = 0;
|
|
184
|
+
this.calendarPicker?.current?.setDoubleDateAndTabIndex(
|
|
185
|
+
this.doubleDate.first,
|
|
186
|
+
this.doubleDate.second,
|
|
187
|
+
this.tabSelected
|
|
166
188
|
);
|
|
167
|
-
|
|
168
|
-
|
|
189
|
+
if (onCTAStateChange) {
|
|
190
|
+
onCTAStateChange(!!this.doubleDate.second);
|
|
191
|
+
}
|
|
192
|
+
if (onDateChange) {
|
|
193
|
+
onDateChange({
|
|
194
|
+
first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
|
|
195
|
+
second: this.doubleDate.second
|
|
196
|
+
? this.doubleDate.second.toDate()
|
|
197
|
+
: null,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
169
200
|
} else {
|
|
170
|
-
|
|
171
|
-
doubleDate.
|
|
172
|
-
tabSelected.current = 0;
|
|
173
|
-
cellHeader2.current.updateView(selectedDate, false);
|
|
174
|
-
cellHeader1.current.setActiveTab(true);
|
|
175
|
-
calendarPicker.current.setDoubleDateAndTabIndex(
|
|
176
|
-
doubleDate.current.first,
|
|
177
|
-
doubleDate.current.second,
|
|
178
|
-
tabSelected.current
|
|
179
|
-
);
|
|
180
|
-
onDateChange?.({ first: doubleDate.current.first!, second: doubleDate.current.second! });
|
|
181
|
-
onCTAStateChange?.(true);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
201
|
+
this.doubleDate.first = this.selectedDate;
|
|
202
|
+
this.doubleDate.second = null;
|
|
184
203
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
204
|
+
this.cellHeader1?.current?.updateView(this.selectedDate, false);
|
|
205
|
+
this.cellHeader2?.current?.updateView(null, false);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
188
208
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
processDoubleDate();
|
|
209
|
+
processDoubleDate() {
|
|
210
|
+
if (this.tabSelected === 0) {
|
|
211
|
+
this.processDateFirst();
|
|
193
212
|
} else {
|
|
194
|
-
|
|
195
|
-
onDateChange?.(selectedDate.toDate());
|
|
213
|
+
this.processDateSecond();
|
|
196
214
|
}
|
|
197
|
-
}
|
|
215
|
+
}
|
|
198
216
|
|
|
199
|
-
|
|
200
|
-
|
|
217
|
+
updateView() {
|
|
218
|
+
const {onDateChange} = this.props;
|
|
219
|
+
const {isDoubleDateMode} = this.state;
|
|
201
220
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
updateView();
|
|
221
|
+
if (isDoubleDateMode) {
|
|
222
|
+
this.processDoubleDate();
|
|
205
223
|
} else {
|
|
206
|
-
|
|
224
|
+
if (this.cellHeaderSingle.current) {
|
|
225
|
+
this.cellHeaderSingle.current.updateView(this.selectedDate, true);
|
|
226
|
+
}
|
|
227
|
+
if (onDateChange) {
|
|
228
|
+
const date = new Date(this.selectedDate.toDate());
|
|
229
|
+
onDateChange(date);
|
|
230
|
+
}
|
|
207
231
|
}
|
|
208
|
-
}
|
|
232
|
+
}
|
|
209
233
|
|
|
210
|
-
|
|
234
|
+
onDateChange = (date: moment.Moment) => {
|
|
235
|
+
this.selectedDate = date;
|
|
236
|
+
this.updateView();
|
|
237
|
+
};
|
|
211
238
|
|
|
212
|
-
|
|
213
|
-
const {onDateChange, onCTAStateChange} = props;
|
|
239
|
+
updateHeaderView = () => {
|
|
240
|
+
const {onDateChange, onCTAStateChange} = this.props;
|
|
241
|
+
const {isDoubleDateMode} = this.state;
|
|
214
242
|
if (isDoubleDateMode) {
|
|
215
|
-
cellHeader1.current
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
243
|
+
if (this.cellHeader1.current && this.cellHeader2.current) {
|
|
244
|
+
this.cellHeader1.current.updateView(this.selectedDate, true);
|
|
245
|
+
this.cellHeader2.current.updateView(null, false);
|
|
246
|
+
this.calendarPicker.current?.setDoubleDateAndTabIndex(
|
|
247
|
+
this.selectedDate,
|
|
248
|
+
null,
|
|
249
|
+
this.tabSelected
|
|
250
|
+
);
|
|
251
|
+
this.doubleDate.first = moment(this.selectedDate);
|
|
252
|
+
this.doubleDate.second = null;
|
|
253
|
+
|
|
254
|
+
this.tabSelected = 1;
|
|
255
|
+
this.cellHeader2.current?.setActiveTab(true);
|
|
256
|
+
this.cellHeader1.current?.setActiveTab(false);
|
|
257
|
+
this.calendarPicker?.current?.setDoubleDateAndTabIndex(
|
|
258
|
+
this.doubleDate.first,
|
|
259
|
+
this.doubleDate.second,
|
|
260
|
+
this.tabSelected
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
if (onCTAStateChange) {
|
|
264
|
+
onCTAStateChange(false);
|
|
265
|
+
}
|
|
266
|
+
if (onDateChange) {
|
|
267
|
+
onDateChange({
|
|
268
|
+
first: this.doubleDate.first
|
|
269
|
+
? this.doubleDate.first.toDate()
|
|
270
|
+
: null,
|
|
271
|
+
second: this.doubleDate.second
|
|
272
|
+
? this.doubleDate.second.toDate()
|
|
273
|
+
: null,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
234
277
|
} else {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
278
|
+
if (onCTAStateChange) {
|
|
279
|
+
onCTAStateChange(true);
|
|
280
|
+
}
|
|
281
|
+
if (this.cellHeaderSingle.current) {
|
|
282
|
+
if (this.doubleDate.first) {
|
|
283
|
+
this.cellHeaderSingle.current.updateView(this.doubleDate.first, true);
|
|
284
|
+
this.selectedDate = this.doubleDate.first;
|
|
285
|
+
} else {
|
|
286
|
+
this.cellHeaderSingle.current.updateView(this.selectedDate, true);
|
|
287
|
+
}
|
|
288
|
+
if (onDateChange) {
|
|
289
|
+
onDateChange(this.selectedDate.toDate());
|
|
290
|
+
}
|
|
241
291
|
}
|
|
242
|
-
props.onDateChange?.(selectedDate.toDate());
|
|
243
292
|
}
|
|
244
293
|
};
|
|
245
294
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
295
|
+
toggleSelectionDateMode = () => {
|
|
296
|
+
const {onCallbackCalendar} = this.props;
|
|
297
|
+
this.setState(
|
|
298
|
+
preState => ({isDoubleDateMode: !preState.isDoubleDateMode}),
|
|
299
|
+
() => {
|
|
300
|
+
const {isDoubleDateMode} = this.state;
|
|
301
|
+
this.updateHeaderView();
|
|
302
|
+
if (onCallbackCalendar && typeof onCallbackCalendar === 'function') {
|
|
303
|
+
onCallbackCalendar('switch', isDoubleDateMode);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
);
|
|
252
307
|
};
|
|
253
308
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
309
|
+
renderSwitchReturnSelection = () => {
|
|
310
|
+
const {isDoubleDateMode} = this.state;
|
|
311
|
+
const {translate, theme} = this.context;
|
|
312
|
+
const { hideSwitchReturnSelection } = this.props;
|
|
313
|
+
if(hideSwitchReturnSelection){
|
|
314
|
+
return null
|
|
260
315
|
}
|
|
261
|
-
}, [isDoubleDateMode]);
|
|
262
|
-
|
|
263
|
-
const renderSwitchReturnSelection = () => {
|
|
264
|
-
if (props.hideSwitchReturnSelection) return null;
|
|
265
316
|
return (
|
|
266
317
|
<View style={styles.headerContainer}>
|
|
267
318
|
<View
|
|
@@ -269,17 +320,22 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
269
320
|
styles.viewSwitch,
|
|
270
321
|
{backgroundColor: theme.colors.background.surface},
|
|
271
322
|
]}>
|
|
272
|
-
<Text typography=
|
|
273
|
-
{props
|
|
323
|
+
<Text typography={'label_default_medium'}>
|
|
324
|
+
{this.props?.titleHeader || translate('chooseRoundtrip')}
|
|
274
325
|
</Text>
|
|
275
|
-
<Switch
|
|
326
|
+
<Switch
|
|
327
|
+
value={isDoubleDateMode}
|
|
328
|
+
onChange={this.toggleSelectionDateMode}
|
|
329
|
+
/>
|
|
276
330
|
</View>
|
|
277
331
|
</View>
|
|
278
332
|
);
|
|
279
333
|
};
|
|
280
334
|
|
|
281
|
-
|
|
282
|
-
isDoubleDateMode
|
|
335
|
+
renderHeaderPanel = (theme: {colors: {background: {default: string}}}) => {
|
|
336
|
+
const {isDoubleDateMode} = this.state;
|
|
337
|
+
const {headerFrom, headerTo} = this.props;
|
|
338
|
+
return isDoubleDateMode ? (
|
|
283
339
|
<View
|
|
284
340
|
style={[
|
|
285
341
|
styles.viewPanel,
|
|
@@ -287,20 +343,20 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
287
343
|
]}>
|
|
288
344
|
<TabHeader
|
|
289
345
|
id={0}
|
|
290
|
-
ref={cellHeader1}
|
|
291
|
-
onChangeTab={onChangeTab}
|
|
292
|
-
label={
|
|
346
|
+
ref={this.cellHeader1}
|
|
347
|
+
onChangeTab={this.onChangeTab}
|
|
348
|
+
label={headerFrom || 'depart'}
|
|
293
349
|
activeTab
|
|
294
|
-
date={doubleDate.
|
|
350
|
+
date={this.doubleDate.first}
|
|
295
351
|
/>
|
|
296
352
|
<View style={{width: 4, height: '100%'}} />
|
|
297
353
|
<TabHeader
|
|
298
354
|
id={1}
|
|
299
|
-
ref={cellHeader2}
|
|
300
|
-
onChangeTab={onChangeTab}
|
|
301
|
-
label={
|
|
355
|
+
ref={this.cellHeader2}
|
|
356
|
+
onChangeTab={this.onChangeTab}
|
|
357
|
+
label={headerTo || 'return'}
|
|
302
358
|
activeTab={false}
|
|
303
|
-
date=
|
|
359
|
+
date=""
|
|
304
360
|
/>
|
|
305
361
|
</View>
|
|
306
362
|
) : (
|
|
@@ -312,55 +368,116 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
312
368
|
<TabHeader
|
|
313
369
|
id={0}
|
|
314
370
|
disabled
|
|
315
|
-
ref={cellHeaderSingle}
|
|
316
|
-
label={
|
|
371
|
+
ref={this.cellHeaderSingle}
|
|
372
|
+
label={headerFrom || 'depart'}
|
|
317
373
|
activeTab
|
|
318
|
-
date={selectedDate}
|
|
374
|
+
date={this.selectedDate}
|
|
319
375
|
/>
|
|
320
376
|
</View>
|
|
321
377
|
);
|
|
378
|
+
};
|
|
322
379
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
380
|
+
setDateRange = (
|
|
381
|
+
dateRange: {
|
|
382
|
+
startDate: moment.Moment | undefined;
|
|
383
|
+
endDate: moment.Moment | undefined;
|
|
384
|
+
},
|
|
385
|
+
isScrollToStartDate: any
|
|
386
|
+
) => {
|
|
387
|
+
const {mode, doubleDate = {}} = this.props;
|
|
388
|
+
if (mode === 'doubleDate') {
|
|
389
|
+
this.cellHeader1?.current?.updateView(
|
|
390
|
+
dateRange.startDate,
|
|
391
|
+
this.tabSelected === 0
|
|
392
|
+
);
|
|
393
|
+
this.cellHeader2?.current?.updateView(
|
|
394
|
+
dateRange.endDate,
|
|
395
|
+
this.tabSelected === 1
|
|
396
|
+
);
|
|
397
|
+
this.calendarPicker?.current?.setDateRange(
|
|
398
|
+
dateRange,
|
|
399
|
+
isScrollToStartDate
|
|
400
|
+
);
|
|
401
|
+
this.doubleDate = doubleDate
|
|
402
|
+
? {
|
|
403
|
+
first: dateRange.startDate ? moment(dateRange.startDate) : null,
|
|
404
|
+
second: dateRange.endDate ? moment(dateRange.endDate) : null,
|
|
405
|
+
}
|
|
406
|
+
: {};
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
onLayout = (e: LayoutChangeEvent) => {
|
|
411
|
+
this.setState({containerWidth: e.nativeEvent.layout.width});
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
render() {
|
|
415
|
+
const currentDate = new Date();
|
|
416
|
+
const minDateDefault = new Date(currentDate);
|
|
417
|
+
const maxDateDefault = new Date(currentDate);
|
|
418
|
+
minDateDefault.setFullYear(minDateDefault.getFullYear() - 1);
|
|
419
|
+
maxDateDefault.setFullYear(maxDateDefault.getFullYear() + 1);
|
|
420
|
+
|
|
421
|
+
const {
|
|
422
|
+
isOffLunar,
|
|
423
|
+
isHideHoliday,
|
|
424
|
+
isShowLunar,
|
|
425
|
+
onCallbackCalendar,
|
|
426
|
+
priceList,
|
|
427
|
+
labelFrom,
|
|
428
|
+
labelTo,
|
|
429
|
+
isHideLabel,
|
|
430
|
+
minDate = minDateDefault,
|
|
431
|
+
maxDate = maxDateDefault,
|
|
432
|
+
doubleDate,
|
|
433
|
+
style,
|
|
434
|
+
disabledDays = [],
|
|
435
|
+
hideHeaderTab = false,
|
|
436
|
+
} = this.props;
|
|
437
|
+
const {isDoubleDateMode, containerWidth} = this.state;
|
|
438
|
+
const {theme} = this.context;
|
|
439
|
+
return (
|
|
440
|
+
<ContainerContext.Provider
|
|
441
|
+
value={{
|
|
442
|
+
width: containerWidth,
|
|
443
|
+
height: priceList ? scaleSize(48) : scaleSize(34),
|
|
444
|
+
}}>
|
|
445
|
+
<View onLayout={this.onLayout} style={[style, styles.scrollView]}>
|
|
446
|
+
<View
|
|
447
|
+
style={[
|
|
448
|
+
{
|
|
449
|
+
backgroundColor: theme.colors.background.surface,
|
|
450
|
+
borderRadius: Radius.XS,
|
|
451
|
+
marginBottom: Spacing.S,
|
|
452
|
+
},
|
|
453
|
+
hideHeaderTab && styles.invisible,
|
|
454
|
+
]}>
|
|
455
|
+
{this.renderSwitchReturnSelection()}
|
|
456
|
+
{this.renderHeaderPanel(theme)}
|
|
457
|
+
</View>
|
|
458
|
+
<CalendarPro
|
|
459
|
+
priceList={priceList}
|
|
460
|
+
ref={this.calendarPicker}
|
|
461
|
+
startDate={doubleDate?.first}
|
|
462
|
+
endDate={doubleDate?.second}
|
|
463
|
+
onDateChange={this.onDateChange}
|
|
464
|
+
isDoubleDateMode={isDoubleDateMode}
|
|
465
|
+
selectedDate={this.selectedDate}
|
|
466
|
+
isShowLunar={isShowLunar}
|
|
467
|
+
onCallbackCalendar={onCallbackCalendar}
|
|
468
|
+
labelFrom={labelFrom}
|
|
469
|
+
labelTo={labelTo}
|
|
470
|
+
isHideLabel={isHideLabel}
|
|
471
|
+
minDate={minDate}
|
|
472
|
+
maxDate={maxDate}
|
|
473
|
+
isHideHoliday={isHideHoliday}
|
|
474
|
+
isOffLunar={isOffLunar}
|
|
475
|
+
disabledDays={disabledDays}
|
|
476
|
+
/>
|
|
341
477
|
</View>
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
endDate={doubleDate.current.second!}
|
|
347
|
-
onDateChange={onDateChangeHandler}
|
|
348
|
-
isDoubleDateMode={isDoubleDateMode}
|
|
349
|
-
selectedDate={selectedDate}
|
|
350
|
-
isShowLunar={isShowLunar}
|
|
351
|
-
onCallbackCalendar={onCallbackCalendar}
|
|
352
|
-
labelFrom={labelFrom}
|
|
353
|
-
labelTo={labelTo}
|
|
354
|
-
isHideLabel={isHideLabel}
|
|
355
|
-
minDate={minDate}
|
|
356
|
-
maxDate={maxDate}
|
|
357
|
-
isHideHoliday={isHideHoliday}
|
|
358
|
-
isOffLunar={isOffLunar}
|
|
359
|
-
disabledDays={disabledDays}
|
|
360
|
-
/>
|
|
361
|
-
</View>
|
|
362
|
-
</ContainerContext.Provider>
|
|
363
|
-
);
|
|
364
|
-
};
|
|
478
|
+
</ContainerContext.Provider>
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
365
482
|
|
|
366
483
|
export {Calendar};
|