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