@momo-kits/date-picker 0.0.5-beta → 0.0.5
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/datePicker/DatePicker.js +15 -6
- package/datePicker/DatePickerInput.js +18 -7
- package/datePicker/ListPicker.js +193 -0
- package/index.js +3 -1
- package/package.json +15 -16
- package/publish.sh +1 -1
package/datePicker/DatePicker.js
CHANGED
|
@@ -128,11 +128,11 @@ class DatePicker extends Component {
|
|
|
128
128
|
} : DatePickerHelper.formatDate(propsSelectedDate, props.format);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
this.createDataDate(this.minDate, this.maxDate);
|
|
131
|
+
this.createDataDate(this.minDate, this.maxDate, props.minuteArray, props.rangeHour);
|
|
132
132
|
this.selectedIndexDate();
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
createDataDate(minDate, maxDate) {
|
|
135
|
+
createDataDate(minDate, maxDate, minuteArray, rangeHour) {
|
|
136
136
|
this.minDay = 1;
|
|
137
137
|
this.minMonth = 1;
|
|
138
138
|
this.minYear = 1970;
|
|
@@ -153,9 +153,13 @@ class DatePicker extends Component {
|
|
|
153
153
|
this.days = DatePickerHelper.makeRange(1, 31);
|
|
154
154
|
this.months = DatePickerHelper.makeRange(1, 12);
|
|
155
155
|
this.years = DatePickerHelper.makeRange(this.minYear, this.maxYear);
|
|
156
|
-
this.minutes = DatePickerHelper.makeRange(0, 59, true);
|
|
157
156
|
this.hours = DatePickerHelper.makeRange(0, 23, true);
|
|
158
|
-
|
|
157
|
+
if (Array.isArray(minuteArray)) {
|
|
158
|
+
this.minutes = minuteArray;
|
|
159
|
+
} else {
|
|
160
|
+
this.minutes = DatePickerHelper.makeRange(0, 59, true);
|
|
161
|
+
}
|
|
162
|
+
this.ranged = rangeHour || DatePickerHelper.arrayRange;
|
|
159
163
|
}
|
|
160
164
|
|
|
161
165
|
selectedIndexDate() {
|
|
@@ -425,10 +429,11 @@ class DatePicker extends Component {
|
|
|
425
429
|
|
|
426
430
|
renderHeader() {
|
|
427
431
|
const {
|
|
428
|
-
title, placeholder, body, buttonTitle, onButtonPress, headerStyle, iconClosePosition = 'right'
|
|
432
|
+
title, placeholder, body, buttonTitle, onButtonPress, headerStyle, iconClosePosition = 'right', iconType
|
|
429
433
|
} = this.props;
|
|
430
434
|
return (
|
|
431
435
|
<BottomPopupHeader
|
|
436
|
+
iconType={iconType}
|
|
432
437
|
iconClosePosition={iconClosePosition}
|
|
433
438
|
body={body}
|
|
434
439
|
onClose={this.hide}
|
|
@@ -578,7 +583,10 @@ DatePicker.propTypes = {
|
|
|
578
583
|
renderDescription: PropTypes.any,
|
|
579
584
|
description: PropTypes.string,
|
|
580
585
|
renderFooter: PropTypes.any,
|
|
581
|
-
style: PropTypes.any
|
|
586
|
+
style: PropTypes.any,
|
|
587
|
+
rangeHour: PropTypes.array,
|
|
588
|
+
iconClosePosition: PropTypes.oneOf(['left', 'right']),
|
|
589
|
+
iconType: PropTypes.oneOf(['icon', 'text']),
|
|
582
590
|
};
|
|
583
591
|
|
|
584
592
|
DatePicker.defaultProps = {
|
|
@@ -596,3 +604,4 @@ DatePicker.defaultProps = {
|
|
|
596
604
|
};
|
|
597
605
|
|
|
598
606
|
export default DatePicker;
|
|
607
|
+
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
import DatePicker from './DatePicker';
|
|
9
9
|
|
|
10
10
|
const DatePickerInput = ({
|
|
11
|
-
navigator, defaultDate, maxDate, minDate, format = 'dd/MM/YYYY', onSelected, onClose,
|
|
11
|
+
navigator, defaultDate, maxDate, minDate, format = 'dd/MM/YYYY', onSelected, onClose,
|
|
12
|
+
style, textStyle, icon, iconStyle, error, disabled, minuteArray, title, showRightIcon
|
|
12
13
|
}) => {
|
|
13
14
|
const [selected, setSelected] = useState(defaultDate || '');
|
|
14
15
|
|
|
@@ -20,8 +21,10 @@ const DatePickerInput = ({
|
|
|
20
21
|
minDate,
|
|
21
22
|
maxDate,
|
|
22
23
|
format,
|
|
24
|
+
title,
|
|
23
25
|
selectedDate: selected,
|
|
24
26
|
onClose,
|
|
27
|
+
minuteArray,
|
|
25
28
|
onSelected: (dateSelected) => {
|
|
26
29
|
onSelected?.(dateSelected);
|
|
27
30
|
setSelected(dateSelected);
|
|
@@ -40,10 +43,12 @@ const DatePickerInput = ({
|
|
|
40
43
|
style={[styles.container, ValueUtil.extractStyle(style), otherStyle]}
|
|
41
44
|
>
|
|
42
45
|
<Text.Title style={[styles.defaultText, ValueUtil.extractStyle(textStyle), isEmpty(selected) ? { color: Colors.black_09 } : {}]}>{isEmpty(selected) ? format : selected}</Text.Title>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
{showRightIcon ? (
|
|
47
|
+
<Image
|
|
48
|
+
source={icon || IconSource.ic_calendar}
|
|
49
|
+
style={[styles.icon, ValueUtil.extractStyle(iconStyle)]}
|
|
50
|
+
/>
|
|
51
|
+
) : <View />}
|
|
47
52
|
</TouchableOpacity>
|
|
48
53
|
);
|
|
49
54
|
};
|
|
@@ -61,7 +66,13 @@ DatePickerInput.propTypes = {
|
|
|
61
66
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
62
67
|
textStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
63
68
|
error: PropTypes.bool,
|
|
64
|
-
disabled: PropTypes.bool
|
|
69
|
+
disabled: PropTypes.bool,
|
|
70
|
+
minuteArray: PropTypes.arrayOf(PropTypes.string),
|
|
71
|
+
showRightIcon: PropTypes.bool,
|
|
72
|
+
title: PropTypes.string
|
|
73
|
+
};
|
|
74
|
+
DatePickerInput.defaultProps = {
|
|
75
|
+
showRightIcon: true
|
|
65
76
|
};
|
|
66
77
|
|
|
67
78
|
export default DatePickerInput;
|
|
@@ -94,4 +105,4 @@ const styles = StyleSheet.create({
|
|
|
94
105
|
backgroundColor: Colors.black_05,
|
|
95
106
|
borderWidth: 0
|
|
96
107
|
}
|
|
97
|
-
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Dimensions, StyleSheet, View
|
|
4
|
+
} from 'react-native';
|
|
5
|
+
import {
|
|
6
|
+
Button, IconSource, TouchableOpacity, Text, Colors, Image, DeviceUtils, SwitchLanguage
|
|
7
|
+
} from '@momo-kits/core';
|
|
8
|
+
import WheelPicker from './WheelPicker';
|
|
9
|
+
|
|
10
|
+
const { isIphoneX } = DeviceUtils;
|
|
11
|
+
|
|
12
|
+
const widthScreen = Dimensions.get('window').width;
|
|
13
|
+
|
|
14
|
+
export default class ListPicker extends Component {
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super(props);
|
|
17
|
+
this.data = 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
hide = () => {
|
|
21
|
+
const { onClose, requestClose } = this.props;
|
|
22
|
+
if (requestClose && typeof requestClose === 'function') {
|
|
23
|
+
requestClose(() => {
|
|
24
|
+
if (onClose && typeof onClose === 'function') {
|
|
25
|
+
onClose();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
onBeginDrag = () => {
|
|
32
|
+
if (this.refs.picker) {
|
|
33
|
+
this.refs.picker.setScrollEnabled(false);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
onEndDrag = () => {
|
|
38
|
+
if (this.refs.picker) {
|
|
39
|
+
this.refs.picker.setScrollEnabled(true);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onChangeValue = (value) => {
|
|
44
|
+
const { callback } = this.props;
|
|
45
|
+
if (typeof callback === 'function') {
|
|
46
|
+
callback(value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
onPressClear = () => {
|
|
51
|
+
this.hide();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onPressChoose = () => {
|
|
55
|
+
this.onChangeValue(this.data);
|
|
56
|
+
this.hide();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
renderRight = () => (
|
|
60
|
+
<TouchableOpacity
|
|
61
|
+
onPress={this.onPressChoose}
|
|
62
|
+
>
|
|
63
|
+
<Text.Title style={{ fontWeight: 'bold', color: Colors.pink_05 }}>{SwitchLanguage.save}</Text.Title>
|
|
64
|
+
</TouchableOpacity>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
renderLeftIcon = () => (
|
|
68
|
+
<TouchableOpacity onPress={() => this.hide()}>
|
|
69
|
+
<Image
|
|
70
|
+
source={IconSource.ic_close_x_24}
|
|
71
|
+
style={{ width: 25, height: 25, tintColor: Colors.black_17 }}
|
|
72
|
+
/>
|
|
73
|
+
</TouchableOpacity>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
renderHeader() {
|
|
77
|
+
const { title = '' } = this.props;
|
|
78
|
+
return (
|
|
79
|
+
<View style={styles.header}>
|
|
80
|
+
{this.renderLeftIcon()}
|
|
81
|
+
<Text style={styles.title}>
|
|
82
|
+
{title}
|
|
83
|
+
</Text>
|
|
84
|
+
{this.props.typeStyle === 'aboveAction' ? this.renderRight() : <View style={{ width: 25 }} />}
|
|
85
|
+
</View>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
renderContent() {
|
|
90
|
+
const { arrData = [], stylePicker, initValue } = this.props;
|
|
91
|
+
return (
|
|
92
|
+
<View style={styles.contentStyle}>
|
|
93
|
+
<WheelPicker
|
|
94
|
+
stylePicker={stylePicker}
|
|
95
|
+
bottomOffset={1}
|
|
96
|
+
value={initValue}
|
|
97
|
+
key="picker"
|
|
98
|
+
ref="picker"
|
|
99
|
+
arrayValue={arrData}
|
|
100
|
+
onBeginDrag={this.onBeginDrag}
|
|
101
|
+
onEndDrag={this.onEndDrag}
|
|
102
|
+
onValueChange={(value) => {
|
|
103
|
+
this.data = value;
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
|
|
107
|
+
</View>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
render() {
|
|
112
|
+
return (
|
|
113
|
+
<View style={styles.view}>
|
|
114
|
+
{this.renderHeader()}
|
|
115
|
+
{this.renderContent()}
|
|
116
|
+
{
|
|
117
|
+
this.props.typeStyle === 'aboveAction'
|
|
118
|
+
? null
|
|
119
|
+
: (
|
|
120
|
+
<View style={styles.btnView}>
|
|
121
|
+
<Button
|
|
122
|
+
style={{ flex: 1 }}
|
|
123
|
+
title={SwitchLanguage.cancel}
|
|
124
|
+
buttonStyle={{ backgroundColor: Colors.second_text_color }}
|
|
125
|
+
onPress={this.onPressClear}
|
|
126
|
+
/>
|
|
127
|
+
<Button
|
|
128
|
+
style={{ flex: 1, marginLeft: 15 }}
|
|
129
|
+
title={SwitchLanguage.choose}
|
|
130
|
+
type="primary"
|
|
131
|
+
onPress={this.onPressChoose}
|
|
132
|
+
/>
|
|
133
|
+
</View>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
</View>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const styles = StyleSheet.create({
|
|
142
|
+
container: {
|
|
143
|
+
flexDirection: 'row',
|
|
144
|
+
width: widthScreen,
|
|
145
|
+
alignItems: 'center',
|
|
146
|
+
justifyContent: 'center'
|
|
147
|
+
},
|
|
148
|
+
contentStyle: {
|
|
149
|
+
height: 200,
|
|
150
|
+
},
|
|
151
|
+
column: {
|
|
152
|
+
borderWidth: 2,
|
|
153
|
+
borderColor: 'red',
|
|
154
|
+
},
|
|
155
|
+
header: {
|
|
156
|
+
flexDirection: 'row',
|
|
157
|
+
height: 50,
|
|
158
|
+
width: widthScreen,
|
|
159
|
+
paddingHorizontal: 16,
|
|
160
|
+
alignItems: 'center',
|
|
161
|
+
justifyContent: 'space-between',
|
|
162
|
+
backgroundColor: '#fff',
|
|
163
|
+
borderBottomWidth: 1,
|
|
164
|
+
borderColor: '#DADADA',
|
|
165
|
+
},
|
|
166
|
+
view: {
|
|
167
|
+
backgroundColor: 'white',
|
|
168
|
+
paddingBottom: 10 + (isIphoneX() ? 10 : 0)
|
|
169
|
+
},
|
|
170
|
+
title: {
|
|
171
|
+
fontWeight: 'bold',
|
|
172
|
+
color: Colors.black_17,
|
|
173
|
+
flex: 1,
|
|
174
|
+
fontSize: 16,
|
|
175
|
+
textAlign: 'center'
|
|
176
|
+
},
|
|
177
|
+
titleCancel: {
|
|
178
|
+
fontSize: 17,
|
|
179
|
+
color: '#4A90E2'
|
|
180
|
+
},
|
|
181
|
+
titleConfirm: {
|
|
182
|
+
fontSize: 17,
|
|
183
|
+
color: '#4A90E2',
|
|
184
|
+
textAlign: 'right'
|
|
185
|
+
},
|
|
186
|
+
btnView: {
|
|
187
|
+
flexDirection: 'row',
|
|
188
|
+
justifyContent: 'space-between',
|
|
189
|
+
marginHorizontal: 15,
|
|
190
|
+
height: 60,
|
|
191
|
+
alignItems: 'center'
|
|
192
|
+
}
|
|
193
|
+
});
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
"name": "@momo-kits/date-picker",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"react-native": ">=0.55",
|
|
9
|
+
"prop-types": "^15.7.2",
|
|
10
|
+
"react": "16.9.0",
|
|
11
|
+
"@momo-kits/core": ">=0.0.5-beta",
|
|
12
|
+
"lodash": "^4.17.15"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {},
|
|
15
|
+
"license": "MoMo"
|
|
16
|
+
}
|
package/publish.sh
CHANGED
|
@@ -12,7 +12,7 @@ echo VERSION: $VERSION
|
|
|
12
12
|
rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
|
|
13
13
|
|
|
14
14
|
# #babel component to dist
|
|
15
|
-
babel ./dist -d dist --copy-files
|
|
15
|
+
#babel ./dist -d dist --copy-files
|
|
16
16
|
|
|
17
17
|
#copy option
|
|
18
18
|
#cp -r ./src/ dist
|