@momo-kits/calendar 0.79.6 → 0.80.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 +386 -0
- package/Day.tsx +242 -0
- package/HeaderControl.tsx +53 -0
- package/Month.tsx +114 -0
- package/{src/MonthList.tsx → MonthList.tsx} +96 -65
- package/{src/TabHeader.tsx → TabHeader.tsx} +30 -12
- package/index.tsx +481 -2
- package/package.json +1 -1
- package/styles.ts +115 -0
- package/types.ts +155 -27
- package/src/Calendar.tsx +0 -488
- package/src/CalendarPro.tsx +0 -436
- package/src/Day/index.tsx +0 -248
- package/src/Day/style.ts +0 -113
- package/src/HeaderControl.tsx +0 -69
- package/src/Month/index.tsx +0 -88
- package/src/Month/style.ts +0 -0
- /package/{src/LunarDateConverter.ts → LunarDateConverter.ts} +0 -0
- /package/{src/LunarService.ts → LunarService.ts} +0 -0
- /package/{src/Util.ts → Util.ts} +0 -0
- /package/{src/holidayData.ts → holidayData.ts} +0 -0
package/src/CalendarPro.tsx
DELETED
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
import React, {Component} from 'react';
|
|
2
|
-
|
|
3
|
-
import {Dimensions, ScrollView, StyleSheet, View} from 'react-native';
|
|
4
|
-
import Moment from 'moment';
|
|
5
|
-
import {
|
|
6
|
-
ApplicationContext,
|
|
7
|
-
CheckBox,
|
|
8
|
-
Colors,
|
|
9
|
-
Radius,
|
|
10
|
-
Spacing,
|
|
11
|
-
Text,
|
|
12
|
-
} from '@momo-kits/foundation';
|
|
13
|
-
import MonthList from './MonthList';
|
|
14
|
-
import HeaderControl from './HeaderControl';
|
|
15
|
-
import LunarDateConverter from './LunarDateConverter';
|
|
16
|
-
import Util from './Util';
|
|
17
|
-
import {CalendarProProps, CalendarProState} from '../types';
|
|
18
|
-
|
|
19
|
-
const widthScreen = Dimensions.get('window').width;
|
|
20
|
-
|
|
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) {
|
|
35
|
-
super(props);
|
|
36
|
-
this.today = Moment();
|
|
37
|
-
this.year = this.today.year();
|
|
38
|
-
this.getDateRange();
|
|
39
|
-
this.header = this.today.clone();
|
|
40
|
-
this.selectedDate = props.selectedDate;
|
|
41
|
-
this.state = {
|
|
42
|
-
startDate: props.startDate,
|
|
43
|
-
endDate: props.endDate,
|
|
44
|
-
showLunar: props.isShowLunar,
|
|
45
|
-
tabSelected: 0,
|
|
46
|
-
holidays: [],
|
|
47
|
-
ownUpdate: false,
|
|
48
|
-
};
|
|
49
|
-
this.converter = new LunarDateConverter();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static getDerivedStateFromProps(
|
|
53
|
-
nextProps: {isShowLunar: any},
|
|
54
|
-
prevState: {ownUpdate: any; showLunar: any},
|
|
55
|
-
) {
|
|
56
|
-
if (prevState.ownUpdate) {
|
|
57
|
-
return {
|
|
58
|
-
ownUpdate: false,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (nextProps.isShowLunar !== prevState.showLunar) {
|
|
62
|
-
return {showLunar: nextProps.isShowLunar};
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setDateRange = (
|
|
68
|
-
dateRange: {startDate: any; endDate: any},
|
|
69
|
-
isScrollToStartDate: any,
|
|
70
|
-
) => {
|
|
71
|
-
if (dateRange && dateRange.startDate && dateRange.endDate) {
|
|
72
|
-
this.setState(
|
|
73
|
-
{
|
|
74
|
-
startDate: dateRange.startDate,
|
|
75
|
-
endDate: dateRange.endDate,
|
|
76
|
-
},
|
|
77
|
-
() => {
|
|
78
|
-
const dateScroll = isScrollToStartDate
|
|
79
|
-
? dateRange.startDate
|
|
80
|
-
: dateRange.endDate;
|
|
81
|
-
this.refs.MonthList.scrollToMonth(dateScroll);
|
|
82
|
-
},
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
ownSetState(state: CalendarProState) {
|
|
88
|
-
this.setState({
|
|
89
|
-
...state,
|
|
90
|
-
ownUpdate: true,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
getDateRange = () => {
|
|
95
|
-
const {maxDate, minDate, format} = this.props;
|
|
96
|
-
let max = Moment(maxDate, format);
|
|
97
|
-
let min = Moment(minDate, format);
|
|
98
|
-
const maxValid = max.isValid();
|
|
99
|
-
const minValid = min.isValid();
|
|
100
|
-
if (!maxValid && !minValid) {
|
|
101
|
-
max = Moment().add(12, 'months');
|
|
102
|
-
min = Moment();
|
|
103
|
-
}
|
|
104
|
-
if (!maxValid && minValid) {
|
|
105
|
-
max = min.add(12, 'months');
|
|
106
|
-
}
|
|
107
|
-
if (maxValid && !minValid) {
|
|
108
|
-
min = max.subtract(12, 'months');
|
|
109
|
-
}
|
|
110
|
-
if (min.isSameOrAfter(max)) return {};
|
|
111
|
-
this.minDate = min;
|
|
112
|
-
this.maxDate = max;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
onChoose = (day: number) => {
|
|
116
|
-
const {startDate, tabSelected} = this.state;
|
|
117
|
-
const {isDoubleDateMode, onDateChange} = this.props;
|
|
118
|
-
if (isDoubleDateMode) {
|
|
119
|
-
if (tabSelected === 1) {
|
|
120
|
-
if (startDate && day >= startDate) {
|
|
121
|
-
this.ownSetState({
|
|
122
|
-
endDate: day,
|
|
123
|
-
});
|
|
124
|
-
} else if (startDate && day < startDate) {
|
|
125
|
-
this.ownSetState({
|
|
126
|
-
startDate: day,
|
|
127
|
-
endDate: null,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
this.ownSetState({
|
|
132
|
-
startDate: day,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
this.ownSetState({
|
|
137
|
-
startDate: day,
|
|
138
|
-
endDate: null,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
if (onDateChange) {
|
|
142
|
-
onDateChange(day);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
executeProcessAfterScrollCalendar = (
|
|
147
|
-
date: Moment.MomentInput | undefined,
|
|
148
|
-
key: any,
|
|
149
|
-
) => {
|
|
150
|
-
const holidays = Object.values(Util.getHolidaysInMonth(Moment(date)));
|
|
151
|
-
const {showLunar} = this.state;
|
|
152
|
-
if (this.refs && this.refs.HeaderControl) {
|
|
153
|
-
this.refs.HeaderControl.onUpdateInfo({date});
|
|
154
|
-
this.header = date.clone().startOf('month');
|
|
155
|
-
}
|
|
156
|
-
let data = [];
|
|
157
|
-
if (!showLunar) {
|
|
158
|
-
data = holidays.filter(item => !item.lunar || item.mixedLabel);
|
|
159
|
-
} else {
|
|
160
|
-
data = holidays;
|
|
161
|
-
}
|
|
162
|
-
this.ownSetState({
|
|
163
|
-
holidays,
|
|
164
|
-
temp: data,
|
|
165
|
-
headerKey: key,
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
onScrollCalendar = (data: {
|
|
170
|
-
key: any;
|
|
171
|
-
date: Moment.MomentInput | undefined;
|
|
172
|
-
}) => {
|
|
173
|
-
const {headerKey} = this.state;
|
|
174
|
-
if (data) {
|
|
175
|
-
if (data.key !== headerKey) {
|
|
176
|
-
this.executeProcessAfterScrollCalendar(data.date, data.key);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
setDoubleDateAndTabIndex = (
|
|
182
|
-
firstDate: Moment.MomentInput | undefined,
|
|
183
|
-
secondDate: Moment.MomentInput | undefined,
|
|
184
|
-
tabSelected: any,
|
|
185
|
-
) => {
|
|
186
|
-
this.ownSetState({
|
|
187
|
-
startDate: firstDate ? Moment(firstDate) : null,
|
|
188
|
-
endDate: secondDate ? Moment(secondDate) : null,
|
|
189
|
-
tabSelected,
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
toggleLunarDate = () => {
|
|
194
|
-
const {showLunar, holidays} = this.state;
|
|
195
|
-
const {onCallbackCalendar} = this.props;
|
|
196
|
-
let data = [];
|
|
197
|
-
const nextStateShowLunar = !showLunar;
|
|
198
|
-
if (!nextStateShowLunar) {
|
|
199
|
-
data = holidays.filter(item => !item.lunar || item.mixedLabel);
|
|
200
|
-
} else {
|
|
201
|
-
data = holidays;
|
|
202
|
-
}
|
|
203
|
-
if (onCallbackCalendar) {
|
|
204
|
-
onCallbackCalendar('lunar', nextStateShowLunar);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
this.ownSetState({
|
|
208
|
-
showLunar: !showLunar,
|
|
209
|
-
temp: data,
|
|
210
|
-
ownUpdate: true,
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
onPressBackArrow = () => {
|
|
215
|
-
const previousDate = Moment(this.header)
|
|
216
|
-
.startOf('month')
|
|
217
|
-
.subtract(1, 'months');
|
|
218
|
-
if (
|
|
219
|
-
this.refs &&
|
|
220
|
-
this.refs.HeaderControl &&
|
|
221
|
-
previousDate.isSameOrAfter(this.minDate, 'month')
|
|
222
|
-
) {
|
|
223
|
-
this.header = previousDate;
|
|
224
|
-
this.refs.HeaderControl.onUpdateInfo({date: previousDate});
|
|
225
|
-
this.refs.MonthList.scrollToMonth(previousDate);
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
onPressNextArrow = () => {
|
|
230
|
-
const nextDate = Moment(this.header).startOf('month').add(1, 'months');
|
|
231
|
-
if (
|
|
232
|
-
this.refs &&
|
|
233
|
-
this.refs.HeaderControl &&
|
|
234
|
-
nextDate.isSameOrBefore(this.maxDate, 'month')
|
|
235
|
-
) {
|
|
236
|
-
this.header = nextDate;
|
|
237
|
-
this.refs.HeaderControl.onUpdateInfo({date: nextDate});
|
|
238
|
-
this.refs.MonthList.scrollToMonth(nextDate);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
render() {
|
|
243
|
-
const {
|
|
244
|
-
startDate,
|
|
245
|
-
endDate,
|
|
246
|
-
showLunar = false,
|
|
247
|
-
tabSelected,
|
|
248
|
-
holidays,
|
|
249
|
-
temp,
|
|
250
|
-
} = this.state;
|
|
251
|
-
const {
|
|
252
|
-
i18n,
|
|
253
|
-
isDoubleDateMode,
|
|
254
|
-
priceList,
|
|
255
|
-
labelFrom,
|
|
256
|
-
labelTo,
|
|
257
|
-
isHideLabel,
|
|
258
|
-
isHideHoliday,
|
|
259
|
-
isOffLunar,
|
|
260
|
-
disabledWeekend,
|
|
261
|
-
isShowLunar,
|
|
262
|
-
containerWidth,
|
|
263
|
-
} = this.props;
|
|
264
|
-
let priceListFormat = priceList?.outbound;
|
|
265
|
-
if (isDoubleDateMode) {
|
|
266
|
-
priceListFormat =
|
|
267
|
-
tabSelected === 0 ? priceList?.outbound : priceList?.inbound;
|
|
268
|
-
}
|
|
269
|
-
const isDisabledWeekend =
|
|
270
|
-
disabledWeekend && !priceList && !isShowLunar && !isDoubleDateMode;
|
|
271
|
-
|
|
272
|
-
const {theme, translate} = this.context;
|
|
273
|
-
|
|
274
|
-
return (
|
|
275
|
-
<View style={styles.container}>
|
|
276
|
-
<View style={styles.viewDate}>
|
|
277
|
-
<HeaderControl
|
|
278
|
-
ref="HeaderControl"
|
|
279
|
-
onPressBackArrow={this.onPressBackArrow}
|
|
280
|
-
onPressNextArrow={this.onPressNextArrow}
|
|
281
|
-
/>
|
|
282
|
-
<View style={styles.blueSeperator} />
|
|
283
|
-
<View>
|
|
284
|
-
<View style={styles.viewDay}>
|
|
285
|
-
{[1, 2, 3, 4, 5, 6, 7].map(item => (
|
|
286
|
-
<Text
|
|
287
|
-
color={
|
|
288
|
-
item === 6 || item === 7 ? Colors.red_03 : Colors.black_17
|
|
289
|
-
}
|
|
290
|
-
typography={'label_s'}
|
|
291
|
-
style={[
|
|
292
|
-
styles.textDay,
|
|
293
|
-
{width: (containerWidth - Spacing.M) / 7},
|
|
294
|
-
]}
|
|
295
|
-
key={item}>
|
|
296
|
-
{Util.mapWeeKDate(item)}
|
|
297
|
-
</Text>
|
|
298
|
-
))}
|
|
299
|
-
</View>
|
|
300
|
-
<MonthList
|
|
301
|
-
containerWidth={containerWidth}
|
|
302
|
-
disabledWeekend={isDisabledWeekend}
|
|
303
|
-
ref="MonthList"
|
|
304
|
-
today={this.today}
|
|
305
|
-
minDate={this.minDate}
|
|
306
|
-
maxDate={this.maxDate}
|
|
307
|
-
startDate={startDate}
|
|
308
|
-
endDate={endDate}
|
|
309
|
-
onChoose={this.onChoose}
|
|
310
|
-
i18n={i18n}
|
|
311
|
-
onScrollCalendar={this.onScrollCalendar}
|
|
312
|
-
isShowLunar={!isOffLunar && showLunar}
|
|
313
|
-
isDoubleDateMode={isDoubleDateMode}
|
|
314
|
-
tabSelected={tabSelected}
|
|
315
|
-
lunarConverter={this.converter}
|
|
316
|
-
holidays={holidays}
|
|
317
|
-
selectedDate={this.selectedDate}
|
|
318
|
-
priceList={priceListFormat}
|
|
319
|
-
labelFrom={labelFrom}
|
|
320
|
-
labelTo={labelTo}
|
|
321
|
-
isHideLabel={isHideLabel}
|
|
322
|
-
/>
|
|
323
|
-
</View>
|
|
324
|
-
</View>
|
|
325
|
-
{!isOffLunar && (
|
|
326
|
-
<View style={[styles.viewLunar]}>
|
|
327
|
-
<CheckBox
|
|
328
|
-
onChange={this.toggleLunarDate}
|
|
329
|
-
value={showLunar}
|
|
330
|
-
label={translate('showLunar')}
|
|
331
|
-
/>
|
|
332
|
-
</View>
|
|
333
|
-
)}
|
|
334
|
-
|
|
335
|
-
{!isHideHoliday && (
|
|
336
|
-
<ScrollView
|
|
337
|
-
contentContainerStyle={styles.contentScroll}
|
|
338
|
-
showsVerticalScrollIndicator={false}
|
|
339
|
-
nestedScrollEnabled>
|
|
340
|
-
{temp &&
|
|
341
|
-
temp.length > 0 &&
|
|
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
|
-
)}
|
|
375
|
-
</ScrollView>
|
|
376
|
-
)}
|
|
377
|
-
</View>
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const styles = StyleSheet.create({
|
|
383
|
-
row: {flexDirection: 'row'},
|
|
384
|
-
txtMonthLunar: {
|
|
385
|
-
color: Colors.red_03,
|
|
386
|
-
marginRight: Spacing.S,
|
|
387
|
-
},
|
|
388
|
-
subTextLunar: {
|
|
389
|
-
color: Colors.black_17,
|
|
390
|
-
},
|
|
391
|
-
contentScroll: {
|
|
392
|
-
paddingHorizontal: 12,
|
|
393
|
-
paddingVertical: 10,
|
|
394
|
-
},
|
|
395
|
-
iconSelected: {
|
|
396
|
-
width: 24,
|
|
397
|
-
height: 24,
|
|
398
|
-
resizeMode: 'cover',
|
|
399
|
-
},
|
|
400
|
-
txtLunar: {
|
|
401
|
-
paddingLeft: 6,
|
|
402
|
-
color: '#222222',
|
|
403
|
-
fontSize: 14,
|
|
404
|
-
},
|
|
405
|
-
viewLunar: {
|
|
406
|
-
flexDirection: 'row',
|
|
407
|
-
alignItems: 'center',
|
|
408
|
-
marginHorizontal: Spacing.M,
|
|
409
|
-
borderTopWidth: 1,
|
|
410
|
-
paddingTop: Spacing.M,
|
|
411
|
-
borderStyle: 'solid',
|
|
412
|
-
borderColor: Colors.black_04,
|
|
413
|
-
},
|
|
414
|
-
viewDate: {},
|
|
415
|
-
textDay: {
|
|
416
|
-
textAlign: 'center',
|
|
417
|
-
},
|
|
418
|
-
viewDay: {
|
|
419
|
-
flexDirection: 'row',
|
|
420
|
-
justifyContent: 'space-between',
|
|
421
|
-
paddingHorizontal: Spacing.S,
|
|
422
|
-
paddingTop: 15,
|
|
423
|
-
paddingBottom: 10,
|
|
424
|
-
},
|
|
425
|
-
container: {
|
|
426
|
-
flex: 1,
|
|
427
|
-
backgroundColor: 'white',
|
|
428
|
-
marginTop: Spacing.S,
|
|
429
|
-
borderRadius: Radius.XS,
|
|
430
|
-
},
|
|
431
|
-
blueSeperator: {
|
|
432
|
-
height: 1,
|
|
433
|
-
width: '100%',
|
|
434
|
-
backgroundColor: Colors.blue_05,
|
|
435
|
-
},
|
|
436
|
-
});
|
package/src/Day/index.tsx
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import React, {Component} from 'react';
|
|
2
|
-
|
|
3
|
-
import {TouchableHighlight, View} from 'react-native';
|
|
4
|
-
import {ApplicationContext, Colors, Spacing, Text} from '@momo-kits/foundation';
|
|
5
|
-
import style from './style';
|
|
6
|
-
|
|
7
|
-
class Day extends Component {
|
|
8
|
-
static contextType = ApplicationContext;
|
|
9
|
-
constructor(props) {
|
|
10
|
-
super(props);
|
|
11
|
-
this.statusCheck();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
chooseDay = () => {
|
|
15
|
-
const {onChoose, date} = this.props;
|
|
16
|
-
onChoose && onChoose(date);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
findHoliday = (date, holidays) => {
|
|
20
|
-
if (date && holidays && holidays.length > 0) {
|
|
21
|
-
const day = date.date();
|
|
22
|
-
const month = date.month() + 1;
|
|
23
|
-
return holidays.find(item => item.day === day && item.month === month);
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
checkHoliday = (date, holidays) => {
|
|
29
|
-
const holiday = this.findHoliday(date, holidays);
|
|
30
|
-
return {
|
|
31
|
-
solarHoliday: !!(holiday && !holiday.lunar),
|
|
32
|
-
lunarHoliday: !!(holiday && holiday.lunar),
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
statusCheck = props => {
|
|
37
|
-
const {
|
|
38
|
-
startDate,
|
|
39
|
-
endDate,
|
|
40
|
-
date = null,
|
|
41
|
-
minDate,
|
|
42
|
-
maxDate,
|
|
43
|
-
empty,
|
|
44
|
-
index,
|
|
45
|
-
isShowLunar,
|
|
46
|
-
isDoubleDateMode,
|
|
47
|
-
lunarDate,
|
|
48
|
-
isSolarHoliday,
|
|
49
|
-
isLunarHoliday,
|
|
50
|
-
} = props || this.props;
|
|
51
|
-
this.isValid =
|
|
52
|
-
date &&
|
|
53
|
-
(date >= minDate || date.isSame(minDate, 'day')) &&
|
|
54
|
-
(date <= maxDate || date.isSame(maxDate, 'day'));
|
|
55
|
-
this.isMid =
|
|
56
|
-
(isDoubleDateMode && date > startDate && date < endDate) ||
|
|
57
|
-
(!date && empty >= startDate && empty <= endDate);
|
|
58
|
-
this.isStart = date && date.isSame(startDate, 'd');
|
|
59
|
-
this.isStartPart = this.isStart && endDate;
|
|
60
|
-
this.isEnd = isDoubleDateMode && date && date.isSame(endDate, 'day');
|
|
61
|
-
this.isFocus = this.isMid || this.isStart || this.isEnd;
|
|
62
|
-
this.isWeekEnd = index === 6 || index === 5;
|
|
63
|
-
this.showLunar = isShowLunar;
|
|
64
|
-
this.lunarDate = lunarDate;
|
|
65
|
-
this.isDoubleDateMode = isDoubleDateMode;
|
|
66
|
-
this.isLunarHoliday = isLunarHoliday;
|
|
67
|
-
this.isLunarDayStart = this.lunarDate && this.lunarDate.lunarDay === 1;
|
|
68
|
-
this.isSolarHoliday = isSolarHoliday;
|
|
69
|
-
this.isInScope = true;
|
|
70
|
-
return this.isFocus || this.diffPrice;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
shouldComponentUpdate(nextProps) {
|
|
74
|
-
const {
|
|
75
|
-
isDoubleDateMode,
|
|
76
|
-
isShowLunar,
|
|
77
|
-
tabSelected,
|
|
78
|
-
isSolarHoliday,
|
|
79
|
-
isLunarHoliday,
|
|
80
|
-
price,
|
|
81
|
-
isBestPrice,
|
|
82
|
-
startDate,
|
|
83
|
-
endDate,
|
|
84
|
-
} = this.props;
|
|
85
|
-
const prevStatus = this.isFocus;
|
|
86
|
-
const selectionModeChange = isDoubleDateMode !== nextProps.isDoubleDateMode;
|
|
87
|
-
const lunarChange = isShowLunar !== nextProps.isShowLunar;
|
|
88
|
-
const nextStatus = this.statusCheck(nextProps);
|
|
89
|
-
const tabChange = tabSelected !== nextProps.tabSelected;
|
|
90
|
-
const solarHoliday = isSolarHoliday !== nextProps.isSolarHoliday;
|
|
91
|
-
const lunarHoliday = isLunarHoliday !== nextProps.isLunarHoliday;
|
|
92
|
-
const diffPrice =
|
|
93
|
-
price !== nextProps.price && isBestPrice !== nextProps.isBestPrice;
|
|
94
|
-
const startDateChange =
|
|
95
|
-
startDate && !startDate?.isSame?.(nextProps.startDate, 'day');
|
|
96
|
-
const endDateChange =
|
|
97
|
-
endDate && !endDate?.isSame?.(nextProps.endDate, 'day');
|
|
98
|
-
return !!(
|
|
99
|
-
prevStatus !== nextStatus ||
|
|
100
|
-
selectionModeChange ||
|
|
101
|
-
lunarChange ||
|
|
102
|
-
tabChange ||
|
|
103
|
-
solarHoliday ||
|
|
104
|
-
lunarHoliday ||
|
|
105
|
-
diffPrice ||
|
|
106
|
-
startDateChange ||
|
|
107
|
-
endDateChange
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
render() {
|
|
112
|
-
const {date, empty, price, isBestPrice, disabledWeekend, width} =
|
|
113
|
-
this.props;
|
|
114
|
-
const {theme, translate} = this.context;
|
|
115
|
-
|
|
116
|
-
const text = date ? date.date() : '';
|
|
117
|
-
let textDayColor = theme.colors.text.default;
|
|
118
|
-
let lunarDayColor = theme.colors.text.hint;
|
|
119
|
-
|
|
120
|
-
if (this.isWeekEnd || this.isSolarHoliday || this.isWeekEnd) {
|
|
121
|
-
textDayColor = theme.colors.error.primary;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (this.isStart || this.isEnd) {
|
|
125
|
-
textDayColor = Colors.black_01;
|
|
126
|
-
lunarDayColor = Colors.black_01;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (this.isLunarHoliday || this.isLunarDayStart) {
|
|
130
|
-
lunarDayColor = theme.colors.error.primary;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<View style={[style.dayContainer, {width, borderWidth: 1}]}>
|
|
135
|
-
<View
|
|
136
|
-
style={[
|
|
137
|
-
this.isMid &&
|
|
138
|
-
!empty && {backgroundColor: theme.colors.background.tonal},
|
|
139
|
-
this.isStartPart && style.dayStartContainer,
|
|
140
|
-
this.isEnd && style.dayEndContainer,
|
|
141
|
-
]}>
|
|
142
|
-
{this.isValid && this.isInScope ? (
|
|
143
|
-
<TouchableHighlight
|
|
144
|
-
style={[
|
|
145
|
-
style.day,
|
|
146
|
-
{
|
|
147
|
-
paddingVertical: !!price ? Spacing.XS : Spacing.S,
|
|
148
|
-
},
|
|
149
|
-
(this.isStart || this.isEnd) && {
|
|
150
|
-
backgroundColor: theme.colors.primary,
|
|
151
|
-
},
|
|
152
|
-
]}
|
|
153
|
-
underlayColor="rgba(255, 255, 255, 0.35)"
|
|
154
|
-
onPress={this.chooseDay}>
|
|
155
|
-
<>
|
|
156
|
-
{this.lunarDate && this.showLunar && (
|
|
157
|
-
<Text
|
|
158
|
-
color={lunarDayColor}
|
|
159
|
-
typography={'label_xxs'}
|
|
160
|
-
style={style.lunarDayText}>
|
|
161
|
-
{this.lunarDate.lunarDay === 1
|
|
162
|
-
? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
|
|
163
|
-
: this.lunarDate.lunarDay}
|
|
164
|
-
</Text>
|
|
165
|
-
)}
|
|
166
|
-
<Text
|
|
167
|
-
color={textDayColor}
|
|
168
|
-
typography={'header_s'}
|
|
169
|
-
style={[style.dayText, {paddingTop: !!price ? 4 : 0}]}>
|
|
170
|
-
{text}
|
|
171
|
-
</Text>
|
|
172
|
-
{!!price ? (
|
|
173
|
-
<Text
|
|
174
|
-
style={[
|
|
175
|
-
this.isValid && this.isInScope
|
|
176
|
-
? style.price
|
|
177
|
-
: style.dayTextDisabled,
|
|
178
|
-
isBestPrice && {
|
|
179
|
-
color: theme.colors.primary,
|
|
180
|
-
},
|
|
181
|
-
(this.isStart || this.isEnd) && {
|
|
182
|
-
color: Colors.black_01,
|
|
183
|
-
},
|
|
184
|
-
]}>
|
|
185
|
-
{price}
|
|
186
|
-
</Text>
|
|
187
|
-
) : (
|
|
188
|
-
<View
|
|
189
|
-
style={{
|
|
190
|
-
paddingBottom: this.props.havePriceList ? Spacing.S : 0,
|
|
191
|
-
}}
|
|
192
|
-
/>
|
|
193
|
-
)}
|
|
194
|
-
</>
|
|
195
|
-
</TouchableHighlight>
|
|
196
|
-
) : (
|
|
197
|
-
<View
|
|
198
|
-
style={[
|
|
199
|
-
style.day,
|
|
200
|
-
{
|
|
201
|
-
paddingVertical: !!price
|
|
202
|
-
? Spacing.XS + Spacing.XXS
|
|
203
|
-
: Spacing.S,
|
|
204
|
-
},
|
|
205
|
-
]}>
|
|
206
|
-
{this.lunarDate && this.showLunar && text ? (
|
|
207
|
-
<Text
|
|
208
|
-
color={theme.colors.text.disable}
|
|
209
|
-
typography={'label_xxs'}
|
|
210
|
-
style={style.lunarDayText}>
|
|
211
|
-
{this.lunarDate.lunarDay === 1
|
|
212
|
-
? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
|
|
213
|
-
: this.lunarDate.lunarDay}
|
|
214
|
-
</Text>
|
|
215
|
-
) : (
|
|
216
|
-
<View />
|
|
217
|
-
)}
|
|
218
|
-
<Text color={theme.colors.text.disable} style={style.dayText}>
|
|
219
|
-
{text}
|
|
220
|
-
</Text>
|
|
221
|
-
{text && !!price ? (
|
|
222
|
-
<Text
|
|
223
|
-
style={[
|
|
224
|
-
this.isValid && this.isInScope
|
|
225
|
-
? style.price
|
|
226
|
-
: style.dayTextDisabled,
|
|
227
|
-
isBestPrice && {
|
|
228
|
-
color: theme.colors.primary,
|
|
229
|
-
},
|
|
230
|
-
]}>
|
|
231
|
-
{price}
|
|
232
|
-
</Text>
|
|
233
|
-
) : (
|
|
234
|
-
<View
|
|
235
|
-
style={{
|
|
236
|
-
paddingBottom: this.props.havePriceList ? Spacing.S : 0,
|
|
237
|
-
}}
|
|
238
|
-
/>
|
|
239
|
-
)}
|
|
240
|
-
</View>
|
|
241
|
-
)}
|
|
242
|
-
</View>
|
|
243
|
-
</View>
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export default Day;
|