@momo-kits/calendar 0.79.4 → 0.79.6

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.
@@ -1,10 +1,11 @@
1
1
  import React, {Component} from 'react';
2
2
 
3
3
  import {TouchableHighlight, View} from 'react-native';
4
- import {Colors, Spacing, Text} from '@momo-kits/core-v2';
4
+ import {ApplicationContext, Colors, Spacing, Text} from '@momo-kits/foundation';
5
5
  import style from './style';
6
6
 
7
7
  class Day extends Component {
8
+ static contextType = ApplicationContext;
8
9
  constructor(props) {
9
10
  super(props);
10
11
  this.statusCheck();
@@ -108,69 +109,81 @@ class Day extends Component {
108
109
  }
109
110
 
110
111
  render() {
111
- const {date, empty, price, isBestPrice, disabledWeekend} = this.props;
112
+ const {date, empty, price, isBestPrice, disabledWeekend, width} =
113
+ this.props;
114
+ const {theme, translate} = this.context;
112
115
 
113
116
  const text = date ? date.date() : '';
117
+ let textDayColor = theme.colors.text.default;
118
+ let lunarDayColor = theme.colors.text.hint;
119
+
120
+ if (this.isWeekEnd || this.isSolarHoliday || this.isWeekEnd) {
121
+ textDayColor = theme.colors.error.primary;
122
+ }
123
+
124
+ if (this.isStart || this.isEnd) {
125
+ textDayColor = Colors.black_01;
126
+ lunarDayColor = Colors.black_01;
127
+ }
128
+
129
+ if (this.isLunarHoliday || this.isLunarDayStart) {
130
+ lunarDayColor = theme.colors.error.primary;
131
+ }
132
+
114
133
  return (
115
- <View style={style.dayContainer}>
134
+ <View style={[style.dayContainer, {width, borderWidth: 1}]}>
116
135
  <View
117
136
  style={[
118
- this.isMid && !empty && style.mid,
137
+ this.isMid &&
138
+ !empty && {backgroundColor: theme.colors.background.tonal},
119
139
  this.isStartPart && style.dayStartContainer,
120
140
  this.isEnd && style.dayEndContainer,
121
141
  ]}>
122
142
  {this.isValid && this.isInScope ? (
123
143
  <TouchableHighlight
124
- disabled={disabledWeekend && this.isWeekEnd}
125
144
  style={[
126
145
  style.day,
127
146
  {
128
147
  paddingVertical: !!price ? Spacing.XS : Spacing.S,
129
148
  },
130
- (this.isStart || this.isEnd) && style.focused,
149
+ (this.isStart || this.isEnd) && {
150
+ backgroundColor: theme.colors.primary,
151
+ },
131
152
  ]}
132
153
  underlayColor="rgba(255, 255, 255, 0.35)"
133
154
  onPress={this.chooseDay}>
134
155
  <>
135
156
  {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
- ]}>
157
+ <Text
158
+ color={lunarDayColor}
159
+ typography={'label_xxs'}
160
+ style={style.lunarDayText}>
143
161
  {this.lunarDate.lunarDay === 1
144
162
  ? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
145
163
  : this.lunarDate.lunarDay}
146
- </Text.Label4>
164
+ </Text>
147
165
  )}
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
- ]}>
166
+ <Text
167
+ color={textDayColor}
168
+ typography={'header_s'}
169
+ style={[style.dayText, {paddingTop: !!price ? 4 : 0}]}>
157
170
  {text}
158
- </Text.Label1>
171
+ </Text>
159
172
  {!!price ? (
160
- <Text.Label3
173
+ <Text
161
174
  style={[
162
175
  this.isValid && this.isInScope
163
176
  ? style.price
164
177
  : style.dayTextDisabled,
165
178
  isBestPrice && {
166
- color: Colors.pink_03,
179
+ color: theme.colors.primary,
167
180
  },
168
181
  (this.isStart || this.isEnd) && {
169
182
  color: Colors.black_01,
170
183
  },
171
184
  ]}>
172
185
  {price}
173
- </Text.Label3>
186
+ </Text>
174
187
  ) : (
175
188
  <View
176
189
  style={{
@@ -191,30 +204,32 @@ class Day extends Component {
191
204
  },
192
205
  ]}>
193
206
  {this.lunarDate && this.showLunar && text ? (
194
- <Text.Label4
195
- style={[style.lunarDayText, style.dayTextDisabled]}>
207
+ <Text
208
+ color={theme.colors.text.disable}
209
+ typography={'label_xxs'}
210
+ style={style.lunarDayText}>
196
211
  {this.lunarDate.lunarDay === 1
197
212
  ? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
198
213
  : this.lunarDate.lunarDay}
199
- </Text.Label4>
214
+ </Text>
200
215
  ) : (
201
216
  <View />
202
217
  )}
203
- <Text.Action2 style={[style.dayText, style.dayTextDisabled]}>
218
+ <Text color={theme.colors.text.disable} style={style.dayText}>
204
219
  {text}
205
- </Text.Action2>
220
+ </Text>
206
221
  {text && !!price ? (
207
- <Text.Label3
222
+ <Text
208
223
  style={[
209
224
  this.isValid && this.isInScope
210
225
  ? style.price
211
226
  : style.dayTextDisabled,
212
227
  isBestPrice && {
213
- color: Colors.pink_03,
228
+ color: theme.colors.primary,
214
229
  },
215
230
  ]}>
216
231
  {price}
217
- </Text.Label3>
232
+ </Text>
218
233
  ) : (
219
234
  <View
220
235
  style={{
@@ -1,5 +1,5 @@
1
- import {Dimensions} from 'react-native';
2
- import {Spacing, Colors} from '@momo-kits/core-v2';
1
+ import {Dimensions, StyleSheet} from 'react-native';
2
+ import {Spacing, Colors, scaleSize} from '@momo-kits/foundation';
3
3
 
4
4
  const dayWidth = (Dimensions.get('window').width - 38) / 7;
5
5
  const SCREEN_WIDTH = Dimensions.get('window').width;
@@ -14,17 +14,13 @@ const lineHeightPriceText = 1.3 * priceTextSize;
14
14
  const containerDayHeight =
15
15
  lineHeightDayText + lineHeightLunarText + lineHeightPriceText + 10;
16
16
  const heightDefault = lineHeightDayText + lineHeightLunarText;
17
- export default {
17
+ export default StyleSheet.create({
18
18
  dayContainer: {
19
- width: dayWidth,
20
19
  borderRadius: 4,
21
20
  alignItems: 'center',
22
- height: containerDayHeight,
21
+ height: scaleSize(48),
23
22
  },
24
- disabledWeekend: {color: Colors.red_07},
25
23
  day: {
26
- width: dayWidth,
27
- overflow: 'hidden',
28
24
  justifyContent: 'center',
29
25
  alignItems: 'center',
30
26
  borderRadius: 4,
@@ -38,25 +34,15 @@ export default {
38
34
  paddingRight: Spacing.XS,
39
35
  position: 'absolute',
40
36
  top: Spacing.XXS,
41
- color: Colors.black_12,
42
37
  },
43
38
  todayText: {
44
39
  color: 'blue',
45
40
  },
46
- weekendDay: {
47
- color: Colors.red_05,
48
- },
49
- dayTextDisabled: {
50
- opacity: 0.4,
51
- },
52
41
 
53
42
  focused: {
54
43
  backgroundColor: Colors.pink_03,
55
44
  },
56
- focusedText: {
57
- fontWeight: 'bold',
58
- color: 'white',
59
- },
45
+
60
46
  dayStartContainer: {
61
47
  borderTopLeftRadius: 4,
62
48
  borderBottomLeftRadius: 4,
@@ -124,4 +110,4 @@ export default {
124
110
  lineHeight: 14,
125
111
  },
126
112
  lineHeightPriceText,
127
- };
113
+ });
@@ -1,7 +1,7 @@
1
- import React, {useState, forwardRef, useImperativeHandle} from 'react';
2
- import {View, TouchableOpacity, StyleSheet} from 'react-native';
1
+ import React, {forwardRef, useImperativeHandle, useState} from 'react';
2
+ import {StyleSheet, TouchableOpacity, View} from 'react-native';
3
3
  import moment from 'moment';
4
- import {Icon, ScaleSize, Text, Colors, Spacing} from '@momo-kits/core-v2';
4
+ import {Colors, Icon, scaleSize, Text} from '@momo-kits/foundation';
5
5
 
6
6
  import Util from './Util';
7
7
 
@@ -26,21 +26,13 @@ const HeaderControl = forwardRef(
26
26
  return (
27
27
  <View style={styles.container}>
28
28
  <TouchableOpacity style={styles.btnLeft} onPress={onPressBackArrow}>
29
- <Icon
30
- name="24_arrow_chevron_left_small"
31
- tintColor={Colors.black_17}
32
- style={styles.icon}
33
- />
29
+ <Icon source="24_arrow_chevron_left_small" />
34
30
  </TouchableOpacity>
35
- <Text.HeaderText2 weight="semibold" style={styles.txtHeader}>
31
+ <Text typography={'header_s'} style={styles.txtHeader}>
36
32
  {headerFormat}
37
- </Text.HeaderText2>
33
+ </Text>
38
34
  <TouchableOpacity style={styles.btnRight} onPress={onPressNextArrow}>
39
- <Icon
40
- name="24_arrow_chevron_right_small"
41
- tintColor={Colors.black_17}
42
- style={styles.icon}
43
- />
35
+ <Icon source="24_arrow_chevron_right_small" />
44
36
  </TouchableOpacity>
45
37
  </View>
46
38
  );
@@ -51,13 +43,7 @@ const HeaderControl = forwardRef(
51
43
 
52
44
  export default HeaderControl;
53
45
  const styles = StyleSheet.create({
54
- icon: {
55
- width: 24,
56
- height: 24,
57
- resizeMode: 'contain',
58
- },
59
46
  txtHeader: {
60
- // fontSize: 15,
61
47
  textAlign: 'center',
62
48
  },
63
49
  btnRight: {
@@ -73,7 +59,7 @@ const styles = StyleSheet.create({
73
59
  alignItems: 'center',
74
60
  },
75
61
  container: {
76
- height: ScaleSize(44),
62
+ height: scaleSize(44),
77
63
  flexDirection: 'row',
78
64
  justifyContent: 'space-between',
79
65
  backgroundColor: Colors.blue_10,
@@ -3,9 +3,7 @@ import React, {PureComponent} from 'react';
3
3
  import {View, Dimensions} from 'react-native';
4
4
  import moment from 'moment';
5
5
  import Day from '../Day';
6
- import {Spacing, ScaleSize} from '@momo-kits/core-v2';
7
-
8
- const {width} = Dimensions.get('window');
6
+ import {Spacing, scaleSize} from '@momo-kits/foundation';
9
7
 
10
8
  export default class Month extends PureComponent {
11
9
  constructor(props) {
@@ -45,7 +43,7 @@ export default class Month extends PureComponent {
45
43
  {dayList.map((item, i) => {
46
44
  const keyDay = moment(item.date).format('YYYY-MM-DD');
47
45
  const priceInfo = this.props?.priceListDate?.[keyDay];
48
-
46
+ const itemWidth = (this.props.containerWidth - Spacing.M) / 7;
49
47
  return (
50
48
  <Day
51
49
  {...this.props}
@@ -59,6 +57,7 @@ export default class Month extends PureComponent {
59
57
  index={i}
60
58
  price={priceInfo?.priceAsString}
61
59
  isBestPrice={priceInfo?.isBestPrice}
60
+ width={itemWidth}
62
61
  />
63
62
  );
64
63
  })}
@@ -75,7 +74,7 @@ export default class Month extends PureComponent {
75
74
  style={{
76
75
  paddingHorizontal: Spacing.S,
77
76
  paddingVertical: 5,
78
- width: width - ScaleSize(24),
77
+ width: '100%',
79
78
  }}>
80
79
  {this.temp.map((item, i) =>
81
80
  this.renderDayRow(item, i, disabledWeekend),
@@ -5,9 +5,9 @@ import moment from 'moment';
5
5
  import Month from './Month';
6
6
  import style from './Day/style';
7
7
  import LunarDateConverter from './LunarDateConverter';
8
- import {ScaleSize} from '@momo-kits/core-v2';
8
+ import {scaleSize} from '@momo-kits/foundation';
9
9
 
10
- const ITEM_WIDTH = Dimensions.get('window').width - ScaleSize(24);
10
+ const ITEM_WIDTH = Dimensions.get('window').width - scaleSize(24);
11
11
  const MAX_RENDER_PER_BATCH = Platform.OS === 'android' ? 1 : 12;
12
12
 
13
13
  const converter = new LunarDateConverter();
@@ -30,12 +30,14 @@ export default class MonthList extends Component {
30
30
  }
31
31
 
32
32
  renderMonth = ({item, index}) => {
33
- const {isDoubleDateMode, priceList, disabledWeekend} = this.props;
33
+ const {isDoubleDateMode, priceList, disabledWeekend, containerWidth} =
34
+ this.props;
34
35
  const keyMonth = moment(item.date)?.format('YYYY-MM');
35
36
  const priceListDate = priceList?.[keyMonth]?.day;
36
37
 
37
38
  return (
38
39
  <Month
40
+ containerWidth={containerWidth}
39
41
  disabledWeekend={disabledWeekend}
40
42
  {...this.props}
41
43
  key={index}
@@ -2,9 +2,10 @@ import React from 'react';
2
2
  import {TouchableWithoutFeedback, View} from 'react-native';
3
3
  import Moment from 'moment';
4
4
  import Util from './Util';
5
- import {Colors, Text} from '@momo-kits/core-v2';
5
+ import {ApplicationContext, Colors, Text} from '@momo-kits/foundation';
6
6
 
7
7
  export default class TabHeader extends React.Component {
8
+ static contextType = ApplicationContext;
8
9
  constructor(props) {
9
10
  super(props);
10
11
  this.state = {
@@ -35,15 +36,17 @@ export default class TabHeader extends React.Component {
35
36
  render() {
36
37
  const {label, disabled} = this.props;
37
38
  const {date, active} = this.state;
39
+ const {theme, translate} = this.context;
40
+
38
41
  const formattedDateFromState = date ? date.format('DD/MM/YYYY') : '';
39
42
  const formattedDateFromDefault = this.defaultDate
40
43
  ? this.defaultDate.format('DD/MM/YYYY')
41
44
  : '';
42
45
  const dayOfWeekFromState = date
43
- ? `${Util.WEEKDAYSFROMMOMENT[date.day()]} -`
46
+ ? `${translate(Util.WEEKDAYSFROMMOMENT[date.day()])} -`
44
47
  : '';
45
48
  const dayOfWeekFromDefault = this.defaultDate
46
- ? `${Util.WEEKDAYSFROMMOMENT[this.defaultDate.day()]} -`
49
+ ? `${translate(Util.WEEKDAYSFROMMOMENT[this.defaultDate.day()])} -`
47
50
  : '';
48
51
 
49
52
  return (
@@ -51,20 +54,15 @@ export default class TabHeader extends React.Component {
51
54
  <View
52
55
  style={{
53
56
  flex: 1,
54
- backgroundColor: Colors.white,
57
+ backgroundColor: theme.colors.background.surface,
55
58
  }}>
56
- <Text.Description2
57
- style={{
58
- fontSize: 12,
59
- lineHeight: 16,
60
- color: Colors.black_12,
61
- }}>
62
- {label}
63
- </Text.Description2>
64
- <Text.Description1 style={{fontWeight: active ? '600' : '400'}}>
59
+ <Text typography={'description_s'} color={Colors.black_12}>
60
+ {translate(label)}
61
+ </Text>
62
+ <Text typography={'header_s'}>
65
63
  {`${dayOfWeekFromState || dayOfWeekFromDefault || '--'} `}
66
64
  {formattedDateFromState || formattedDateFromDefault || '--/--/----'}
67
- </Text.Description1>
65
+ </Text>
68
66
  </View>
69
67
  </TouchableWithoutFeedback>
70
68
  );
@@ -1,80 +1,78 @@
1
- import {SwitchLanguage} from '@momo-kits/core-v2';
2
-
3
1
  module.exports = {
4
2
  solar: {
5
3
  1: [
6
4
  {
7
5
  day: 1,
8
6
  month: 1,
9
- label: SwitchLanguage.newYear,
7
+ label: 'newYear',
10
8
  },
11
9
  ],
12
10
  2: [
13
11
  {
14
12
  day: 14,
15
13
  month: 2,
16
- label: SwitchLanguage.valentine,
14
+ label: 'valentine',
17
15
  },
18
16
  ],
19
17
  3: [
20
18
  {
21
19
  day: 8,
22
20
  month: 3,
23
- label: SwitchLanguage.womenDay,
21
+ label: 'womenDay',
24
22
  },
25
23
  ],
26
24
  4: [
27
25
  {
28
26
  day: 30,
29
27
  month: 4,
30
- label: SwitchLanguage.liberationDay,
28
+ label: 'liberationDay',
31
29
  },
32
30
  ],
33
31
  5: [
34
32
  {
35
33
  day: 1,
36
34
  month: 5,
37
- label: SwitchLanguage.laborDay,
35
+ label: 'laborDay',
38
36
  },
39
37
  ],
40
38
  6: [
41
39
  {
42
40
  day: 1,
43
41
  month: 6,
44
- label: SwitchLanguage.childrenDay,
42
+ label: 'childrenDay',
45
43
  },
46
44
  ],
47
45
  9: [
48
46
  {
49
47
  day: 2,
50
48
  month: 9,
51
- label: SwitchLanguage.nationalDay,
49
+ label: 'nationalDay',
52
50
  },
53
51
  ],
54
52
  10: [
55
53
  {
56
54
  day: 20,
57
55
  month: 10,
58
- label: SwitchLanguage.womenDayVN,
56
+ label: 'womenDayVN',
59
57
  },
60
58
  ],
61
59
  11: [
62
60
  {
63
61
  day: 20,
64
62
  month: 11,
65
- label: SwitchLanguage.teacherDay,
63
+ label: 'teacherDay',
66
64
  },
67
65
  ],
68
66
  12: [
69
67
  {
70
68
  day: 24,
71
69
  month: 12,
72
- label: SwitchLanguage.christmasEve,
70
+ label: 'christmasEve',
73
71
  },
74
72
  {
75
73
  day: 25,
76
74
  month: 12,
77
- label: SwitchLanguage.christmas,
75
+ label: 'christmas',
78
76
  },
79
77
  ],
80
78
  },
@@ -83,42 +81,42 @@ module.exports = {
83
81
  lunarDay: 30,
84
82
  lunarMonth: 12,
85
83
  lunar: true,
86
- label: SwitchLanguage.lunarNewYear,
84
+ label: 'lunarNewYear',
87
85
  highlight: '(30/12)',
88
86
  },
89
87
  {
90
88
  lunarDay: 1,
91
89
  lunarMonth: 1,
92
90
  lunar: true,
93
- label: SwitchLanguage.lunarNewYear,
91
+ label: 'lunarNewYear',
94
92
  highlight: '(1/1)',
95
93
  },
96
94
  {
97
95
  lunarDay: 2,
98
96
  lunarMonth: 1,
99
97
  lunar: true,
100
- label: SwitchLanguage.lunarNewYear,
98
+ label: 'lunarNewYear',
101
99
  highlight: '(2/1)',
102
100
  },
103
101
  {
104
102
  lunarDay: 3,
105
103
  lunarMonth: 1,
106
104
  lunar: true,
107
- label: SwitchLanguage.lunarNewYear,
105
+ label: 'lunarNewYear',
108
106
  highlight: '(3/1)',
109
107
  },
110
108
  {
111
109
  lunarDay: 4,
112
110
  lunarMonth: 1,
113
111
  lunar: true,
114
- label: SwitchLanguage.lunarNewYear,
112
+ label: 'lunarNewYear',
115
113
  highlight: '(4/1)',
116
114
  },
117
115
  {
118
116
  lunarDay: 10,
119
117
  lunarMonth: 3,
120
118
  lunar: true,
121
- label: SwitchLanguage.hungKingDay,
119
+ label: 'hungKingDay',
122
120
  highlight: '(10/3)',
123
121
  },
124
122
  ],
package/types.ts ADDED
@@ -0,0 +1,70 @@
1
+ import Moment from 'moment';
2
+ import {ViewStyle} from 'react-native';
3
+
4
+ export type CalendarProProps = {
5
+ startDate: Moment.Moment | number | null;
6
+ endDate: Moment.Moment | number | null;
7
+ maxDate: Date;
8
+ minDate: Date;
9
+ format: string;
10
+ isShowLunar?: boolean;
11
+ selectedDate: Date;
12
+ isDoubleDateMode?: boolean;
13
+ onDateChange: (day: number) => void;
14
+ priceList: any;
15
+ labelFrom?: string;
16
+ labelTo?: string;
17
+ isHideLabel?: boolean;
18
+ isHideHoliday?: boolean;
19
+ isOffLunar?: boolean;
20
+ disabledWeekend?: boolean;
21
+ onCallbackCalendar?: (lunar: string, nextStateShowLunar: boolean) => void;
22
+ containerWidth: number;
23
+ };
24
+
25
+ export type CalendarProState = {
26
+ startDate?: Moment.Moment | number | null;
27
+ endDate?: Moment.Moment | number | null;
28
+ showLunar?: boolean;
29
+ tabSelected?: number;
30
+ holidays?: any[];
31
+ ownUpdate?: boolean;
32
+ temp?: any;
33
+ headerKey?: string;
34
+ };
35
+
36
+ export type DoubleDate = {
37
+ first: Moment.Moment | Date | null;
38
+ second: Moment.Moment | Date | null;
39
+ };
40
+
41
+ export type CalendarProps = {
42
+ doubleDate: DoubleDate;
43
+ selectedDate: Moment.Moment;
44
+ mode: 'doubleDate' | 'singleDate';
45
+ id: number;
46
+ onChangeTab: (id: number) => void;
47
+ onDateChange: (date: DoubleDate | Date) => void;
48
+ onCTAStateChange: (b: boolean) => void;
49
+ onCallbackCalendar: (type: string, isDoubleDateMode: boolean) => void;
50
+ headerFrom?: string;
51
+ headerTo?: string;
52
+ isOffLunar?: boolean;
53
+ isHideHoliday?: boolean;
54
+ isHiddenSwitch?: boolean;
55
+ isShowLunar?: boolean;
56
+ priceList?: any;
57
+ labelFrom?: string;
58
+ labelTo?: string;
59
+ isHideLabel?: boolean;
60
+ minDate: Date;
61
+ maxDate: Date;
62
+ isHideHeaderPanel?: boolean;
63
+ disabledWeekend?: boolean;
64
+ style: ViewStyle | ViewStyle[];
65
+ };
66
+
67
+ export type CalendarState = {
68
+ isDoubleDateMode: boolean;
69
+ containerWidth: number;
70
+ };
package/index.js DELETED
@@ -1,4 +0,0 @@
1
- import Calendar from './src/Calendar';
2
- import CalendarPicker from './src/calendarPicker/index';
3
-
4
- export {Calendar, CalendarPicker};