@momo-kits/date-picker 0.0.40-beta → 0.0.40-beta.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.
@@ -6,7 +6,7 @@ import {
6
6
  } from 'react-native';
7
7
  import PropTypes from 'prop-types';
8
8
  import {
9
- BottomPopupHeader, Button, Text, ScreenUtils, SwitchLanguage, Spacing
9
+ BottomPopupHeader, Button, Text, ScreenUtils, SwitchLanguage, Spacing, Colors
10
10
  } from '@momo-kits/core';
11
11
  import WheelPicker from './WheelPicker';
12
12
  import DatePickerHelper from './helper/DatePickerHelper';
@@ -26,13 +26,22 @@ const styles = StyleSheet.create({
26
26
  width: widthScreen,
27
27
  alignItems: 'center',
28
28
  justifyContent: 'center',
29
+ paddingHorizontal: 21,
30
+ paddingTop: 12
29
31
  },
30
32
  column: {
31
33
  borderWidth: 2,
32
34
  borderColor: 'red',
33
35
  },
34
36
  header: {
35
- borderRadius: 16,
37
+ borderTopLeftRadius: 12,
38
+ borderTopRightRadius: 12,
39
+ //backgroundColor:'red',
40
+ height: 64,
41
+ borderBottomColor: Colors.black_04,
42
+ borderBottomWidth: 1,
43
+ alignItems:'center',
44
+ justifyContent:'center',
36
45
  marginBottom: 0, // Spacing.S,
37
46
  },
38
47
  view: {
@@ -128,11 +137,11 @@ class DatePicker extends Component {
128
137
  } : DatePickerHelper.formatDate(propsSelectedDate, props.format);
129
138
  }
130
139
  }
131
- this.createDataDate(this.minDate, this.maxDate, props.minuteArray);
140
+ this.createDataDate(this.minDate, this.maxDate, props.minuteArray, props.rangeHour);
132
141
  this.selectedIndexDate();
133
142
  }
134
143
 
135
- createDataDate(minDate, maxDate, minuteArray) {
144
+ createDataDate(minDate, maxDate, minuteArray, rangeHour) {
136
145
  this.minDay = 1;
137
146
  this.minMonth = 1;
138
147
  this.minYear = 1970;
@@ -159,7 +168,7 @@ class DatePicker extends Component {
159
168
  } else {
160
169
  this.minutes = DatePickerHelper.makeRange(0, 59, true);
161
170
  }
162
- this.ranged = DatePickerHelper.arrayRange;
171
+ this.ranged = rangeHour || DatePickerHelper.arrayRange;
163
172
  }
164
173
 
165
174
  selectedIndexDate() {
@@ -171,15 +180,13 @@ class DatePicker extends Component {
171
180
  current = this.maxDate;
172
181
  }
173
182
  if (format === 'hh:mm' && isRanged) {
174
- const valueHours_1 = this.selectedDate ? `${getStrings(this.selectedDate?.from?.getHours()?.toString())}:${getStrings(this.selectedDate?.from?.getMinutes()?.toString())}` : '';
175
-
176
- const valueHours_2 = this.selectedDate ? `${getStrings(this.selectedDate?.to?.getHours()?.toString())}:${getStrings(this.selectedDate?.to?.getMinutes()?.toString())}` : '';
177
-
178
- this.hourRangeIndex_1 = this.selectedDate
183
+ const valueHours_1 = this.selectedDate?.from ? `${getStrings(this.selectedDate?.from?.getHours()?.toString())}:${getStrings(this.selectedDate?.from?.getMinutes()?.toString())}` : '00:00';
184
+ const valueHours_2 = this.selectedDate?.to ? `${getStrings(this.selectedDate?.to?.getHours()?.toString())}:${getStrings(this.selectedDate?.to?.getMinutes()?.toString())}` : '00:00';
185
+ this.hourRangeIndex_1 = valueHours_1
179
186
  ? this.ranged.indexOf(valueHours_1)
180
187
  : this.ranged.indexOf(`${current.getHours().toString()}:${current.getMinutes().toString()}`);
181
188
 
182
- this.hourRangeIndex_2 = this.selectedDate
189
+ this.hourRangeIndex_2 = valueHours_2
183
190
  ? this.ranged.indexOf(valueHours_2)
184
191
  : this.ranged.indexOf(`${current.getHours().toString()}:${current.getMinutes().toString()}`);
185
192
  return;
@@ -199,14 +206,14 @@ class DatePicker extends Component {
199
206
  if (format === 'hh:mm' && !isRanged) {
200
207
  const valueHours = this.selectedDate ? this.selectedDate?.getHours()?.toString()?.length === 1 ? `0${this.selectedDate.getHours().toString()}` : this.selectedDate?.getHours()?.toString() || '' : '';
201
208
  const valueMinute = this.selectedDate ? this.selectedDate?.getMinutes()?.toString()?.length === 1 ? `0${this.selectedDate.getMinutes().toString()}` : this.selectedDate?.getMinutes()?.toString() || '' : '';
202
-
209
+
203
210
  this.hourIndex = this.selectedDate
204
211
  ? this.hours.indexOf(valueHours)
205
- : this.hours.indexOf(current.getHours().toString());
212
+ : this.hours.indexOf(current.getHours().toString().length === 1 ? `0${current.getHours().toString()}` : current.getHours().toString());
206
213
 
207
214
  this.minuteIndex = this.selectedDate
208
215
  ? this.minutes.indexOf(valueMinute)
209
- : this.minutes.indexOf(current.getMinutes().toString());
216
+ : this.minutes.indexOf(current.getMinutes().toString().length === 1 ? `0${current.getMinutes().toString()}` : current.getMinutes().toString());
210
217
  }
211
218
  }
212
219
 
@@ -259,11 +266,9 @@ class DatePicker extends Component {
259
266
  const day = this.days[this.dayIndex];
260
267
  const month = this.months[this.monthIndex];
261
268
  const year = this.years[this.yearIndex];
262
- const hour = this.hours[this.hourIndex];
263
- const minute = this.minutes[this.minuteIndex];
264
-
269
+ const hour = this.hours[this.hourIndex] || '00';
270
+ const minute = this.minutes[this.minuteIndex] || '00';
265
271
  const selectedDateFormatted = DatePickerHelper.toString(day, month, year, hour, minute, format);
266
-
267
272
  if (onSelected && typeof onSelected === 'function') {
268
273
  onSelected(selectedDateFormatted || selectedDate || DatePickerHelper.getCurrentDate(format));
269
274
  }
@@ -429,10 +434,11 @@ class DatePicker extends Component {
429
434
 
430
435
  renderHeader() {
431
436
  const {
432
- title, placeholder, body, buttonTitle, onButtonPress, headerStyle, iconClosePosition = 'right'
437
+ title, placeholder, body, buttonTitle, onButtonPress, headerStyle, iconClosePosition = 'right', iconType
433
438
  } = this.props;
434
439
  return (
435
440
  <BottomPopupHeader
441
+ iconType={iconType}
436
442
  iconClosePosition={iconClosePosition}
437
443
  body={body}
438
444
  onClose={this.hide}
@@ -539,7 +545,7 @@ class DatePicker extends Component {
539
545
  renderFooter() {
540
546
  const { titleFooter, renderFooter } = this.props;
541
547
  return renderFooter ? renderFooter() : (
542
- <View style={{ paddingHorizontal: 12, marginBottom: ifIphoneX(29, 11), marginTop: 28 }}>
548
+ <View style={{ paddingHorizontal: 12, marginBottom: ifIphoneX(35, 12), marginTop: 16 }}>
543
549
  <Button
544
550
  onPress={this.finish}
545
551
  title={titleFooter || SwitchLanguage.confirm}
@@ -582,7 +588,10 @@ DatePicker.propTypes = {
582
588
  renderDescription: PropTypes.any,
583
589
  description: PropTypes.string,
584
590
  renderFooter: PropTypes.any,
585
- style: PropTypes.any
591
+ style: PropTypes.any,
592
+ rangeHour: PropTypes.array,
593
+ iconClosePosition: PropTypes.oneOf(['left', 'right']),
594
+ iconType: PropTypes.oneOf(['icon', 'text']),
586
595
  };
587
596
 
588
597
  DatePicker.defaultProps = {
@@ -146,7 +146,7 @@ const styles = StyleSheet.create({
146
146
  justifyContent: 'center'
147
147
  },
148
148
  contentStyle: {
149
- height: 200,
149
+ height: 230,
150
150
  },
151
151
  column: {
152
152
  borderWidth: 2,
@@ -6,6 +6,7 @@ import {
6
6
  LinearGradient, Text, Colors, ScaleSize
7
7
  } from '@momo-kits/core';
8
8
  import ScrollCustom from './custom/ScrollCustom';
9
+ import DatePickerHelper from './helper/DatePickerHelper';
9
10
 
10
11
  const widthScreen = Dimensions.get('window').width;
11
12
  // var heightScreen = Dimensions.get('window').height;
@@ -14,8 +15,9 @@ export default class WheelPicker extends Component {
14
15
  constructor(props) {
15
16
  super(props);
16
17
  const {
17
- heightItem, value, numberItem, arrayValue
18
+ heightItem, value: valueItem, numberItem, arrayValue
18
19
  } = this.props;
20
+ const value = valueItem === -1 ? 0 : valueItem;
19
21
  this.heightItem = heightItem;
20
22
  this.currentPosition = value * this.heightItem;
21
23
  this.prePosition = this.currentPosition;
@@ -171,19 +173,20 @@ export default class WheelPicker extends Component {
171
173
  const { items, value, width } = this.state;
172
174
  const { preFix, bottomOffset } = this.props;
173
175
  return (
174
- <View style={{ flex: 1, height: heightContain + 20 }}>
175
- <Text.SubTitle style={{
176
+ <View style={{ flex: 1, height: heightContain + 40 }}>
177
+ <Text.SubTitle weight='bold' style={{
176
178
  color: Colors.black_17, marginLeft: 6, marginBottom: 3
177
179
  }}
178
180
  >
179
- {preFix?.toUpperCase()}
181
+ {DatePickerHelper.capitalizeFirstLetter(preFix || '')}
180
182
  </Text.SubTitle>
181
183
  <View
182
184
  style={{
183
185
  flex: 1,
184
186
  height: heightContain,
185
- // backgroundColor: 'blue',
187
+ //backgroundColor: 'blue',
186
188
  marginHorizontal: 6,
189
+ paddingBottom: 20,
187
190
  borderWidth: 1,
188
191
  borderColor: Colors.black_04,
189
192
  borderRadius: 8,
@@ -77,7 +77,7 @@ export default class DatePickerHelper {
77
77
  static formatDate(date, format) {
78
78
  if (date && format) {
79
79
  const {
80
- year, month, day, hour, minute, second
80
+ year, month, day, hour, minute, second = 0
81
81
  } = DatePickerHelper.getDateTimeFromFormat(date, format);
82
82
  if (DatePickerHelper.checkValidDate(year, month, day)
83
83
  && DatePickerHelper.checkValidTime(hour, minute, second)) {
@@ -156,17 +156,21 @@ export default class DatePickerHelper {
156
156
  return null;
157
157
  }
158
158
 
159
- static checkValidDate(year, month, day) {
159
+ static checkValidDate(y, m, d) {
160
+ const year = parseInt(y);
161
+ const month = parseInt(m);
162
+ const day = parseInt(d);
160
163
  const months31 = [0, 2, 4, 6, 7, 9, 11];
161
164
  const months30 = [3, 5, 8, 10];
162
165
  const months28 = [1];
163
166
  const isLeap = ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
164
167
  if (year != null && month != null && day != null) {
165
168
  const isDayValid = day > 0;
166
- const isMonthValid = (months31.indexOf(month) !== -1 && day <= 31)
167
- || (months30.indexOf(month) !== -1 && day <= 30)
168
- || (months28.indexOf(month) !== -1 && day <= 28)
169
- || (months28.indexOf(month) !== -1 && day <= 29 && isLeap);
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);
170
174
  return isDayValid && isMonthValid;
171
175
  }
172
176
  return false;
@@ -194,4 +198,8 @@ export default class DatePickerHelper {
194
198
 
195
199
  return monthLength[month - 1];
196
200
  }
201
+
202
+ static capitalizeFirstLetter(string) {
203
+ return string.charAt(0).toUpperCase() + string.slice(1);
204
+ }
197
205
  }
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import DatePicker from './datePicker/DatePicker';
2
2
  import DatePickerInput from './datePicker/DatePickerInput';
3
+ import ListPicker from './datePicker/ListPicker';
3
4
 
4
5
  export {
5
6
  DatePicker,
6
- DatePickerInput
7
+ DatePickerInput,
8
+ ListPicker
7
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/date-picker",
3
- "version": "0.0.40-beta",
3
+ "version": "0.0.40-beta.2",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},
@@ -8,8 +8,8 @@
8
8
  "react-native": ">=0.55",
9
9
  "prop-types": "^15.7.2",
10
10
  "react": "16.9.0",
11
- "lodash": "^4.17.15",
12
- "@momo-kits/core": ">=0.0.5-beta"
11
+ "@momo-kits/core": ">=0.0.5-beta",
12
+ "lodash": "^4.17.15"
13
13
  },
14
14
  "devDependencies": {},
15
15
  "license": "MoMo"
package/publish.sh CHANGED
@@ -21,7 +21,7 @@ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type
21
21
  #npm login
22
22
  #publish dist to npm
23
23
  cd dist
24
- npm publish --access=public
24
+ npm publish --tag beta --access=public
25
25
  cd ..
26
26
  rm -rf dist
27
27