@momo-kits/date-picker 0.0.62-alpha.2 → 0.0.62-alpha.20

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.
@@ -11,7 +11,7 @@ import {
11
11
  SwitchLanguage,
12
12
  Spacing,
13
13
  Colors,
14
- } from '@momo-kits/core';
14
+ } from '@momo-kits/core-v2';
15
15
  import WheelPicker from './WheelPicker';
16
16
  import DatePickerHelper from './helper/DatePickerHelper';
17
17
 
@@ -67,6 +67,7 @@ const styles = StyleSheet.create({
67
67
 
68
68
  const getStrings = (strings) =>
69
69
  strings?.length === 1 ? `0${strings}` : strings;
70
+
70
71
  class DatePicker extends Component {
71
72
  constructor(props) {
72
73
  super(props);
@@ -224,8 +225,6 @@ class DatePicker extends Component {
224
225
  this.minutes = DatePickerHelper.makeRange(0, 59, true);
225
226
  }
226
227
  this.ranged = rangeHour || DatePickerHelper.arrayRange;
227
- this.startTime = startTime || DatePickerHelper.arrayRange;
228
- this.endTime = endTime || DatePickerHelper.arrayRange;
229
228
  }
230
229
 
231
230
  selectedIndexDate() {
@@ -358,8 +357,12 @@ class DatePicker extends Component {
358
357
  if (isRanged && format === 'hh:mm') {
359
358
  const from = this.ranged[this.hourRangeIndex_1];
360
359
  const to = this.ranged[this.hourRangeIndex_2];
360
+
361
361
  if (onSelected && typeof onSelected === 'function') {
362
- onSelected({ from, to });
362
+ onSelected({
363
+ from,
364
+ to,
365
+ });
363
366
  }
364
367
  this.hide();
365
368
  return;
@@ -594,9 +597,10 @@ class DatePicker extends Component {
594
597
  const { description, descriptionStyle, renderDescription } = this.props;
595
598
  if (renderDescription) return renderDescription;
596
599
  return description ? (
597
- <Text.Title style={[{ marginBottom: Spacing.S }, descriptionStyle]}>
600
+ <Text.Paragraph
601
+ style={[{ marginBottom: Spacing.S }, descriptionStyle]}>
598
602
  {description}
599
- </Text.Title>
603
+ </Text.Paragraph>
600
604
  ) : null;
601
605
  };
602
606
 
@@ -611,6 +615,7 @@ class DatePicker extends Component {
611
615
  labelHour,
612
616
  isRanged,
613
617
  } = this.props;
618
+
614
619
  if (isRanged && format === 'hh:mm') {
615
620
  return (
616
621
  <View style={styles.container}>
@@ -619,7 +624,7 @@ class DatePicker extends Component {
619
624
  {this.renderColumn(
620
625
  'HourRange1',
621
626
  this.hourRangeIndex_1,
622
- this.startTime,
627
+ this.ranged,
623
628
  SwitchLanguage.from,
624
629
  bottomOffset,
625
630
  (value) => {
@@ -630,7 +635,7 @@ class DatePicker extends Component {
630
635
  {this.renderColumn(
631
636
  'HourRange2',
632
637
  this.hourRangeIndex_2,
633
- this.endTime,
638
+ this.ranged,
634
639
  SwitchLanguage.to,
635
640
  bottomOffset,
636
641
  (value) => {
@@ -9,7 +9,8 @@ import {
9
9
  Colors,
10
10
  ValueUtil,
11
11
  Image,
12
- } from '@momo-kits/core';
12
+ Radius,
13
+ } from '@momo-kits/core-v2';
13
14
  import DatePicker from './DatePicker';
14
15
 
15
16
  const DatePickerInput = ({
@@ -64,14 +65,14 @@ const DatePickerInput = ({
64
65
  ValueUtil.extractStyle(style),
65
66
  otherStyle,
66
67
  ]}>
67
- <Text.Title
68
+ <Text.Paragraph
68
69
  style={[
69
70
  styles.defaultText,
70
71
  ValueUtil.extractStyle(textStyle),
71
72
  isEmpty(selected) ? { color: Colors.black_09 } : {},
72
73
  ]}>
73
74
  {isEmpty(selected) ? format : selected}
74
- </Text.Title>
75
+ </Text.Paragraph>
75
76
  {showRightIcon ? (
76
77
  <Image
77
78
  source={icon || IconSource.ic_calendar}
@@ -118,7 +119,7 @@ const styles = StyleSheet.create({
118
119
  container: {
119
120
  flexDirection: 'row',
120
121
  height: 42,
121
- borderRadius: 4,
122
+ borderRadius: Radius.S,
122
123
  borderColor: Colors.black_06,
123
124
  borderWidth: 1,
124
125
  alignItems: 'center',
@@ -127,7 +128,7 @@ const styles = StyleSheet.create({
127
128
  backgroundColor: Colors.black_01,
128
129
  },
129
130
  error: {
130
- borderColor: Colors.red_05,
131
+ borderColor: Colors.red_03,
131
132
  },
132
133
  defaultText: {
133
134
  // fontSize: 14
@@ -9,7 +9,7 @@ import {
9
9
  Image,
10
10
  DeviceUtils,
11
11
  SwitchLanguage,
12
- } from '@momo-kits/core';
12
+ } from '@momo-kits/core-v2';
13
13
  import WheelPicker from './WheelPicker';
14
14
 
15
15
  const { isIphoneX } = DeviceUtils;
@@ -63,9 +63,10 @@ export default class ListPicker extends Component {
63
63
 
64
64
  renderRight = () => (
65
65
  <TouchableOpacity onPress={this.onPressChoose}>
66
- <Text.Title style={{ fontWeight: 'bold', color: Colors.pink_05 }}>
66
+ <Text.Paragraph
67
+ style={{ fontWeight: 'bold', color: Colors.pink_05 }}>
67
68
  {SwitchLanguage.save}
68
- </Text.Title>
69
+ </Text.Paragraph>
69
70
  </TouchableOpacity>
70
71
  );
71
72
 
@@ -1,6 +1,6 @@
1
1
  import React, { Component } from 'react';
2
2
  import { Dimensions, View } from 'react-native';
3
- import { LinearGradient, Text, Colors, ScaleSize } from '@momo-kits/core';
3
+ import { LinearGradient, Text, Colors, ScaleSize } from '@momo-kits/core-v2';
4
4
  import ScrollCustom from './custom/ScrollCustom';
5
5
  import DatePickerHelper from './helper/DatePickerHelper';
6
6
 
@@ -32,6 +32,7 @@ export default class WheelPicker extends Component {
32
32
 
33
33
  componentDidMount() {
34
34
  const { value } = this.props;
35
+ console.log(value);
35
36
  this.scrollToPosition(value);
36
37
  }
37
38
 
@@ -186,21 +187,24 @@ export default class WheelPicker extends Component {
186
187
  const { items, value, width } = this.state;
187
188
  const { preFix, bottomOffset } = this.props;
188
189
  return (
189
- <View style={{ flex: 1, height: heightContain + 40 }}>
190
- <Text.SubTitle
191
- weight="bold"
190
+ <View
191
+ style={{
192
+ flex: 1,
193
+ height: heightContain + 40,
194
+ }}>
195
+ <Text.Description2
196
+ weight="semibold"
192
197
  style={{
193
198
  color: Colors.black_17,
194
199
  marginLeft: 6,
195
200
  marginBottom: 3,
196
201
  }}>
197
202
  {DatePickerHelper.capitalizeFirstLetter(preFix || '')}
198
- </Text.SubTitle>
203
+ </Text.Description2>
199
204
  <View
200
205
  style={{
201
206
  flex: 1,
202
207
  height: heightContain,
203
- //backgroundColor: 'blue',
204
208
  marginHorizontal: 6,
205
209
  paddingBottom: 20,
206
210
  borderWidth: 1,
@@ -275,22 +279,21 @@ export default class WheelPicker extends Component {
275
279
  justifyContent: 'center',
276
280
  alignItems: 'center',
277
281
  }}>
278
- <Text
282
+ <Text.Action2
283
+ weight={
284
+ value === index ? 'bold' : 'semibold'
285
+ }
279
286
  style={{
280
287
  color:
281
288
  value === index
282
289
  ? Colors.black_17
283
- : '#909090',
284
- fontWeight:
285
- value === index ? 'bold' : '700',
286
- fontSize:
287
- value === index
288
- ? ScaleSize(20)
289
- : ScaleSize(16),
290
+ : Colors.black_12,
291
+
292
+ fontSize: 15,
290
293
  }}>
291
294
  {valueItem}
292
295
  {/* {reversePreFix ? `${valueItem} ${preFix}` : `${preFix} ${valueItem}`} */}
293
- </Text>
296
+ </Text.Action2>
294
297
  </View>
295
298
  ))}
296
299
  {this.renderHiddenItem(
@@ -49,7 +49,7 @@ export default class DatePickerHelper {
49
49
  '22:00',
50
50
  '22:30',
51
51
  '23:00',
52
- '23:30'
52
+ '23:30',
53
53
  ];
54
54
 
55
55
  static makeRange(min, max, isDouble) {
@@ -57,7 +57,8 @@ export default class DatePickerHelper {
57
57
  // eslint-disable-next-line no-plusplus
58
58
  for (let i = min; i <= max; i++) {
59
59
  const string = String(i);
60
- const value = string.length === 1 && isDouble ? `0${string}` : string;
60
+ const value =
61
+ string.length === 1 && isDouble ? `0${string}` : string;
61
62
  array.push(value);
62
63
  }
63
64
  return array;
@@ -69,7 +70,14 @@ export default class DatePickerHelper {
69
70
  const day = current.getDate().toString();
70
71
  const month = (current.getMonth() + 1).toString();
71
72
  const year = current.getFullYear().toString();
72
- return DatePickerHelper.toString(day, month, year, null, null, format);
73
+ return DatePickerHelper.toString(
74
+ day,
75
+ month,
76
+ year,
77
+ null,
78
+ null,
79
+ format,
80
+ );
73
81
  }
74
82
  return '';
75
83
  }
@@ -77,10 +85,17 @@ export default class DatePickerHelper {
77
85
  static formatDate(date, format) {
78
86
  if (date && format) {
79
87
  const {
80
- year, month, day, hour, minute, second = 0
88
+ year,
89
+ month,
90
+ day,
91
+ hour,
92
+ minute,
93
+ second = 0,
81
94
  } = DatePickerHelper.getDateTimeFromFormat(date, format);
82
- if (DatePickerHelper.checkValidDate(year, month, day)
83
- && DatePickerHelper.checkValidTime(hour, minute, second)) {
95
+ if (
96
+ DatePickerHelper.checkValidDate(year, month, day) &&
97
+ DatePickerHelper.checkValidTime(hour, minute, second)
98
+ ) {
84
99
  return new Date(year, month, day, hour, minute, second);
85
100
  }
86
101
  return null;
@@ -119,8 +134,14 @@ export default class DatePickerHelper {
119
134
 
120
135
  const today = new Date();
121
136
 
122
- const year = yearIndex > -1 ? dateItems?.[yearIndex] : today.getFullYear();
123
- const month = monthIndex > -1 ? dateItems?.[monthIndex] - 1 : today.getMonth() === 0 ? 1 : today.getMonth() - 1;
137
+ const year =
138
+ yearIndex > -1 ? dateItems?.[yearIndex] : today.getFullYear();
139
+ const month =
140
+ monthIndex > -1
141
+ ? dateItems?.[monthIndex] - 1
142
+ : today.getMonth() === 0
143
+ ? 1
144
+ : today.getMonth() - 1;
124
145
  const day = dayIndex > -1 ? dateItems?.[dayIndex] : today.getDate();
125
146
 
126
147
  const hour = hourIndex > -1 ? dateItems[hourIndex] : 0;
@@ -142,7 +163,7 @@ export default class DatePickerHelper {
142
163
  return number;
143
164
  }
144
165
  return `0${number}`;
145
- }
166
+ };
146
167
 
147
168
  static toString(day, month, year, hour, minute, format) {
148
169
  if (day && month && year && format) {
@@ -160,24 +181,32 @@ export default class DatePickerHelper {
160
181
  const year = parseInt(y);
161
182
  const month = parseInt(m);
162
183
  const day = parseInt(d);
163
- const months31 = [0, 2, 4, 6, 7, 9, 11];
164
- const months30 = [3, 5, 8, 10];
165
- const months28 = [1];
166
- const isLeap = ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
184
+ const months31 = [1, 3, 5, 7, 8, 10, 12];
185
+ const months30 = [4, 6, 9, 11];
186
+ const months28 = [2];
187
+ const isLeap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
167
188
  if (year != null && month != null && day != null) {
168
189
  const isDayValid = day > 0;
169
- const isMonthValid = (months31.indexOf(parseInt(month)) != -1 && day <= 31)
170
- || (months30.indexOf(month) != -1 && day <= 30)
171
- || (months30.indexOf(month) != -1 && day <= 31)
172
- || (months28.indexOf(month) != -1 && day <= 28)
173
- || (months28.indexOf(month) != -1 && day <= 29 && isLeap);
190
+ const isMonthValid =
191
+ (months31.indexOf(parseInt(month)) != -1 && day <= 31) ||
192
+ (months30.indexOf(month) != -1 && day <= 30) ||
193
+ (months30.indexOf(month) != -1 && day <= 31) ||
194
+ (months28.indexOf(month) != -1 && day <= 28) ||
195
+ (months28.indexOf(month) != -1 && day <= 29 && isLeap);
174
196
  return isDayValid && isMonthValid;
175
197
  }
176
198
  return false;
177
199
  }
178
200
 
179
201
  static checkValidTime(hour, minute, second) {
180
- if ((hour >= 0 && hour < 24) && (minute >= 0 && minute < 60) && (second >= 0 && second < 60)) {
202
+ if (
203
+ hour >= 0 &&
204
+ hour < 24 &&
205
+ minute >= 0 &&
206
+ minute < 60 &&
207
+ second >= 0 &&
208
+ second < 60
209
+ ) {
181
210
  return true;
182
211
  }
183
212
  return false;
@@ -185,11 +214,18 @@ export default class DatePickerHelper {
185
214
 
186
215
  static calculateDateSinceYearAgo(yearAgo) {
187
216
  let nowDate = new Date();
188
- nowDate = new Date(nowDate.getFullYear() - yearAgo, nowDate.getMonth(), nowDate.getDate());
217
+ nowDate = new Date(
218
+ nowDate.getFullYear() - yearAgo,
219
+ nowDate.getMonth(),
220
+ nowDate.getDate(),
221
+ );
189
222
  return nowDate;
190
223
  }
191
224
 
192
- static getMaxDate(month = new Date().getMonth(), year = new Date().getFullYear()) {
225
+ static getMaxDate(
226
+ month = new Date().getMonth(),
227
+ year = new Date().getFullYear(),
228
+ ) {
193
229
  const monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
194
230
  // Adjust for leap years
195
231
  if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
@@ -201,5 +237,5 @@ export default class DatePickerHelper {
201
237
 
202
238
  static capitalizeFirstLetter(string) {
203
239
  return string.charAt(0).toUpperCase() + string.slice(1);
204
- }
240
+ }
205
241
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@momo-kits/date-picker",
3
- "version": "0.0.62-alpha.2",
3
+ "version": "0.0.62-alpha.20",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},
7
7
  "peerDependencies": {
8
- "@momo-kits/core": ">=0.0.5-beta",
8
+ "@momo-kits/core-v2": ">=0.0.5-beta",
9
9
  "lodash": "^4.17.15",
10
10
  "prop-types": "^15.7.2",
11
11
  "react": "16.9.0",
@@ -13,4 +13,4 @@
13
13
  },
14
14
  "devDependencies": {},
15
15
  "license": "MoMo"
16
- }
16
+ }