@momo-kits/calendar 0.0.74-beta → 0.72.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/src/Day/index.js CHANGED
@@ -1,193 +1,233 @@
1
- import React, { Component } from 'react';
2
- import PropTypes from 'prop-types';
1
+ import React, {Component} from 'react';
3
2
 
4
- import {
5
- View,
6
- TouchableHighlight,
7
- Text
8
- } from 'react-native';
9
- import { Colors, SwitchLanguage } from '@momo-kits/core';
3
+ import {TouchableHighlight, View} from 'react-native';
4
+ import {Colors, Spacing, Text} from '@momo-kits/core-v2';
10
5
  import style from './style';
11
6
 
12
7
  class Day extends Component {
13
- constructor(props) {
14
- super(props);
15
- this.statusCheck();
16
- }
17
-
18
- chooseDay = () => {
19
- const { onChoose, date } = this.props;
20
- onChoose && onChoose(date);
21
- };
8
+ constructor(props) {
9
+ super(props);
10
+ this.statusCheck();
11
+ }
22
12
 
23
- findHoliday = (date, holidays) => {
24
- if (date && holidays && holidays.length > 0) {
25
- const day = date.date();
26
- const month = date.month() + 1;
27
- return holidays.find((item) => item.day === day && item.month === month);
28
- }
29
- return null;
30
- };
13
+ chooseDay = () => {
14
+ const {onChoose, date} = this.props;
15
+ onChoose && onChoose(date);
16
+ };
31
17
 
32
- checkHoliday = (date, holidays) => {
33
- const holiday = this.findHoliday(date, holidays);
34
- return {
35
- solarHoliday: !!(holiday && !holiday.lunar),
36
- lunarHoliday: !!(holiday && holiday.lunar)
37
- };
38
- };
18
+ findHoliday = (date, holidays) => {
19
+ if (date && holidays && holidays.length > 0) {
20
+ const day = date.date();
21
+ const month = date.month() + 1;
22
+ return holidays.find(item => item.day === day && item.month === month);
23
+ }
24
+ return null;
25
+ };
39
26
 
40
- statusCheck = (props) => {
41
- const {
42
- startDate,
43
- endDate,
44
- date = null,
45
- minDate,
46
- maxDate,
47
- empty,
48
- index,
49
- isShowLunar,
50
- tabSelected,
51
- isDoubleDateMode,
52
- lunarDate,
53
- isSolarHoliday,
54
- isLunarHoliday,
55
- price
56
- } = props || this.props;
57
- this.isValid = date && (date >= minDate || date.isSame(minDate, 'day')) && (date <= maxDate || date.isSame(maxDate, 'day'));
58
- this.isMid = isDoubleDateMode && date > startDate && date < endDate
59
- || (!date && empty >= startDate && empty <= endDate);
60
- this.isStart = date && date.isSame(startDate, 'd');
61
- this.isStartPart = this.isStart && endDate;
62
- this.isEnd = isDoubleDateMode && date && date.isSame(endDate, 'day');
63
- this.isFocus = this.isMid || this.isStart || this.isEnd;
64
- this.isWeekEnd = index === 6 || index === 5;
65
- this.showLunar = isShowLunar;
66
- this.lunarDate = lunarDate;
67
- this.isDoubleDateMode = isDoubleDateMode;
68
- this.isLunarHoliday = isLunarHoliday;
69
- this.isLunarDayStart = this.lunarDate && this.lunarDate.lunarDay === 1;
70
- this.isSolarHoliday = isSolarHoliday;
71
- this.isInScope = isDoubleDateMode ? (tabSelected === 0 || (tabSelected === 1 && startDate && date && date.isSameOrAfter(startDate, 'day'))) : true;
72
- return this.isFocus || this.diffPrice;
27
+ checkHoliday = (date, holidays) => {
28
+ const holiday = this.findHoliday(date, holidays);
29
+ return {
30
+ solarHoliday: !!(holiday && !holiday.lunar),
31
+ lunarHoliday: !!(holiday && holiday.lunar),
73
32
  };
33
+ };
74
34
 
75
- shouldComponentUpdate(nextProps) {
76
- const {
77
- isDoubleDateMode, isShowLunar, tabSelected, isSolarHoliday,
78
- isLunarHoliday,
79
- price,
80
- isBestPrice,
81
- startDate,
82
- endDate
83
- } = this.props;
84
- const prevStatus = this.isFocus;
85
- const selectionModeChange = isDoubleDateMode !== nextProps.isDoubleDateMode;
86
- const lunarChange = isShowLunar !== nextProps.isShowLunar;
87
- const nextStatus = this.statusCheck(nextProps);
88
- const tabChange = tabSelected !== nextProps.tabSelected;
89
- const solarHoliday = isSolarHoliday !== nextProps.isSolarHoliday;
90
- const lunarHoliday = isLunarHoliday !== nextProps.isLunarHoliday;
91
- const diffPrice = price !== nextProps.price && isBestPrice !== nextProps.isBestPrice;
92
- const startDateChange = startDate && !startDate?.isSame?.(nextProps.startDate, 'day');
93
- const endDateChange = endDate && !endDate?.isSame?.(nextProps.endDate, 'day');
94
- return !!(prevStatus !== nextStatus || selectionModeChange || lunarChange || tabChange || solarHoliday || lunarHoliday || diffPrice || startDateChange || endDateChange);
95
- }
35
+ statusCheck = props => {
36
+ const {
37
+ startDate,
38
+ endDate,
39
+ date = null,
40
+ minDate,
41
+ maxDate,
42
+ empty,
43
+ index,
44
+ isShowLunar,
45
+ isDoubleDateMode,
46
+ lunarDate,
47
+ isSolarHoliday,
48
+ isLunarHoliday,
49
+ } = props || this.props;
50
+ this.isValid =
51
+ date &&
52
+ (date >= minDate || date.isSame(minDate, 'day')) &&
53
+ (date <= maxDate || date.isSame(maxDate, 'day'));
54
+ this.isMid =
55
+ (isDoubleDateMode && date > startDate && date < endDate) ||
56
+ (!date && empty >= startDate && empty <= endDate);
57
+ this.isStart = date && date.isSame(startDate, 'd');
58
+ this.isStartPart = this.isStart && endDate;
59
+ this.isEnd = isDoubleDateMode && date && date.isSame(endDate, 'day');
60
+ this.isFocus = this.isMid || this.isStart || this.isEnd;
61
+ this.isWeekEnd = index === 6 || index === 5;
62
+ this.showLunar = isShowLunar;
63
+ this.lunarDate = lunarDate;
64
+ this.isDoubleDateMode = isDoubleDateMode;
65
+ this.isLunarHoliday = isLunarHoliday;
66
+ this.isLunarDayStart = this.lunarDate && this.lunarDate.lunarDay === 1;
67
+ this.isSolarHoliday = isSolarHoliday;
68
+ this.isInScope = true;
69
+ return this.isFocus || this.diffPrice;
70
+ };
96
71
 
97
- render() {
98
- const {
99
- date, empty, isDoubleDateMode, price, isBestPrice, isShowPrice, labelFrom, labelTo, isHideLabel
100
- } = this.props;
101
- const text = date ? date.date() : '';
102
- return (
103
- <View style={style.dayContainer}>
104
- <View style={[
105
- this.isMid && !empty && style.mid,
106
- this.isStartPart && style.dayStartContainer,
107
- this.isEnd && style.dayEndContainer
72
+ shouldComponentUpdate(nextProps) {
73
+ const {
74
+ isDoubleDateMode,
75
+ isShowLunar,
76
+ tabSelected,
77
+ isSolarHoliday,
78
+ isLunarHoliday,
79
+ price,
80
+ isBestPrice,
81
+ startDate,
82
+ endDate,
83
+ } = this.props;
84
+ const prevStatus = this.isFocus;
85
+ const selectionModeChange = isDoubleDateMode !== nextProps.isDoubleDateMode;
86
+ const lunarChange = isShowLunar !== nextProps.isShowLunar;
87
+ const nextStatus = this.statusCheck(nextProps);
88
+ const tabChange = tabSelected !== nextProps.tabSelected;
89
+ const solarHoliday = isSolarHoliday !== nextProps.isSolarHoliday;
90
+ const lunarHoliday = isLunarHoliday !== nextProps.isLunarHoliday;
91
+ const diffPrice =
92
+ price !== nextProps.price && isBestPrice !== nextProps.isBestPrice;
93
+ const startDateChange =
94
+ startDate && !startDate?.isSame?.(nextProps.startDate, 'day');
95
+ const endDateChange =
96
+ endDate && !endDate?.isSame?.(nextProps.endDate, 'day');
97
+ return !!(
98
+ prevStatus !== nextStatus ||
99
+ selectionModeChange ||
100
+ lunarChange ||
101
+ tabChange ||
102
+ solarHoliday ||
103
+ lunarHoliday ||
104
+ diffPrice ||
105
+ startDateChange ||
106
+ endDateChange
107
+ );
108
+ }
108
109
 
109
- ]}
110
- >
111
- {this.isValid && this.isInScope
112
- ? (
113
- <TouchableHighlight
114
- style={[
115
- style.day,
116
- (this.isStart || this.isEnd) && style.focused
117
- ]}
118
- underlayColor="rgba(255, 255, 255, 0.35)"
119
- onPress={this.chooseDay}
120
- >
121
- <>
122
- <Text style={[
123
- style.dayText,
124
- this.isWeekEnd && style.weekendDay,
125
- this.isSolarHoliday && style.weekendDay,
126
- (this.isStart || this.isEnd) && style.focusedText,
127
- ]}
128
- >
129
- {text}
130
- </Text>
131
- {
132
- this.lunarDate && this.showLunar && (
133
- <Text style={[
134
- style.lunarDayText,
135
- (this.isLunarHoliday || this.isLunarDayStart) && style.weekendDay,
136
- (this.isStart || this.isEnd) && style.focusedText,
137
- ]}
138
- >
139
- {this.lunarDate.lunarDay === 1 ? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}` : this.lunarDate.lunarDay}
140
- </Text>
141
- )
142
- }
143
- </>
144
- </TouchableHighlight>
145
- )
146
- : (
147
- <View style={[style.day]}>
148
- <Text style={[
149
- style.dayText,
150
- style.dayTextDisabled,
151
- ]}
152
- >
153
- {text}
154
- </Text>
155
- {
156
- this.lunarDate && this.showLunar && text ? (
157
- <Text style={[
158
- style.lunarDayText,
159
- style.dayTextDisabled,
160
- ]}
161
- >
162
- {this.lunarDate.lunarDay === 1 ? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}` : this.lunarDate.lunarDay}
163
- </Text>
164
- ) : <View />
165
- }
166
- </View>
167
- )}
168
- </View>
110
+ render() {
111
+ const {date, empty, price, isBestPrice, disabledWeekend} = this.props;
169
112
 
170
- {(isDoubleDateMode && this.isStart && !isHideLabel) && (
171
- <View style={style.txtGo}>
172
- <Text style={{ fontSize: 8, color: 'white' }}>
173
- {labelFrom || SwitchLanguage.departing}
174
- </Text>
175
- </View>
113
+ const text = date ? date.date() : '';
114
+ return (
115
+ <View style={style.dayContainer}>
116
+ <View
117
+ style={[
118
+ this.isMid && !empty && style.mid,
119
+ this.isStartPart && style.dayStartContainer,
120
+ this.isEnd && style.dayEndContainer,
121
+ ]}>
122
+ {this.isValid && this.isInScope ? (
123
+ <TouchableHighlight
124
+ disabled={disabledWeekend && this.isWeekEnd}
125
+ style={[
126
+ style.day,
127
+ {
128
+ paddingVertical: !!price ? Spacing.XS : Spacing.S,
129
+ },
130
+ (this.isStart || this.isEnd) && style.focused,
131
+ ]}
132
+ underlayColor="rgba(255, 255, 255, 0.35)"
133
+ onPress={this.chooseDay}>
134
+ <>
135
+ {this.lunarDate && this.showLunar && (
136
+ <Text.Label4
137
+ style={[
138
+ style.lunarDayText,
139
+ (this.isLunarHoliday || this.isLunarDayStart) &&
140
+ style.weekendDay,
141
+ (this.isStart || this.isEnd) && style.focusedText,
142
+ ]}>
143
+ {this.lunarDate.lunarDay === 1
144
+ ? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
145
+ : this.lunarDate.lunarDay}
146
+ </Text.Label4>
176
147
  )}
177
- {(isDoubleDateMode && this.isEnd && !isHideLabel) && (
178
- <View style={style.txtBack}>
179
- <Text style={{ fontSize: 8, color: 'white' }}>
180
- {labelTo || SwitchLanguage.returning}
181
- </Text>
182
- </View>
148
+ <Text.Label1
149
+ style={[
150
+ style.dayText,
151
+ {paddingTop: !!price ? 4 : 0},
152
+ this.isWeekEnd && style.weekendDay,
153
+ this.isSolarHoliday && style.weekendDay,
154
+ (this.isStart || this.isEnd) && style.focusedText,
155
+ this.isWeekEnd && disabledWeekend && style.disabledWeekend,
156
+ ]}>
157
+ {text}
158
+ </Text.Label1>
159
+ {!!price ? (
160
+ <Text.Label3
161
+ style={[
162
+ this.isValid && this.isInScope
163
+ ? style.price
164
+ : style.dayTextDisabled,
165
+ isBestPrice && {
166
+ color: Colors.pink_03,
167
+ },
168
+ (this.isStart || this.isEnd) && {
169
+ color: Colors.black_01,
170
+ },
171
+ ]}>
172
+ {price}
173
+ </Text.Label3>
174
+ ) : (
175
+ <View
176
+ style={{
177
+ paddingBottom: this.props.havePriceList ? Spacing.S : 0,
178
+ }}
179
+ />
183
180
  )}
184
- {this.isValid
185
- && this.isInScope
186
- && !!(price)
187
- && <Text style={[style.price, isBestPrice && { color: Colors.pink_05_b }]}>{price}</Text>}
181
+ </>
182
+ </TouchableHighlight>
183
+ ) : (
184
+ <View
185
+ style={[
186
+ style.day,
187
+ {
188
+ paddingVertical: !!price
189
+ ? Spacing.XS + Spacing.XXS
190
+ : Spacing.S,
191
+ },
192
+ ]}>
193
+ {this.lunarDate && this.showLunar && text ? (
194
+ <Text.Label4
195
+ style={[style.lunarDayText, style.dayTextDisabled]}>
196
+ {this.lunarDate.lunarDay === 1
197
+ ? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
198
+ : this.lunarDate.lunarDay}
199
+ </Text.Label4>
200
+ ) : (
201
+ <View />
202
+ )}
203
+ <Text.Action2 style={[style.dayText, style.dayTextDisabled]}>
204
+ {text}
205
+ </Text.Action2>
206
+ {text && !!price ? (
207
+ <Text.Label3
208
+ style={[
209
+ this.isValid && this.isInScope
210
+ ? style.price
211
+ : style.dayTextDisabled,
212
+ isBestPrice && {
213
+ color: Colors.pink_03,
214
+ },
215
+ ]}>
216
+ {price}
217
+ </Text.Label3>
218
+ ) : (
219
+ <View
220
+ style={{
221
+ paddingBottom: this.props.havePriceList ? Spacing.S : 0,
222
+ }}
223
+ />
224
+ )}
188
225
  </View>
189
- );
190
- }
226
+ )}
227
+ </View>
228
+ </View>
229
+ );
230
+ }
191
231
  }
192
232
 
193
233
  export default Day;
package/src/Day/style.js CHANGED
@@ -1,9 +1,9 @@
1
- import { Dimensions } from 'react-native';
2
- import { Colors } from '@momo-kits/core';
1
+ import {Dimensions} from 'react-native';
2
+ import {Spacing, Colors} from '@momo-kits/core-v2';
3
3
 
4
4
  const dayWidth = (Dimensions.get('window').width - 38) / 7;
5
5
  const SCREEN_WIDTH = Dimensions.get('window').width;
6
- const SCREEN_DPI_WIDTH = (SCREEN_WIDTH * Dimensions.get('window').scale);
6
+ const SCREEN_DPI_WIDTH = SCREEN_WIDTH * Dimensions.get('window').scale;
7
7
  const IPHONE_4_5_WIDTH = 640;
8
8
  const dayTextSize = SCREEN_DPI_WIDTH === IPHONE_4_5_WIDTH ? 13 : 15;
9
9
  const lunarTextSize = SCREEN_DPI_WIDTH === IPHONE_4_5_WIDTH ? 8 : 10;
@@ -11,119 +11,117 @@ const priceTextSize = SCREEN_DPI_WIDTH === IPHONE_4_5_WIDTH ? 8 : 10;
11
11
  const lineHeightDayText = 1.3 * dayTextSize;
12
12
  const lineHeightLunarText = 1.3 * lunarTextSize;
13
13
  const lineHeightPriceText = 1.3 * priceTextSize;
14
- const containerDayHeight = lineHeightDayText + lineHeightLunarText + lineHeightPriceText + 10;
14
+ const containerDayHeight =
15
+ lineHeightDayText + lineHeightLunarText + lineHeightPriceText + 10;
15
16
  const heightDefault = lineHeightDayText + lineHeightLunarText;
16
17
  export default {
17
- dayContainer: {
18
- width: dayWidth,
19
- borderRadius: 4,
20
- alignItems: 'center',
21
- height: containerDayHeight,
22
- },
23
- day: {
24
- width: dayWidth,
25
- paddingVertical: 5,
26
- overflow: 'hidden',
27
- justifyContent: 'center',
28
- alignItems: 'center',
29
- borderRadius: 4,
30
- height: heightDefault + 5
31
- },
32
- dayText: {
33
- fontSize: dayTextSize,
34
- textAlign: 'center',
35
- fontWeight: 'bold',
36
- color: '#222222'
37
- },
38
- lunarDayText: {
39
- width: dayWidth,
40
- textAlign: 'right',
41
- fontSize: SCREEN_DPI_WIDTH === IPHONE_4_5_WIDTH ? 8 : 10,
42
- paddingRight: 5,
43
- color: '#222222'
44
- },
45
- todayText: {
46
- color: 'blue'
47
- },
48
- weekendDay: {
49
- color: '#e82956'
50
- },
51
- dayTextDisabled: {
52
- opacity: 0.2
53
- },
54
- focused: {
55
- backgroundColor: Colors.pink_05_b
56
- },
57
- focusedText: {
58
- color: 'white'
59
- },
60
- dayStartContainer: {
61
- borderTopLeftRadius: 4,
62
- borderBottomLeftRadius: 4,
63
- backgroundColor: Colors.pink_09,
64
- // height: heightDefault
65
- },
66
- dayEndContainer: {
67
- borderTopRightRadius: 4,
68
- borderBottomRightRadius: 4,
69
- backgroundColor: Colors.pink_09,
70
- // height: heightDefault
71
- },
72
- mid: {
73
- backgroundColor: Colors.pink_09,
74
- // height: heightDefault
75
- },
76
- departLabel: {
77
- position: 'absolute',
78
- backgroundColor: 'yellow',
79
- width: 20,
80
- height: 20,
81
- borderRadius: 10,
82
- justifyContent: 'center',
83
- alignItems: 'center'
84
- },
85
- returnLabel: {
86
- position: 'absolute',
87
- backgroundColor: 'yellow',
88
- width: 20,
89
- height: 20,
90
- borderRadius: 10,
91
- justifyContent: 'center',
92
- alignItems: 'center',
93
- top: 0,
94
- right: 0
95
- },
96
- containerDayHeight,
97
- txtBack: {
98
- position: 'absolute',
99
- backgroundColor: '#ffbb1e',
100
- borderRadius: 100,
101
- top: -2,
102
- right: -2,
103
- zIndex: 999,
104
- padding: 2,
105
- width: 15,
106
- height: 15,
107
- justifyContent: 'center',
108
- alignItems: 'center'
109
- },
110
- txtGo: {
111
- position: 'absolute',
112
- backgroundColor: '#ffbb1e',
113
- top: -2,
114
- left: -2,
115
- borderRadius: 100,
116
- padding: 2,
117
- zIndex: 999,
118
- width: 15,
119
- height: 15,
120
- justifyContent: 'center',
121
- alignItems: 'center'
122
- },
123
- price: {
124
- fontSize: priceTextSize,
125
- lineHeight: lineHeightPriceText,
126
- color: '#8d919d'
127
- },
128
- lineHeightPriceText
18
+ dayContainer: {
19
+ width: dayWidth,
20
+ borderRadius: 4,
21
+ alignItems: 'center',
22
+ height: containerDayHeight,
23
+ },
24
+ disabledWeekend: {color: Colors.red_07},
25
+ day: {
26
+ width: dayWidth,
27
+ overflow: 'hidden',
28
+ justifyContent: 'center',
29
+ alignItems: 'center',
30
+ borderRadius: 4,
31
+ },
32
+ dayText: {
33
+ textAlign: 'center',
34
+ },
35
+ lunarDayText: {
36
+ width: dayWidth,
37
+ textAlign: 'right',
38
+ paddingRight: Spacing.XS,
39
+ position: 'absolute',
40
+ top: Spacing.XXS,
41
+ color: Colors.black_12,
42
+ },
43
+ todayText: {
44
+ color: 'blue',
45
+ },
46
+ weekendDay: {
47
+ color: Colors.red_05,
48
+ },
49
+ dayTextDisabled: {
50
+ opacity: 0.4,
51
+ },
52
+
53
+ focused: {
54
+ backgroundColor: Colors.pink_03,
55
+ },
56
+ focusedText: {
57
+ fontWeight: 'bold',
58
+ color: 'white',
59
+ },
60
+ dayStartContainer: {
61
+ borderTopLeftRadius: 4,
62
+ borderBottomLeftRadius: 4,
63
+ backgroundColor: Colors.pink_03,
64
+ },
65
+ dayEndContainer: {
66
+ borderTopRightRadius: 4,
67
+ borderBottomRightRadius: 4,
68
+ backgroundColor: Colors.pink_03,
69
+ },
70
+ mid: {
71
+ backgroundColor: Colors.pink_09,
72
+ // height: heightDefault
73
+ },
74
+ departLabel: {
75
+ position: 'absolute',
76
+ backgroundColor: 'yellow',
77
+ width: 20,
78
+ height: 20,
79
+ borderRadius: 10,
80
+ justifyContent: 'center',
81
+ alignItems: 'center',
82
+ },
83
+ returnLabel: {
84
+ position: 'absolute',
85
+ backgroundColor: 'yellow',
86
+ width: 20,
87
+ height: 20,
88
+ borderRadius: 10,
89
+ justifyContent: 'center',
90
+ alignItems: 'center',
91
+ top: 0,
92
+ right: 0,
93
+ },
94
+ containerDayHeight,
95
+ txtBack: {
96
+ position: 'absolute',
97
+ backgroundColor: '#ffbb1e',
98
+ borderRadius: 100,
99
+ top: -2,
100
+ right: -2,
101
+ zIndex: 999,
102
+ padding: 2,
103
+ width: 15,
104
+ height: 15,
105
+ justifyContent: 'center',
106
+ alignItems: 'center',
107
+ },
108
+ txtGo: {
109
+ position: 'absolute',
110
+ backgroundColor: '#ffbb1e',
111
+ top: -2,
112
+ left: -2,
113
+ borderRadius: 100,
114
+ padding: 2,
115
+ zIndex: 999,
116
+ width: 15,
117
+ height: 15,
118
+ justifyContent: 'center',
119
+ alignItems: 'center',
120
+ },
121
+ price: {
122
+ color: Colors.black_15,
123
+ marginTop: -4,
124
+ lineHeight: 14,
125
+ },
126
+ lineHeightPriceText,
129
127
  };