@momo-kits/calendar 0.167.1-duo.8 → 0.167.1-rc.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/CalendarHeader.tsx +107 -0
- package/CalendarPro.tsx +18 -26
- package/ContainerContext.ts +3 -0
- package/Day.tsx +20 -20
- package/HeaderControl.tsx +1 -2
- package/LunarDateConverter.ts +21 -19
- package/Month.tsx +8 -20
- package/MonthList.tsx +36 -23
- package/TabHeader.tsx +57 -83
- package/Util.ts +6 -108
- package/index.tsx +51 -123
- package/package.json +17 -17
- package/styles.ts +22 -16
- package/types.ts +5 -38
- package/LunarService.ts +0 -206
package/TabHeader.tsx
CHANGED
|
@@ -1,91 +1,65 @@
|
|
|
1
|
-
import React
|
|
2
|
-
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useContext,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useState,
|
|
6
|
+
} from 'react';
|
|
7
|
+
import { TouchableWithoutFeedback, View } from 'react-native';
|
|
3
8
|
import Moment from 'moment';
|
|
4
9
|
import Util from './Util';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Radius,
|
|
9
|
-
Spacing,
|
|
10
|
-
Text,
|
|
11
|
-
} from '@momo-kits/foundation';
|
|
12
|
-
import {TabHeaderProps, TabHeaderState} from './types';
|
|
10
|
+
import styles from './styles';
|
|
11
|
+
import { ApplicationContext, Text } from '@momo-kits/foundation';
|
|
12
|
+
import { TabHeaderProps, TabHeaderRef } from './types';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
defaultDate: Moment.Moment | null;
|
|
14
|
+
const TabHeader = forwardRef<TabHeaderRef, TabHeaderProps>((props, ref) => {
|
|
15
|
+
const { label, disabled, id, onChangeTab } = props;
|
|
16
|
+
const { theme, translate } = useContext(ApplicationContext);
|
|
17
|
+
const [active, setActive] = useState<boolean | undefined>(props.activeTab);
|
|
18
|
+
const [date, setDate] = useState<Moment.Moment | undefined>(
|
|
19
|
+
props.date ? Moment(props.date) : undefined,
|
|
20
|
+
);
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
22
|
+
useImperativeHandle(ref, () => ({
|
|
23
|
+
updateView: (nextDate, activeTab) => {
|
|
24
|
+
setDate(nextDate ? Moment(nextDate) : undefined);
|
|
25
|
+
setActive(activeTab);
|
|
26
|
+
},
|
|
27
|
+
setActiveTab: setActive,
|
|
28
|
+
}));
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
30
|
+
const weekday = (day: Moment.Moment) =>
|
|
31
|
+
translate?.(Util.WEEKDAYSFROMMOMENT[day.day()]);
|
|
32
|
+
const isHighlighted = active && !disabled;
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
date: date ? Moment(date) : undefined,
|
|
40
|
-
active: activeTab,
|
|
41
|
-
});
|
|
42
|
-
};
|
|
34
|
+
const formattedDate = date ? date.format('DD/MM/YYYY') : '';
|
|
35
|
+
const dayOfWeek = date ? `${weekday(date)}, ` : '';
|
|
43
36
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
return (
|
|
38
|
+
<TouchableWithoutFeedback
|
|
39
|
+
disabled={disabled}
|
|
40
|
+
onPress={() => onChangeTab?.(id)}
|
|
41
|
+
>
|
|
42
|
+
<View
|
|
43
|
+
style={[
|
|
44
|
+
styles.tabHeader,
|
|
45
|
+
isHighlighted && {
|
|
46
|
+
backgroundColor: theme.colors.background.surface,
|
|
47
|
+
},
|
|
48
|
+
]}
|
|
49
|
+
>
|
|
50
|
+
<Text
|
|
51
|
+
typography={'description_default_regular'}
|
|
52
|
+
color={theme.colors.text.hint}
|
|
53
|
+
>
|
|
54
|
+
{translate?.(label)}
|
|
55
|
+
</Text>
|
|
56
|
+
<Text typography={'header_s_semibold'}>
|
|
57
|
+
{`${dayOfWeek || '--'} `}
|
|
58
|
+
{formattedDate || '--/--/----'}
|
|
59
|
+
</Text>
|
|
60
|
+
</View>
|
|
61
|
+
</TouchableWithoutFeedback>
|
|
62
|
+
);
|
|
63
|
+
});
|
|
47
64
|
|
|
48
|
-
|
|
49
|
-
const {label, disabled} = this.props;
|
|
50
|
-
const {date, active} = this.state;
|
|
51
|
-
const {theme, translate} = this.context;
|
|
52
|
-
|
|
53
|
-
const formattedDateFromState = date ? date.format('DD/MM/YYYY') : '';
|
|
54
|
-
const formattedDateFromDefault = this.defaultDate
|
|
55
|
-
? this.defaultDate.format('DD/MM/YYYY')
|
|
56
|
-
: '';
|
|
57
|
-
const dayOfWeekFromState = date
|
|
58
|
-
? `${translate?.(Util.WEEKDAYSFROMMOMENT[date.day()])}, `
|
|
59
|
-
: '';
|
|
60
|
-
const dayOfWeekFromDefault = this.defaultDate
|
|
61
|
-
? `${translate?.(Util.WEEKDAYSFROMMOMENT[this.defaultDate.day()])},`
|
|
62
|
-
: '';
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<TouchableWithoutFeedback disabled={disabled} onPress={this.onChangeTab}>
|
|
66
|
-
<View
|
|
67
|
-
style={[
|
|
68
|
-
{
|
|
69
|
-
flex: 1,
|
|
70
|
-
padding: Spacing.S,
|
|
71
|
-
borderRadius: Radius.S,
|
|
72
|
-
},
|
|
73
|
-
active &&
|
|
74
|
-
!disabled && {
|
|
75
|
-
backgroundColor: theme.colors.background.surface,
|
|
76
|
-
},
|
|
77
|
-
]}>
|
|
78
|
-
<Text
|
|
79
|
-
typography={'description_default_regular'}
|
|
80
|
-
color={Colors.black_12}>
|
|
81
|
-
{translate?.(label)}
|
|
82
|
-
</Text>
|
|
83
|
-
<Text typography={'header_s_semibold'}>
|
|
84
|
-
{`${dayOfWeekFromState || dayOfWeekFromDefault || '--'} `}
|
|
85
|
-
{formattedDateFromState || formattedDateFromDefault || '--/--/----'}
|
|
86
|
-
</Text>
|
|
87
|
-
</View>
|
|
88
|
-
</TouchableWithoutFeedback>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
65
|
+
export default TabHeader;
|
package/Util.ts
CHANGED
|
@@ -3,50 +3,8 @@ import LunarDateConverter from './LunarDateConverter';
|
|
|
3
3
|
import holiday from './holidayData';
|
|
4
4
|
import {Holidays} from './types';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
w: ['', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
|
|
9
|
-
weekday: [
|
|
10
|
-
'',
|
|
11
|
-
'Monday',
|
|
12
|
-
'Tuesday',
|
|
13
|
-
'Wednesday',
|
|
14
|
-
'Thursday',
|
|
15
|
-
'Friday',
|
|
16
|
-
'Saturday',
|
|
17
|
-
'Sunday',
|
|
18
|
-
],
|
|
19
|
-
text: {
|
|
20
|
-
start: 'Start',
|
|
21
|
-
end: 'End',
|
|
22
|
-
date: 'Date',
|
|
23
|
-
save: 'Save',
|
|
24
|
-
clear: 'Reset',
|
|
25
|
-
},
|
|
26
|
-
date: 'DD / MM',
|
|
27
|
-
},
|
|
28
|
-
vi: {
|
|
29
|
-
w: ['', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'CN'],
|
|
30
|
-
weekday: [
|
|
31
|
-
'',
|
|
32
|
-
'Thứ hai',
|
|
33
|
-
'Thứ ba',
|
|
34
|
-
'Thứ tư',
|
|
35
|
-
'Thứ năm',
|
|
36
|
-
'Thứ sáu',
|
|
37
|
-
'Thứ bảy',
|
|
38
|
-
'Chủ nhật',
|
|
39
|
-
],
|
|
40
|
-
text: {
|
|
41
|
-
start: 'Start',
|
|
42
|
-
end: 'End',
|
|
43
|
-
date: 'Date',
|
|
44
|
-
save: 'Save',
|
|
45
|
-
clear: 'Reset',
|
|
46
|
-
},
|
|
47
|
-
date: 'DD / MM',
|
|
48
|
-
},
|
|
49
|
-
};
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const converter = new LunarDateConverter();
|
|
50
8
|
|
|
51
9
|
const Solar = (momentDate: moment.Moment) => ({
|
|
52
10
|
solarDay: momentDate.date(),
|
|
@@ -68,9 +26,7 @@ const groupHolidaysByDate = (
|
|
|
68
26
|
holidays.forEach(item => {
|
|
69
27
|
const {day, month, lunar, label} = item;
|
|
70
28
|
const key = formatDDMM(day, month);
|
|
71
|
-
let holidaysObj = groupedHolidays[key]
|
|
72
|
-
? {...groupedHolidays[key]}
|
|
73
|
-
: {...item};
|
|
29
|
+
let holidaysObj = { ...(groupedHolidays[key] || item) };
|
|
74
30
|
if (groupedHolidays[key]) {
|
|
75
31
|
if (holidaysObj.lunar && !lunar) {
|
|
76
32
|
holidaysObj = {
|
|
@@ -108,39 +64,8 @@ const sortByDate = (arr: Holidays[]): Holidays[] => {
|
|
|
108
64
|
};
|
|
109
65
|
|
|
110
66
|
const Utils = {
|
|
111
|
-
WEEKDAYS: ['T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'CN'],
|
|
112
|
-
|
|
113
67
|
WEEKDAYSFROMMOMENT: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
|
|
114
68
|
|
|
115
|
-
WEEKDAYSNAME: [
|
|
116
|
-
'Thứ 2',
|
|
117
|
-
'Thứ 3',
|
|
118
|
-
'Thứ 4',
|
|
119
|
-
'Thứ 5',
|
|
120
|
-
'Thứ 6',
|
|
121
|
-
'Thứ 7',
|
|
122
|
-
'Chủ nhật',
|
|
123
|
-
],
|
|
124
|
-
|
|
125
|
-
MONTHS: [
|
|
126
|
-
'Tháng 1',
|
|
127
|
-
'Tháng 2',
|
|
128
|
-
'Tháng 3',
|
|
129
|
-
'Tháng 4',
|
|
130
|
-
'Tháng 5',
|
|
131
|
-
'Tháng 6',
|
|
132
|
-
'Tháng 7',
|
|
133
|
-
'Tháng 8',
|
|
134
|
-
'Tháng 9',
|
|
135
|
-
'Tháng 10',
|
|
136
|
-
'Tháng 11',
|
|
137
|
-
'Tháng 12',
|
|
138
|
-
],
|
|
139
|
-
|
|
140
|
-
MAX_ROWS: 7,
|
|
141
|
-
|
|
142
|
-
MAX_COLUMNS: 7,
|
|
143
|
-
|
|
144
69
|
mapWeeKDate(i: number) {
|
|
145
70
|
const date = ['', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
146
71
|
return date[i];
|
|
@@ -164,45 +89,19 @@ const Utils = {
|
|
|
164
89
|
return month.get(i);
|
|
165
90
|
},
|
|
166
91
|
|
|
167
|
-
mapMonthShorten(i: number) {
|
|
168
|
-
const month = new Map([
|
|
169
|
-
[1, 'Jan'],
|
|
170
|
-
[2, 'Feb'],
|
|
171
|
-
[3, 'Mar'],
|
|
172
|
-
[4, 'Apr'],
|
|
173
|
-
[5, 'May'],
|
|
174
|
-
[6, 'Jun'],
|
|
175
|
-
[7, 'Jul'],
|
|
176
|
-
[8, 'Aug'],
|
|
177
|
-
[9, 'Sep'],
|
|
178
|
-
[10, 'Oct'],
|
|
179
|
-
[11, 'Nov'],
|
|
180
|
-
[12, 'Dec'],
|
|
181
|
-
]);
|
|
182
|
-
return month.get(i);
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
getDaysInMonth(month: number, year: number) {
|
|
186
|
-
const lastDayOfMonth = new Date(year, month + 1, 0);
|
|
187
|
-
return lastDayOfMonth.getDate();
|
|
188
|
-
},
|
|
189
|
-
|
|
190
92
|
/**
|
|
191
93
|
* Get sorted list of holidays within the given month.
|
|
192
94
|
*/
|
|
193
95
|
getHolidaysInMonth(headerInfo: moment.Moment): Holidays[] {
|
|
194
96
|
if (headerInfo) {
|
|
195
|
-
// @ts-ignore
|
|
196
|
-
const converter = new LunarDateConverter();
|
|
197
97
|
const startDate = moment(headerInfo).startOf('month');
|
|
198
98
|
const endDate = moment(headerInfo).endOf('month');
|
|
199
99
|
const minLunarDate = converter.SolarToLunar(Solar(startDate));
|
|
200
100
|
const maxLunarDate = converter.SolarToLunar(Solar(endDate));
|
|
201
101
|
const holidays: any[] = [];
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
: minLunarDate.lunarYear;
|
|
102
|
+
const minYear = minLunarDate.lunarYear;
|
|
103
|
+
const maxYear = maxLunarDate.lunarYear;
|
|
104
|
+
const currentYear = minYear !== maxYear ? [minYear, maxYear] : minYear;
|
|
206
105
|
|
|
207
106
|
// Handle Solar holidays
|
|
208
107
|
// @ts-ignore
|
|
@@ -282,7 +181,6 @@ const Utils = {
|
|
|
282
181
|
}
|
|
283
182
|
return [];
|
|
284
183
|
},
|
|
285
|
-
I18N_MAP,
|
|
286
184
|
};
|
|
287
185
|
|
|
288
186
|
export default Utils;
|
package/index.tsx
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
-
import React, {
|
|
3
|
-
useState,
|
|
4
|
-
useRef,
|
|
5
|
-
useEffect,
|
|
6
|
-
useContext,
|
|
7
|
-
createContext,
|
|
8
|
-
} from 'react';
|
|
2
|
+
import React, { useState, useRef, useEffect, useContext } from 'react';
|
|
9
3
|
import { Dimensions, LayoutChangeEvent, View } from 'react-native';
|
|
10
4
|
import moment from 'moment';
|
|
11
5
|
import {
|
|
@@ -13,20 +7,17 @@ import {
|
|
|
13
7
|
Radius,
|
|
14
8
|
useScaleSize,
|
|
15
9
|
Spacing,
|
|
16
|
-
Switch,
|
|
17
|
-
Text,
|
|
18
10
|
} from '@momo-kits/foundation';
|
|
19
11
|
import CalendarPro from './CalendarPro';
|
|
20
|
-
import
|
|
21
|
-
import { CalendarProps, CalendarProRef } from './types';
|
|
12
|
+
import { HeaderPanel, SwitchReturnSelection } from './CalendarHeader';
|
|
13
|
+
import { CalendarProps, CalendarProRef, TabHeaderRef } from './types';
|
|
14
|
+
import { ContainerContext } from './ContainerContext';
|
|
22
15
|
import styles from './styles';
|
|
23
16
|
|
|
24
17
|
const DOUBLE = 'doubleDate';
|
|
25
18
|
|
|
26
|
-
export const ContainerContext = createContext({ width: 0, height: 0 });
|
|
27
|
-
|
|
28
19
|
const Calendar: React.FC<CalendarProps> = props => {
|
|
29
|
-
const {
|
|
20
|
+
const { theme } = useContext(ApplicationContext);
|
|
30
21
|
const scaledHeight48 = useScaleSize(48);
|
|
31
22
|
const scaledHeight34 = useScaleSize(34);
|
|
32
23
|
|
|
@@ -49,9 +40,6 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
49
40
|
isHideHoliday,
|
|
50
41
|
isShowLunar,
|
|
51
42
|
priceList,
|
|
52
|
-
labelFrom,
|
|
53
|
-
labelTo,
|
|
54
|
-
isHideLabel,
|
|
55
43
|
minDate = minDateDefault,
|
|
56
44
|
maxDate = maxDateDefault,
|
|
57
45
|
style,
|
|
@@ -66,32 +54,28 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
66
54
|
const [isDoubleDateMode, setIsDoubleDateMode] = useState<boolean>(
|
|
67
55
|
mode === DOUBLE,
|
|
68
56
|
);
|
|
57
|
+
let initialDate = initialSelectedDate;
|
|
58
|
+
if (!initialDate && mode === DOUBLE) {
|
|
59
|
+
initialDate = initDoubleDate?.first;
|
|
60
|
+
}
|
|
69
61
|
const [selectedDate, setSelectedDate] = useState<moment.Moment>(
|
|
70
|
-
|
|
71
|
-
? moment(initialSelectedDate)
|
|
72
|
-
: mode === DOUBLE && initDoubleDate && initDoubleDate.first
|
|
73
|
-
? moment(initDoubleDate.first)
|
|
74
|
-
: moment(),
|
|
62
|
+
initialDate ? moment(initialDate) : moment(),
|
|
75
63
|
);
|
|
76
64
|
|
|
77
65
|
const doubleDate = useRef<{
|
|
78
66
|
first: moment.Moment | null;
|
|
79
67
|
second: moment.Moment | null;
|
|
80
|
-
}>(
|
|
81
|
-
initDoubleDate
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
second: initDoubleDate.second ? moment(initDoubleDate.second) : null,
|
|
85
|
-
}
|
|
86
|
-
: { first: null, second: null },
|
|
87
|
-
);
|
|
68
|
+
}>({
|
|
69
|
+
first: initDoubleDate?.first ? moment(initDoubleDate.first) : null,
|
|
70
|
+
second: initDoubleDate?.second ? moment(initDoubleDate.second) : null,
|
|
71
|
+
});
|
|
88
72
|
const tabSelected = useRef<number>(id || 0);
|
|
89
73
|
|
|
90
74
|
const calendarPicker = useRef<CalendarProRef>(null);
|
|
91
75
|
// hold refs to TabHeader instances
|
|
92
|
-
const cellHeader1 = useRef<
|
|
93
|
-
const cellHeader2 = useRef<
|
|
94
|
-
const cellHeaderSingle = useRef<
|
|
76
|
+
const cellHeader1 = useRef<TabHeaderRef>(null);
|
|
77
|
+
const cellHeader2 = useRef<TabHeaderRef>(null);
|
|
78
|
+
const cellHeaderSingle = useRef<TabHeaderRef>(null);
|
|
95
79
|
|
|
96
80
|
// Initialize view on mount
|
|
97
81
|
useEffect(() => {
|
|
@@ -120,11 +104,11 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
120
104
|
const onLayout = (e: LayoutChangeEvent) =>
|
|
121
105
|
setContainerWidth(e.nativeEvent.layout.width);
|
|
122
106
|
|
|
123
|
-
const onChangeTab = (
|
|
124
|
-
onChangeTabProp?.(
|
|
125
|
-
tabSelected.current =
|
|
126
|
-
cellHeader1.current?.setActiveTab(
|
|
127
|
-
cellHeader2.current?.setActiveTab(
|
|
107
|
+
const onChangeTab = (tabId: number) => {
|
|
108
|
+
onChangeTabProp?.(tabId);
|
|
109
|
+
tabSelected.current = tabId;
|
|
110
|
+
cellHeader1.current?.setActiveTab(tabId === 0);
|
|
111
|
+
cellHeader2.current?.setActiveTab(tabId === 1);
|
|
128
112
|
calendarPicker.current?.setDoubleDateAndTabIndex(
|
|
129
113
|
doubleDate.current.first,
|
|
130
114
|
doubleDate.current.second,
|
|
@@ -221,18 +205,11 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
221
205
|
const updateHeaderView = () => {
|
|
222
206
|
const { onDateChange, onCTAStateChange } = props;
|
|
223
207
|
if (isDoubleDateMode) {
|
|
224
|
-
cellHeader1.current?.updateView(selectedDate, true);
|
|
225
|
-
cellHeader2.current?.updateView(null, false);
|
|
226
|
-
calendarPicker.current?.setDoubleDateAndTabIndex(
|
|
227
|
-
selectedDate,
|
|
228
|
-
null,
|
|
229
|
-
tabSelected.current,
|
|
230
|
-
);
|
|
231
208
|
doubleDate.current.first = moment(selectedDate);
|
|
232
209
|
doubleDate.current.second = null;
|
|
233
210
|
tabSelected.current = 1;
|
|
234
|
-
|
|
235
|
-
|
|
211
|
+
cellHeader1.current?.updateView(selectedDate, false);
|
|
212
|
+
cellHeader2.current?.updateView(null, true);
|
|
236
213
|
calendarPicker.current?.setDoubleDateAndTabIndex(
|
|
237
214
|
doubleDate.current.first,
|
|
238
215
|
doubleDate.current.second,
|
|
@@ -241,16 +218,17 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
241
218
|
onCTAStateChange?.(false);
|
|
242
219
|
onDateChange?.({ first: doubleDate.current.first!, second: null });
|
|
243
220
|
} else {
|
|
244
|
-
|
|
221
|
+
const date = doubleDate.current.first ?? selectedDate;
|
|
245
222
|
doubleDate.current.second = null;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
223
|
+
tabSelected.current = 0;
|
|
224
|
+
calendarPicker.current?.setDoubleDateAndTabIndex(date, null, 0);
|
|
225
|
+
onCTAStateChange?.(true);
|
|
226
|
+
if (date.isSame(selectedDate, 'day')) {
|
|
227
|
+
cellHeaderSingle.current?.updateView(date, true);
|
|
228
|
+
onDateChange?.(date.toDate());
|
|
250
229
|
} else {
|
|
251
|
-
|
|
230
|
+
setSelectedDate(date);
|
|
252
231
|
}
|
|
253
|
-
props.onDateChange?.(selectedDate.toDate());
|
|
254
232
|
}
|
|
255
233
|
};
|
|
256
234
|
|
|
@@ -271,69 +249,6 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
271
249
|
}
|
|
272
250
|
}, [isDoubleDateMode]);
|
|
273
251
|
|
|
274
|
-
const renderSwitchReturnSelection = () => {
|
|
275
|
-
if (props.hideSwitchReturnSelection) return null;
|
|
276
|
-
return (
|
|
277
|
-
<View style={styles.headerContainer}>
|
|
278
|
-
<View
|
|
279
|
-
style={[
|
|
280
|
-
styles.viewSwitch,
|
|
281
|
-
{ backgroundColor: theme.colors.background.surface },
|
|
282
|
-
]}
|
|
283
|
-
>
|
|
284
|
-
<Text typography="label_default_medium">
|
|
285
|
-
{props.titleHeader || translate?.('chooseRoundtrip')}
|
|
286
|
-
</Text>
|
|
287
|
-
<Switch value={isDoubleDateMode} onChange={toggleSelectionDateMode} />
|
|
288
|
-
</View>
|
|
289
|
-
</View>
|
|
290
|
-
);
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
const renderHeaderPanel = () =>
|
|
294
|
-
isDoubleDateMode ? (
|
|
295
|
-
<View
|
|
296
|
-
style={[
|
|
297
|
-
styles.viewPanel,
|
|
298
|
-
{ backgroundColor: theme.colors.background.default },
|
|
299
|
-
]}
|
|
300
|
-
>
|
|
301
|
-
<TabHeader
|
|
302
|
-
id={0}
|
|
303
|
-
ref={cellHeader1}
|
|
304
|
-
onChangeTab={onChangeTab}
|
|
305
|
-
label={props.headerFrom || 'depart'}
|
|
306
|
-
activeTab
|
|
307
|
-
date={doubleDate.current.first}
|
|
308
|
-
/>
|
|
309
|
-
<View style={{ width: 4, height: '100%' }} />
|
|
310
|
-
<TabHeader
|
|
311
|
-
id={1}
|
|
312
|
-
ref={cellHeader2}
|
|
313
|
-
onChangeTab={onChangeTab}
|
|
314
|
-
label={props.headerTo || 'return'}
|
|
315
|
-
activeTab={false}
|
|
316
|
-
date={doubleDate.current.second}
|
|
317
|
-
/>
|
|
318
|
-
</View>
|
|
319
|
-
) : (
|
|
320
|
-
<View
|
|
321
|
-
style={[
|
|
322
|
-
styles.viewPanel,
|
|
323
|
-
{ backgroundColor: theme.colors.background.default },
|
|
324
|
-
]}
|
|
325
|
-
>
|
|
326
|
-
<TabHeader
|
|
327
|
-
id={0}
|
|
328
|
-
disabled
|
|
329
|
-
ref={cellHeaderSingle}
|
|
330
|
-
label={props.headerFrom || 'depart'}
|
|
331
|
-
activeTab
|
|
332
|
-
date={selectedDate}
|
|
333
|
-
/>
|
|
334
|
-
</View>
|
|
335
|
-
);
|
|
336
|
-
|
|
337
252
|
return (
|
|
338
253
|
<ContainerContext.Provider
|
|
339
254
|
value={{
|
|
@@ -352,8 +267,24 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
352
267
|
hideHeaderTab && styles.invisible,
|
|
353
268
|
]}
|
|
354
269
|
>
|
|
355
|
-
|
|
356
|
-
|
|
270
|
+
<SwitchReturnSelection
|
|
271
|
+
hidden={props.hideSwitchReturnSelection}
|
|
272
|
+
title={props.titleHeader}
|
|
273
|
+
value={isDoubleDateMode}
|
|
274
|
+
onChange={toggleSelectionDateMode}
|
|
275
|
+
/>
|
|
276
|
+
<HeaderPanel
|
|
277
|
+
isDoubleDateMode={isDoubleDateMode}
|
|
278
|
+
cellHeader1={cellHeader1}
|
|
279
|
+
cellHeader2={cellHeader2}
|
|
280
|
+
cellHeaderSingle={cellHeaderSingle}
|
|
281
|
+
onChangeTab={onChangeTab}
|
|
282
|
+
headerFrom={props.headerFrom}
|
|
283
|
+
headerTo={props.headerTo}
|
|
284
|
+
firstDate={doubleDate.current.first}
|
|
285
|
+
secondDate={doubleDate.current.second}
|
|
286
|
+
selectedDate={selectedDate}
|
|
287
|
+
/>
|
|
357
288
|
</View>
|
|
358
289
|
<CalendarPro
|
|
359
290
|
priceList={priceList}
|
|
@@ -365,9 +296,6 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
365
296
|
selectedDate={selectedDate}
|
|
366
297
|
isShowLunar={isShowLunar}
|
|
367
298
|
onCallbackCalendar={onCallbackCalendar}
|
|
368
|
-
labelFrom={labelFrom}
|
|
369
|
-
labelTo={labelTo}
|
|
370
|
-
isHideLabel={isHideLabel}
|
|
371
299
|
minDate={minDate}
|
|
372
300
|
maxDate={maxDate}
|
|
373
301
|
isHideHoliday={isHideHoliday}
|
|
@@ -380,4 +308,4 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
380
308
|
);
|
|
381
309
|
};
|
|
382
310
|
|
|
383
|
-
export { Calendar };
|
|
311
|
+
export { Calendar, ContainerContext };
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
2
|
+
"name": "@momo-kits/calendar",
|
|
3
|
+
"version": "0.167.1-rc.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"@momo-kits/foundation": "latest",
|
|
8
|
+
"react": "*",
|
|
9
|
+
"react-native": "*"
|
|
10
|
+
},
|
|
11
|
+
"license": "MoMo",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"moment": "^2.24.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/styles.ts
CHANGED
|
@@ -16,6 +16,10 @@ export default StyleSheet.create({
|
|
|
16
16
|
alignItems: 'center',
|
|
17
17
|
marginBottom: Spacing.XS,
|
|
18
18
|
},
|
|
19
|
+
tabGap: {
|
|
20
|
+
width: Spacing.XS,
|
|
21
|
+
height: '100%',
|
|
22
|
+
},
|
|
19
23
|
headerContainer: {
|
|
20
24
|
paddingHorizontal: Spacing.M,
|
|
21
25
|
marginTop: Spacing.S,
|
|
@@ -57,7 +61,6 @@ export default StyleSheet.create({
|
|
|
57
61
|
marginTop: Spacing.S,
|
|
58
62
|
},
|
|
59
63
|
container: {
|
|
60
|
-
backgroundColor: 'white',
|
|
61
64
|
borderRadius: Radius.XS,
|
|
62
65
|
},
|
|
63
66
|
blueSeperator: {
|
|
@@ -70,18 +73,6 @@ export default StyleSheet.create({
|
|
|
70
73
|
txtHeader: {
|
|
71
74
|
textAlign: 'center',
|
|
72
75
|
},
|
|
73
|
-
btnRight: {
|
|
74
|
-
width: 36,
|
|
75
|
-
height: 36,
|
|
76
|
-
justifyContent: 'center',
|
|
77
|
-
alignItems: 'center',
|
|
78
|
-
},
|
|
79
|
-
btnLeft: {
|
|
80
|
-
width: 36,
|
|
81
|
-
height: 36,
|
|
82
|
-
justifyContent: 'center',
|
|
83
|
-
alignItems: 'center',
|
|
84
|
-
},
|
|
85
76
|
headerControlContainer: {
|
|
86
77
|
flexDirection: 'row',
|
|
87
78
|
justifyContent: 'space-between',
|
|
@@ -101,9 +92,6 @@ export default StyleSheet.create({
|
|
|
101
92
|
alignItems: 'center',
|
|
102
93
|
borderRadius: Radius.XS,
|
|
103
94
|
},
|
|
104
|
-
dayText: {
|
|
105
|
-
textAlign: 'center',
|
|
106
|
-
},
|
|
107
95
|
dayStartContainer: {
|
|
108
96
|
borderTopLeftRadius: Radius.XS,
|
|
109
97
|
borderBottomLeftRadius: Radius.XS,
|
|
@@ -119,4 +107,22 @@ export default StyleSheet.create({
|
|
|
119
107
|
marginBottom: 0,
|
|
120
108
|
overflow: 'hidden',
|
|
121
109
|
},
|
|
110
|
+
lunarText: {
|
|
111
|
+
position: 'absolute',
|
|
112
|
+
},
|
|
113
|
+
monthRows: {
|
|
114
|
+
paddingHorizontal: Spacing.S,
|
|
115
|
+
width: '100%',
|
|
116
|
+
alignItems: 'center',
|
|
117
|
+
},
|
|
118
|
+
monthRow: {
|
|
119
|
+
flexDirection: 'row',
|
|
120
|
+
alignItems: 'center',
|
|
121
|
+
marginBottom: Spacing.XS,
|
|
122
|
+
},
|
|
123
|
+
tabHeader: {
|
|
124
|
+
flex: 1,
|
|
125
|
+
padding: Spacing.S,
|
|
126
|
+
borderRadius: Radius.S,
|
|
127
|
+
},
|
|
122
128
|
});
|