@momo-kits/calendar 0.0.55-beta → 0.0.55-beta.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/package.json +17 -16
- package/publish.sh +2 -2
- package/src/Calendar.js +193 -67
- package/src/CalendarPro.js +150 -87
- package/src/Day/index.js +119 -96
- package/src/MonthList.js +81 -53
- package/src/calendarPicker/Day.js +33 -32
- package/src/calendarPicker/WeekDaysLabels.js +6 -7
package/src/CalendarPro.js
CHANGED
|
@@ -7,11 +7,16 @@ import {
|
|
|
7
7
|
Dimensions,
|
|
8
8
|
ScrollView,
|
|
9
9
|
TouchableWithoutFeedback,
|
|
10
|
-
StyleSheet
|
|
10
|
+
StyleSheet,
|
|
11
11
|
} from 'react-native';
|
|
12
12
|
import Moment from 'moment';
|
|
13
13
|
import {
|
|
14
|
-
Text,
|
|
14
|
+
Text,
|
|
15
|
+
SwitchLanguage,
|
|
16
|
+
LocalizedStrings,
|
|
17
|
+
Colors,
|
|
18
|
+
Image,
|
|
19
|
+
IconSource,
|
|
15
20
|
} from '@momo-kits/core';
|
|
16
21
|
import MonthList from './MonthList';
|
|
17
22
|
import HeaderControl from './HeaderControl';
|
|
@@ -44,7 +49,8 @@ export default class CalendarPro extends Component {
|
|
|
44
49
|
return {
|
|
45
50
|
ownUpdate: false,
|
|
46
51
|
};
|
|
47
|
-
}
|
|
52
|
+
}
|
|
53
|
+
if (nextProps.isShowLunar !== prevState.showLunar) {
|
|
48
54
|
return { showLunar: nextProps.isShowLunar };
|
|
49
55
|
}
|
|
50
56
|
return null;
|
|
@@ -52,24 +58,29 @@ export default class CalendarPro extends Component {
|
|
|
52
58
|
|
|
53
59
|
setDateRange = (dateRange, isScrollToStartDate) => {
|
|
54
60
|
if (dateRange && dateRange.startDate && dateRange.endDate) {
|
|
55
|
-
this.setState(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
this.setState(
|
|
62
|
+
{ startDate: dateRange.startDate, endDate: dateRange.endDate },
|
|
63
|
+
() => {
|
|
64
|
+
const dateScroll = isScrollToStartDate
|
|
65
|
+
? dateRange.startDate
|
|
66
|
+
: dateRange.endDate;
|
|
67
|
+
this.refs.MonthList.scrollToMonth(dateScroll);
|
|
68
|
+
},
|
|
69
|
+
);
|
|
59
70
|
}
|
|
60
|
-
}
|
|
71
|
+
};
|
|
61
72
|
|
|
62
73
|
ownSetState(state) {
|
|
63
74
|
this.setState({ ...state, ownUpdate: true });
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
loadLabel = (data, type) => {
|
|
67
|
-
const {
|
|
68
|
-
i18n,
|
|
69
|
-
customI18n
|
|
70
|
-
} = this.props;
|
|
78
|
+
const { i18n, customI18n } = this.props;
|
|
71
79
|
if (~['w', 'weekday', 'text'].indexOf(type)) {
|
|
72
|
-
return (
|
|
80
|
+
return (
|
|
81
|
+
(customI18n[type] || {})[data] ||
|
|
82
|
+
Util.I18N_MAP[i18n][type][data]
|
|
83
|
+
);
|
|
73
84
|
}
|
|
74
85
|
if (type === 'date') {
|
|
75
86
|
return data.format(customI18n[type] || Util.I18N_MAP[i18n][type]);
|
|
@@ -77,11 +88,7 @@ export default class CalendarPro extends Component {
|
|
|
77
88
|
};
|
|
78
89
|
|
|
79
90
|
getDateRange = () => {
|
|
80
|
-
const {
|
|
81
|
-
maxDate,
|
|
82
|
-
minDate,
|
|
83
|
-
format
|
|
84
|
-
} = this.props;
|
|
91
|
+
const { maxDate, minDate, format } = this.props;
|
|
85
92
|
let max = Moment(maxDate, format);
|
|
86
93
|
let min = Moment(minDate, format);
|
|
87
94
|
const maxValid = max.isValid();
|
|
@@ -102,25 +109,23 @@ export default class CalendarPro extends Component {
|
|
|
102
109
|
};
|
|
103
110
|
|
|
104
111
|
onChoose = (day) => {
|
|
105
|
-
const {
|
|
106
|
-
startDate, tabSelected
|
|
107
|
-
} = this.state;
|
|
112
|
+
const { startDate, tabSelected } = this.state;
|
|
108
113
|
const { isDoubleDateMode, onDateChange } = this.props;
|
|
109
114
|
if (isDoubleDateMode) {
|
|
110
115
|
if (tabSelected === 1) {
|
|
111
116
|
if (startDate && day >= startDate) {
|
|
112
117
|
this.ownSetState({
|
|
113
|
-
endDate: day
|
|
118
|
+
endDate: day,
|
|
114
119
|
});
|
|
115
120
|
} else if (startDate && day < startDate) {
|
|
116
121
|
this.ownSetState({
|
|
117
122
|
startDate: day,
|
|
118
|
-
endDate: null
|
|
123
|
+
endDate: null,
|
|
119
124
|
});
|
|
120
125
|
}
|
|
121
126
|
} else {
|
|
122
127
|
this.ownSetState({
|
|
123
|
-
startDate: day
|
|
128
|
+
startDate: day,
|
|
124
129
|
});
|
|
125
130
|
}
|
|
126
131
|
} else {
|
|
@@ -136,9 +141,7 @@ export default class CalendarPro extends Component {
|
|
|
136
141
|
|
|
137
142
|
executeProcessAfterScrollCalendar = (date, key) => {
|
|
138
143
|
const holidays = Object.values(Util.getHolidaysInMonth(Moment(date)));
|
|
139
|
-
const {
|
|
140
|
-
showLunar
|
|
141
|
-
} = this.state;
|
|
144
|
+
const { showLunar } = this.state;
|
|
142
145
|
if (this.refs && this.refs.HeaderControl) {
|
|
143
146
|
this.refs.HeaderControl.onUpdateInfo({ date });
|
|
144
147
|
this.header = date.clone().startOf('month');
|
|
@@ -165,7 +168,7 @@ export default class CalendarPro extends Component {
|
|
|
165
168
|
this.ownSetState({
|
|
166
169
|
startDate: firstDate ? Moment(firstDate) : null,
|
|
167
170
|
endDate: secondDate ? Moment(secondDate) : null,
|
|
168
|
-
tabSelected
|
|
171
|
+
tabSelected,
|
|
169
172
|
});
|
|
170
173
|
};
|
|
171
174
|
|
|
@@ -183,12 +186,22 @@ export default class CalendarPro extends Component {
|
|
|
183
186
|
onCallbackCalendar('lunar', nextStateShowLunar);
|
|
184
187
|
}
|
|
185
188
|
|
|
186
|
-
this.ownSetState({
|
|
189
|
+
this.ownSetState({
|
|
190
|
+
showLunar: !showLunar,
|
|
191
|
+
temp: data,
|
|
192
|
+
ownUpdate: true,
|
|
193
|
+
});
|
|
187
194
|
};
|
|
188
195
|
|
|
189
196
|
onPressBackArrow = () => {
|
|
190
|
-
const previousDate = Moment(this.header)
|
|
191
|
-
|
|
197
|
+
const previousDate = Moment(this.header)
|
|
198
|
+
.startOf('month')
|
|
199
|
+
.subtract(1, 'months');
|
|
200
|
+
if (
|
|
201
|
+
this.refs &&
|
|
202
|
+
this.refs.HeaderControl &&
|
|
203
|
+
previousDate.isSameOrAfter(this.minDate, 'month')
|
|
204
|
+
) {
|
|
192
205
|
this.header = previousDate;
|
|
193
206
|
this.refs.HeaderControl.onUpdateInfo({ date: previousDate });
|
|
194
207
|
this.refs.MonthList.scrollToMonth(previousDate);
|
|
@@ -197,7 +210,11 @@ export default class CalendarPro extends Component {
|
|
|
197
210
|
|
|
198
211
|
onPressNextArrow = () => {
|
|
199
212
|
const nextDate = Moment(this.header).startOf('month').add(1, 'months');
|
|
200
|
-
if (
|
|
213
|
+
if (
|
|
214
|
+
this.refs &&
|
|
215
|
+
this.refs.HeaderControl &&
|
|
216
|
+
nextDate.isSameOrBefore(this.maxDate, 'month')
|
|
217
|
+
) {
|
|
201
218
|
this.header = nextDate;
|
|
202
219
|
this.refs.HeaderControl.onUpdateInfo({ date: nextDate });
|
|
203
220
|
this.refs.MonthList.scrollToMonth(nextDate);
|
|
@@ -205,15 +222,22 @@ export default class CalendarPro extends Component {
|
|
|
205
222
|
};
|
|
206
223
|
|
|
207
224
|
render() {
|
|
225
|
+
const { startDate, endDate, showLunar, tabSelected, holidays, temp } =
|
|
226
|
+
this.state;
|
|
208
227
|
const {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
228
|
+
i18n,
|
|
229
|
+
isDoubleDateMode,
|
|
230
|
+
priceList,
|
|
231
|
+
labelFrom,
|
|
232
|
+
labelTo,
|
|
233
|
+
isHideLabel,
|
|
234
|
+
isHideHoliday,
|
|
235
|
+
isOffLunar,
|
|
213
236
|
} = this.props;
|
|
214
237
|
let priceListFormat = priceList?.outbound;
|
|
215
238
|
if (isDoubleDateMode) {
|
|
216
|
-
priceListFormat =
|
|
239
|
+
priceListFormat =
|
|
240
|
+
tabSelected === 0 ? priceList?.outbound : priceList?.inbound;
|
|
217
241
|
}
|
|
218
242
|
return (
|
|
219
243
|
<View style={styles.container}>
|
|
@@ -227,13 +251,19 @@ export default class CalendarPro extends Component {
|
|
|
227
251
|
<View style={styles.viewDay}>
|
|
228
252
|
{[1, 2, 3, 4, 5, 6, 7].map((item) => (
|
|
229
253
|
<Text
|
|
230
|
-
style={[
|
|
231
|
-
|
|
232
|
-
|
|
254
|
+
style={[
|
|
255
|
+
styles.textDay,
|
|
256
|
+
{
|
|
257
|
+
color:
|
|
258
|
+
item === 6 || item === 7
|
|
259
|
+
? Colors.red_05
|
|
260
|
+
: Colors.black_12,
|
|
261
|
+
},
|
|
262
|
+
]}
|
|
263
|
+
key={item}>
|
|
233
264
|
{Util.mapWeeKDate(item)}
|
|
234
265
|
</Text>
|
|
235
|
-
)
|
|
236
|
-
)}
|
|
266
|
+
))}
|
|
237
267
|
</View>
|
|
238
268
|
<MonthList
|
|
239
269
|
ref="MonthList"
|
|
@@ -257,51 +287,72 @@ export default class CalendarPro extends Component {
|
|
|
257
287
|
isHideLabel={isHideLabel}
|
|
258
288
|
/>
|
|
259
289
|
</View>
|
|
260
|
-
{
|
|
261
|
-
|
|
262
|
-
<
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
{
|
|
271
|
-
|
|
272
|
-
</
|
|
273
|
-
|
|
274
|
-
|
|
290
|
+
{!isOffLunar && (
|
|
291
|
+
<View style={styles.viewLunar}>
|
|
292
|
+
<TouchableWithoutFeedback
|
|
293
|
+
onPress={this.toggleLunarDate}>
|
|
294
|
+
<Image
|
|
295
|
+
source={
|
|
296
|
+
showLunar
|
|
297
|
+
? IconSource.ic_checkbox_checked_24
|
|
298
|
+
: IconSource.ic_checkbox_unchecked_24
|
|
299
|
+
}
|
|
300
|
+
style={styles.iconSelected}
|
|
301
|
+
/>
|
|
302
|
+
</TouchableWithoutFeedback>
|
|
303
|
+
<Text
|
|
304
|
+
style={styles.txtLunar}
|
|
305
|
+
onPress={this.toggleLunarDate}>
|
|
306
|
+
{SwitchLanguage.showLunar}
|
|
307
|
+
</Text>
|
|
308
|
+
</View>
|
|
309
|
+
)}
|
|
275
310
|
|
|
276
|
-
{
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const labelHoliday = showLunar
|
|
285
|
-
|
|
286
|
-
|
|
311
|
+
{!isHideHoliday && (
|
|
312
|
+
<ScrollView
|
|
313
|
+
contentContainerStyle={styles.contentScroll}
|
|
314
|
+
showsVerticalScrollIndicator={false}
|
|
315
|
+
enabledNestedScroll>
|
|
316
|
+
{temp &&
|
|
317
|
+
temp.length > 0 &&
|
|
318
|
+
temp.map((item, idx) => {
|
|
319
|
+
const labelHoliday = showLunar
|
|
320
|
+
? item.mixedLabel || item.label || ''
|
|
321
|
+
: item.label || '';
|
|
322
|
+
const labelHighlight = showLunar
|
|
323
|
+
? item.highlight || ''
|
|
324
|
+
: '';
|
|
325
|
+
const labelDate =
|
|
326
|
+
LocalizedStrings.defaultLanguage === 'en'
|
|
327
|
+
? `${Util.mapMonthShorten(
|
|
328
|
+
item.month,
|
|
329
|
+
)} ${item.day}`
|
|
330
|
+
: `${item.day} tháng ${item.month}`;
|
|
287
331
|
return (
|
|
288
|
-
<View
|
|
289
|
-
|
|
332
|
+
<View
|
|
333
|
+
style={styles.row}
|
|
334
|
+
key={idx.toString()}>
|
|
335
|
+
<Text style={styles.txtMonthLunar}>
|
|
290
336
|
{labelDate}
|
|
291
|
-
</Text
|
|
292
|
-
<Text
|
|
337
|
+
</Text>
|
|
338
|
+
<Text style={styles.subTextLunar}>
|
|
293
339
|
{`${labelHoliday} `}
|
|
294
|
-
{
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
340
|
+
{labelHighlight ? (
|
|
341
|
+
<Text
|
|
342
|
+
style={{
|
|
343
|
+
color: Colors.red_05,
|
|
344
|
+
}}>
|
|
345
|
+
{labelHighlight}
|
|
346
|
+
</Text>
|
|
347
|
+
) : (
|
|
348
|
+
''
|
|
349
|
+
)}
|
|
350
|
+
</Text>
|
|
298
351
|
</View>
|
|
299
352
|
);
|
|
300
353
|
})}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
|
|
354
|
+
</ScrollView>
|
|
355
|
+
)}
|
|
305
356
|
</View>
|
|
306
357
|
);
|
|
307
358
|
}
|
|
@@ -313,15 +364,21 @@ CalendarPro.propTypes = {
|
|
|
313
364
|
customI18n: PropTypes.object,
|
|
314
365
|
isShowLunar: PropTypes.bool,
|
|
315
366
|
onCallbackCalendar: PropTypes.func,
|
|
316
|
-
minDate: PropTypes.oneOfType([
|
|
317
|
-
|
|
367
|
+
minDate: PropTypes.oneOfType([
|
|
368
|
+
PropTypes.string,
|
|
369
|
+
PropTypes.instanceOf(Date),
|
|
370
|
+
]),
|
|
371
|
+
maxDate: PropTypes.oneOfType([
|
|
372
|
+
PropTypes.string,
|
|
373
|
+
PropTypes.instanceOf(Date),
|
|
374
|
+
]),
|
|
318
375
|
};
|
|
319
376
|
|
|
320
377
|
CalendarPro.defaultProps = {
|
|
321
378
|
format: 'YYYY-MM-DD',
|
|
322
379
|
i18n: 'vi',
|
|
323
380
|
customI18n: {},
|
|
324
|
-
isShowLunar: true
|
|
381
|
+
isShowLunar: true,
|
|
325
382
|
};
|
|
326
383
|
|
|
327
384
|
const styles = StyleSheet.create({
|
|
@@ -331,7 +388,7 @@ const styles = StyleSheet.create({
|
|
|
331
388
|
// fontSize: 12,
|
|
332
389
|
color: '#222222',
|
|
333
390
|
paddingLeft: 6,
|
|
334
|
-
flexShrink: 1
|
|
391
|
+
flexShrink: 1,
|
|
335
392
|
},
|
|
336
393
|
contentScroll: { paddingHorizontal: 12, paddingVertical: 10 },
|
|
337
394
|
iconSelected: { width: 24, height: 24, resizeMode: 'cover' },
|
|
@@ -339,10 +396,16 @@ const styles = StyleSheet.create({
|
|
|
339
396
|
paddingLeft: 6,
|
|
340
397
|
color: '#222222',
|
|
341
398
|
// fontSize: 12,
|
|
342
|
-
lineHeight: 14
|
|
399
|
+
lineHeight: 14,
|
|
343
400
|
},
|
|
344
401
|
viewLunar: {
|
|
345
|
-
flexDirection: 'row',
|
|
402
|
+
flexDirection: 'row',
|
|
403
|
+
alignItems: 'center',
|
|
404
|
+
marginHorizontal: 12,
|
|
405
|
+
paddingVertical: 12,
|
|
406
|
+
borderBottomWidth: 1,
|
|
407
|
+
borderStyle: 'solid',
|
|
408
|
+
borderColor: '#c7c7cd',
|
|
346
409
|
},
|
|
347
410
|
viewDate: { paddingHorizontal: 12 },
|
|
348
411
|
textDay: {
|
|
@@ -359,5 +422,5 @@ const styles = StyleSheet.create({
|
|
|
359
422
|
paddingTop: 15,
|
|
360
423
|
paddingBottom: 10,
|
|
361
424
|
},
|
|
362
|
-
container: { flex: 1, backgroundColor: 'white', marginTop: 20
|
|
425
|
+
container: { flex: 1, backgroundColor: 'white', marginTop: 20 },
|
|
363
426
|
});
|