@momo-kits/calendar 0.0.48-rc.2 → 0.0.48

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/holidayData.ts ADDED
@@ -0,0 +1,125 @@
1
+ const holidayData = {
2
+ solar: {
3
+ 1: [
4
+ {
5
+ day: 1,
6
+ month: 1,
7
+ label: 'newYear',
8
+ },
9
+ ],
10
+ 2: [
11
+ {
12
+ day: 14,
13
+ month: 2,
14
+ label: 'valentine',
15
+ },
16
+ ],
17
+ 3: [
18
+ {
19
+ day: 8,
20
+ month: 3,
21
+ label: 'womenDay',
22
+ },
23
+ ],
24
+ 4: [
25
+ {
26
+ day: 30,
27
+ month: 4,
28
+ label: 'liberationDay',
29
+ },
30
+ ],
31
+ 5: [
32
+ {
33
+ day: 1,
34
+ month: 5,
35
+ label: 'laborDay',
36
+ },
37
+ ],
38
+ 6: [
39
+ {
40
+ day: 1,
41
+ month: 6,
42
+ label: 'childrenDay',
43
+ },
44
+ ],
45
+ 9: [
46
+ {
47
+ day: 2,
48
+ month: 9,
49
+ label: 'nationalDay',
50
+ },
51
+ ],
52
+ 10: [
53
+ {
54
+ day: 20,
55
+ month: 10,
56
+ label: 'womenDayVN',
57
+ },
58
+ ],
59
+ 11: [
60
+ {
61
+ day: 20,
62
+ month: 11,
63
+ label: 'teacherDay',
64
+ },
65
+ ],
66
+ 12: [
67
+ {
68
+ day: 24,
69
+ month: 12,
70
+ label: 'christmasEve',
71
+ },
72
+ {
73
+ day: 25,
74
+ month: 12,
75
+ label: 'christmas',
76
+ },
77
+ ],
78
+ },
79
+ lunar: [
80
+ {
81
+ lunarDay: 30,
82
+ lunarMonth: 12,
83
+ lunar: true,
84
+ label: 'lunarNewYear',
85
+ highlight: '(30/12)',
86
+ },
87
+ {
88
+ lunarDay: 1,
89
+ lunarMonth: 1,
90
+ lunar: true,
91
+ label: 'lunarNewYear',
92
+ highlight: '(1/1)',
93
+ },
94
+ {
95
+ lunarDay: 2,
96
+ lunarMonth: 1,
97
+ lunar: true,
98
+ label: 'lunarNewYear',
99
+ highlight: '(2/1)',
100
+ },
101
+ {
102
+ lunarDay: 3,
103
+ lunarMonth: 1,
104
+ lunar: true,
105
+ label: 'lunarNewYear',
106
+ highlight: '(3/1)',
107
+ },
108
+ {
109
+ lunarDay: 4,
110
+ lunarMonth: 1,
111
+ lunar: true,
112
+ label: 'lunarNewYear',
113
+ highlight: '(4/1)',
114
+ },
115
+ {
116
+ lunarDay: 10,
117
+ lunarMonth: 3,
118
+ lunar: true,
119
+ label: 'hungKingDay',
120
+ highlight: '(10/3)',
121
+ },
122
+ ],
123
+ };
124
+
125
+ export default holidayData;
package/index.tsx ADDED
@@ -0,0 +1,479 @@
1
+ import React, {Component, createContext, RefObject} from 'react';
2
+ import {Dimensions, LayoutChangeEvent, View} from 'react-native';
3
+ import moment from 'moment';
4
+ import {
5
+ ApplicationContext,
6
+ Radius,
7
+ scaleSize,
8
+ Spacing,
9
+ Switch,
10
+ Text,
11
+ } from '@momo-kits/foundation';
12
+ import CalendarPro from './CalendarPro';
13
+ import TabHeader from './TabHeader';
14
+ import {CalendarProps, CalendarState} from './types';
15
+ import styles from './styles';
16
+
17
+ const DOUBLE = 'doubleDate';
18
+
19
+ export const ContainerContext = createContext({width: 0, height: 0});
20
+
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>;
30
+
31
+ constructor(props: CalendarProps) {
32
+ super(props);
33
+ this.doubleDate = props.doubleDate
34
+ ? {
35
+ first: props.doubleDate.first ? moment(props.doubleDate.first) : null,
36
+ second: props.doubleDate.second
37
+ ? moment(props.doubleDate.second)
38
+ : null,
39
+ }
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
+ }
56
+
57
+ componentDidMount() {
58
+ const {id} = this.props;
59
+ this.tabSelected = id || 0;
60
+ this.viewInit();
61
+ }
62
+
63
+ viewInit() {
64
+ const {mode} = this.props;
65
+ if (mode === DOUBLE) {
66
+ if (
67
+ this.cellHeader1.current &&
68
+ this.cellHeader2.current &&
69
+ this.calendarPicker.current
70
+ ) {
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
79
+ );
80
+ }
81
+ } else if (this.calendarPicker.current) {
82
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate);
83
+ }
84
+ }
85
+
86
+ onChangeTab = (idTab: number) => {
87
+ this.props.onChangeTab?.(idTab);
88
+ this.tabSelected = idTab;
89
+
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();
95
+ };
96
+
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
+ }
106
+
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
188
+ );
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
+ }
200
+ } else {
201
+ this.doubleDate.first = this.selectedDate;
202
+ this.doubleDate.second = null;
203
+
204
+ this.cellHeader1?.current?.updateView(this.selectedDate, false);
205
+ this.cellHeader2?.current?.updateView(null, false);
206
+ }
207
+ }
208
+
209
+ processDoubleDate() {
210
+ if (this.tabSelected === 0) {
211
+ this.processDateFirst();
212
+ } else {
213
+ this.processDateSecond();
214
+ }
215
+ }
216
+
217
+ updateView() {
218
+ const {onDateChange} = this.props;
219
+ const {isDoubleDateMode} = this.state;
220
+
221
+ if (isDoubleDateMode) {
222
+ this.processDoubleDate();
223
+ } else {
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
+ }
231
+ }
232
+ }
233
+
234
+ onDateChange = (date: moment.Moment) => {
235
+ this.selectedDate = date;
236
+ this.updateView();
237
+ };
238
+
239
+ updateHeaderView = () => {
240
+ const {onDateChange, onCTAStateChange} = this.props;
241
+ const {isDoubleDateMode} = this.state;
242
+ if (isDoubleDateMode) {
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
+ }
277
+ } else {
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
+ }
291
+ }
292
+ }
293
+ };
294
+
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
+ );
307
+ };
308
+
309
+ renderSwitchReturnSelection = () => {
310
+ const {isDoubleDateMode} = this.state;
311
+ const {translate, theme} = this.context;
312
+ return (
313
+ <View style={styles.headerContainer}>
314
+ <View
315
+ style={[
316
+ styles.viewSwitch,
317
+ {backgroundColor: theme.colors.background.surface},
318
+ ]}>
319
+ <Text typography={'label_default_medium'}>
320
+ {translate('chooseRoundtrip')}
321
+ </Text>
322
+ <Switch
323
+ value={isDoubleDateMode}
324
+ onChange={this.toggleSelectionDateMode}
325
+ />
326
+ </View>
327
+ </View>
328
+ );
329
+ };
330
+
331
+ renderHeaderPanel = (theme: {colors: {background: {default: string}}}) => {
332
+ const {isDoubleDateMode} = this.state;
333
+ const {headerFrom, headerTo} = this.props;
334
+ return isDoubleDateMode ? (
335
+ <View
336
+ style={[
337
+ styles.viewPanel,
338
+ {backgroundColor: theme.colors.background.default},
339
+ ]}>
340
+ <TabHeader
341
+ id={0}
342
+ ref={this.cellHeader1}
343
+ onChangeTab={this.onChangeTab}
344
+ label={headerFrom || 'depart'}
345
+ activeTab
346
+ date={this.doubleDate.first}
347
+ />
348
+ <View style={{width: 4, height: '100%'}} />
349
+ <TabHeader
350
+ id={1}
351
+ ref={this.cellHeader2}
352
+ onChangeTab={this.onChangeTab}
353
+ label={headerTo || 'return'}
354
+ activeTab={false}
355
+ date=""
356
+ />
357
+ </View>
358
+ ) : (
359
+ <View
360
+ style={[
361
+ styles.viewPanel,
362
+ {backgroundColor: theme.colors.background.default},
363
+ ]}>
364
+ <TabHeader
365
+ id={0}
366
+ disabled
367
+ ref={this.cellHeaderSingle}
368
+ label={headerFrom || 'depart'}
369
+ activeTab
370
+ date={this.selectedDate}
371
+ />
372
+ </View>
373
+ );
374
+ };
375
+
376
+ setDateRange = (
377
+ dateRange: {
378
+ startDate: moment.Moment | undefined;
379
+ endDate: moment.Moment | undefined;
380
+ },
381
+ isScrollToStartDate: any
382
+ ) => {
383
+ const {mode, doubleDate = {}} = this.props;
384
+ if (mode === 'doubleDate') {
385
+ this.cellHeader1?.current?.updateView(
386
+ dateRange.startDate,
387
+ this.tabSelected === 0
388
+ );
389
+ this.cellHeader2?.current?.updateView(
390
+ dateRange.endDate,
391
+ this.tabSelected === 1
392
+ );
393
+ this.calendarPicker?.current?.setDateRange(
394
+ dateRange,
395
+ isScrollToStartDate
396
+ );
397
+ this.doubleDate = doubleDate
398
+ ? {
399
+ first: dateRange.startDate ? moment(dateRange.startDate) : null,
400
+ second: dateRange.endDate ? moment(dateRange.endDate) : null,
401
+ }
402
+ : {};
403
+ }
404
+ };
405
+
406
+ onLayout = (e: LayoutChangeEvent) => {
407
+ this.setState({containerWidth: e.nativeEvent.layout.width});
408
+ };
409
+
410
+ render() {
411
+ const currentDate = new Date();
412
+ const minDateDefault = new Date(currentDate);
413
+ const maxDateDefault = new Date(currentDate);
414
+ minDateDefault.setFullYear(minDateDefault.getFullYear() - 1);
415
+ maxDateDefault.setFullYear(maxDateDefault.getFullYear() + 1);
416
+
417
+ const {
418
+ isOffLunar,
419
+ isHideHoliday,
420
+ isShowLunar,
421
+ onCallbackCalendar,
422
+ priceList,
423
+ labelFrom,
424
+ labelTo,
425
+ isHideLabel,
426
+ minDate = minDateDefault,
427
+ maxDate = maxDateDefault,
428
+ doubleDate,
429
+ style,
430
+ disabledDays = [],
431
+ hideHeaderTab = false,
432
+ } = this.props;
433
+ const {isDoubleDateMode, containerWidth} = this.state;
434
+ const {theme} = this.context;
435
+ return (
436
+ <ContainerContext.Provider
437
+ value={{
438
+ width: containerWidth,
439
+ height: priceList ? scaleSize(48) : scaleSize(34),
440
+ }}>
441
+ <View onLayout={this.onLayout} style={[style, styles.scrollView]}>
442
+ <View
443
+ style={[
444
+ {
445
+ backgroundColor: theme.colors.background.surface,
446
+ borderRadius: Radius.XS,
447
+ marginBottom: Spacing.S,
448
+ },
449
+ hideHeaderTab && styles.invisible,
450
+ ]}>
451
+ {this.renderSwitchReturnSelection()}
452
+ {this.renderHeaderPanel(theme)}
453
+ </View>
454
+ <CalendarPro
455
+ priceList={priceList}
456
+ ref={this.calendarPicker}
457
+ startDate={doubleDate?.first}
458
+ endDate={doubleDate?.second}
459
+ onDateChange={this.onDateChange}
460
+ isDoubleDateMode={isDoubleDateMode}
461
+ selectedDate={this.selectedDate}
462
+ isShowLunar={isShowLunar}
463
+ onCallbackCalendar={onCallbackCalendar}
464
+ labelFrom={labelFrom}
465
+ labelTo={labelTo}
466
+ isHideLabel={isHideLabel}
467
+ minDate={minDate}
468
+ maxDate={maxDate}
469
+ isHideHoliday={isHideHoliday}
470
+ isOffLunar={isOffLunar}
471
+ disabledDays={disabledDays}
472
+ />
473
+ </View>
474
+ </ContainerContext.Provider>
475
+ );
476
+ }
477
+ }
478
+
479
+ export {Calendar};
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
- "name": "@momo-kits/calendar",
3
- "version": "0.0.48-rc.2",
4
- "private": false,
5
- "main": "index.js",
6
- "dependencies": {
7
- "@momo-kits/date-picker": "latest",
8
- "moment": "^2.24.0"
9
- },
10
- "peerDependencies": {
11
- "react": "16.9.0",
12
- "react-native": ">=0.55",
13
- "prop-types": "^15.7.2",
14
- "@momo-kits/core": ">=0.0.5-beta"
15
- },
16
- "devDependencies": {},
17
- "license": "MoMo"
18
- }
2
+ "name": "@momo-kits/calendar",
3
+ "version": "0.0.48",
4
+ "private": false,
5
+ "main": "index.tsx",
6
+ "peerDependencies": {
7
+ "@momo-kits/foundation": "latest",
8
+ "react": "16.9.0",
9
+ "react-native": ">=0.55",
10
+ "prop-types": "^15.7.2"
11
+ },
12
+ "devDependencies": {
13
+ "@momo-platform/versions": "4.1.11"
14
+ },
15
+ "license": "MoMo",
16
+ "dependencies": {
17
+ "moment": "^2.24.0"
18
+ }
19
+ }
package/publish.sh CHANGED
@@ -1,29 +1,23 @@
1
1
  #!/bin/bash
2
+
3
+ # Prepare dist files
2
4
  rm -rf dist
3
5
  mkdir dist
4
-
5
- cp . ./dist
6
-
7
- # GET VERSION from mck_package.json
8
- VERSIONSTRING=( v$(jq .version package.json) )
9
- VERSION=(${VERSIONSTRING//[\"]/})
10
- echo VERSION: $VERSION
11
-
12
- rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
13
-
14
- # #babel component to dist
15
- #babel ./dist -d dist --copy-files
16
-
17
- #copy option
18
- #cp -r ./src/ dist
19
-
20
-
21
- #npm login
22
- #publish dist to npm
6
+ rsync -r --exclude=/dist ./* dist
23
7
  cd dist
24
- npm publish --tag beta --access=public
8
+
9
+ if [ "$1" == "beta" ]; then # Publish beta
10
+ npm version $(npm view @momo-kits/calendar@beta version)
11
+ npm version prepatch --preid=beta
12
+ npm publish --tag beta --access=public
13
+ else # Publish latest
14
+ npm version $(npm view @momo-kits/calendar version)
15
+ npm version patch
16
+ npm publish --tag latest --access=public
17
+ fi
18
+ PACKAGE_NAME=$(npm pkg get name)
19
+ NEW_PACKAGE_VERSION=$(npm pkg get version)
20
+
21
+ # Clean up
25
22
  cd ..
26
23
  rm -rf dist
27
-
28
-
29
- #curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/calendar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/calendar"}'