@momo-kits/date-picker 0.0.65-alpha.20 → 0.0.65-alpha.23

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,136 +1,139 @@
1
1
  import PropTypes from 'prop-types';
2
- import React, {useState} from 'react';
3
- import {StyleSheet} from 'react-native';
4
- import {isEmpty} from 'lodash';
2
+ import React, { useState } from 'react';
3
+ import { StyleSheet } from 'react-native';
4
+ import { isEmpty } from 'lodash';
5
5
  import {
6
- IconSource,
7
- TouchableOpacity,
8
- Text,
9
- Colors,
10
- ValueUtil,
11
- Image,
12
- Radius,
13
- } from '@momo-kits/core-v2';
6
+ IconSource,
7
+ TouchableOpacity,
8
+ Text,
9
+ Colors,
10
+ ValueUtil,
11
+ Image,
12
+ } from '@momo-kits/core';
14
13
  import DatePicker from './DatePicker';
15
14
 
16
15
  const DatePickerInput = ({
17
- navigator,
18
- defaultDate,
19
- maxDate,
20
- minDate,
21
- format = 'dd/MM/YYYY',
22
- onSelected,
23
- onClose,
24
- style,
25
- textStyle,
26
- icon,
27
- iconStyle,
28
- error,
29
- disabled,
30
- minuteArray,
31
- title,
32
- showRightIcon,
16
+ navigator,
17
+ defaultDate,
18
+ maxDate,
19
+ minDate,
20
+ format = 'dd/MM/YYYY',
21
+ onSelected,
22
+ onClose,
23
+ style,
24
+ textStyle,
25
+ icon,
26
+ iconStyle,
27
+ error,
28
+ disabled,
29
+ minuteArray,
30
+ title,
31
+ showRightIcon,
33
32
  }) => {
34
- const [selected, setSelected] = useState(defaultDate || '');
33
+ const [selected, setSelected] = useState(defaultDate || '');
35
34
 
36
- const onPress = () => {
37
- navigator?.showBottom?.({
38
- screen: DatePicker,
39
- params: {
40
- dragDisabled: true,
41
- minDate,
42
- maxDate,
43
- format,
44
- title,
45
- selectedDate: selected,
46
- onClose,
47
- minuteArray,
48
- onSelected: dateSelected => {
49
- onSelected?.(dateSelected);
50
- setSelected(dateSelected);
51
- },
52
- },
53
- });
54
- };
55
- let otherStyle = {};
56
- if (error) otherStyle = styles.error;
57
- if (disabled) otherStyle = styles.disabled;
35
+ const onPress = () => {
36
+ navigator?.showBottom?.({
37
+ screen: DatePicker,
38
+ params: {
39
+ dragDisabled: true,
40
+ minDate,
41
+ maxDate,
42
+ format,
43
+ title,
44
+ selectedDate: selected,
45
+ onClose,
46
+ minuteArray,
47
+ onSelected: (dateSelected) => {
48
+ onSelected?.(dateSelected);
49
+ setSelected(dateSelected);
50
+ },
51
+ },
52
+ });
53
+ };
54
+ let otherStyle = {};
55
+ if (error) otherStyle = styles.error;
56
+ if (disabled) otherStyle = styles.disabled;
58
57
 
59
- return (
60
- <TouchableOpacity
61
- disabled={disabled}
62
- onPress={onPress}
63
- style={[styles.container, ValueUtil.extractStyle(style), otherStyle]}>
64
- <Text.Paragraph
65
- style={[
66
- styles.defaultText,
67
- ValueUtil.extractStyle(textStyle),
68
- isEmpty(selected) ? {color: Colors.black_09} : {},
69
- ]}>
70
- {isEmpty(selected) ? format : selected}
71
- </Text.Paragraph>
72
- {showRightIcon ? (
73
- <Image
74
- source={icon || IconSource.ic_calendar}
75
- style={[styles.icon, ValueUtil.extractStyle(iconStyle)]}
76
- />
77
- ) : (
78
- <View />
79
- )}
80
- </TouchableOpacity>
81
- );
58
+ return (
59
+ <TouchableOpacity
60
+ disabled={disabled}
61
+ onPress={onPress}
62
+ style={[
63
+ styles.container,
64
+ ValueUtil.extractStyle(style),
65
+ otherStyle,
66
+ ]}>
67
+ <Text.Title
68
+ style={[
69
+ styles.defaultText,
70
+ ValueUtil.extractStyle(textStyle),
71
+ isEmpty(selected) ? { color: Colors.black_09 } : {},
72
+ ]}>
73
+ {isEmpty(selected) ? format : selected}
74
+ </Text.Title>
75
+ {showRightIcon ? (
76
+ <Image
77
+ source={icon || IconSource.ic_calendar}
78
+ style={[styles.icon, ValueUtil.extractStyle(iconStyle)]}
79
+ />
80
+ ) : (
81
+ <View />
82
+ )}
83
+ </TouchableOpacity>
84
+ );
82
85
  };
83
86
 
84
87
  DatePickerInput.propTypes = {
85
- defaultDate: PropTypes.string,
86
- format: PropTypes.oneOf(['hh:mm', 'MM/YYYY', 'dd/MM', 'dd/MM/YYYY']),
87
- icon: PropTypes.any,
88
- maxDate: PropTypes.string,
89
- minDate: PropTypes.string,
90
- navigator: PropTypes.object,
91
- onClose: PropTypes.func,
92
- onSelected: PropTypes.func,
93
- iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
94
- style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
95
- textStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
96
- error: PropTypes.bool,
97
- disabled: PropTypes.bool,
98
- minuteArray: PropTypes.arrayOf(PropTypes.string),
99
- showRightIcon: PropTypes.bool,
100
- title: PropTypes.string,
88
+ defaultDate: PropTypes.string,
89
+ format: PropTypes.oneOf(['hh:mm', 'MM/YYYY', 'dd/MM', 'dd/MM/YYYY']),
90
+ icon: PropTypes.any,
91
+ maxDate: PropTypes.string,
92
+ minDate: PropTypes.string,
93
+ navigator: PropTypes.object,
94
+ onClose: PropTypes.func,
95
+ onSelected: PropTypes.func,
96
+ iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
97
+ style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
98
+ textStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
99
+ error: PropTypes.bool,
100
+ disabled: PropTypes.bool,
101
+ minuteArray: PropTypes.arrayOf(PropTypes.string),
102
+ showRightIcon: PropTypes.bool,
103
+ title: PropTypes.string,
101
104
  };
102
105
  DatePickerInput.defaultProps = {
103
- showRightIcon: true,
106
+ showRightIcon: true,
104
107
  };
105
108
 
106
109
  export default DatePickerInput;
107
110
 
108
111
  const styles = StyleSheet.create({
109
- icon: {
110
- width: 16,
111
- height: 16,
112
- resizeMode: 'contain',
113
- tintColor: Colors.black_09,
114
- },
115
- container: {
116
- flexDirection: 'row',
117
- height: 42,
118
- borderRadius: Radius.S,
119
- borderColor: Colors.black_06,
120
- borderWidth: 1,
121
- alignItems: 'center',
122
- justifyContent: 'space-between',
123
- paddingHorizontal: 12,
124
- backgroundColor: Colors.black_01,
125
- },
126
- error: {
127
- borderColor: Colors.red_03,
128
- },
129
- defaultText: {
130
- // fontSize: 14
131
- },
132
- disabled: {
133
- backgroundColor: Colors.black_05,
134
- borderWidth: 0,
135
- },
112
+ icon: {
113
+ width: 16,
114
+ height: 16,
115
+ resizeMode: 'contain',
116
+ tintColor: Colors.black_09,
117
+ },
118
+ container: {
119
+ flexDirection: 'row',
120
+ height: 42,
121
+ borderRadius: 4,
122
+ borderColor: Colors.black_06,
123
+ borderWidth: 1,
124
+ alignItems: 'center',
125
+ justifyContent: 'space-between',
126
+ paddingHorizontal: 12,
127
+ backgroundColor: Colors.black_01,
128
+ },
129
+ error: {
130
+ borderColor: Colors.red_05,
131
+ },
132
+ defaultText: {
133
+ // fontSize: 14
134
+ },
135
+ disabled: {
136
+ backgroundColor: Colors.black_05,
137
+ borderWidth: 0,
138
+ },
136
139
  });
@@ -1,208 +1,197 @@
1
- import React, {Component} from 'react';
2
- import {Dimensions, StyleSheet, View} from 'react-native';
1
+ import React, { Component } from 'react';
2
+ import { Dimensions, StyleSheet, View } from 'react-native';
3
3
  import {
4
- Button,
5
- IconSource,
6
- TouchableOpacity,
7
- Text,
8
- Colors,
9
- Image,
10
- DeviceUtils,
11
- SwitchLanguage,
12
- } from '@momo-kits/core-v2';
4
+ Button,
5
+ IconSource,
6
+ TouchableOpacity,
7
+ Text,
8
+ Colors,
9
+ Image,
10
+ DeviceUtils,
11
+ SwitchLanguage,
12
+ } from '@momo-kits/core';
13
13
  import WheelPicker from './WheelPicker';
14
14
 
15
- const {isIphoneX} = DeviceUtils;
15
+ const { isIphoneX } = DeviceUtils;
16
16
 
17
17
  const widthScreen = Dimensions.get('window').width;
18
18
 
19
19
  export default class ListPicker extends Component {
20
- constructor(props) {
21
- super(props);
22
- this.data = 0;
23
- }
24
-
25
- hide = () => {
26
- const {onClose, requestClose} = this.props;
27
- if (requestClose && typeof requestClose === 'function') {
28
- requestClose(() => {
29
- if (onClose && typeof onClose === 'function') {
30
- onClose();
31
- }
32
- });
33
- }
34
- };
35
-
36
- onBeginDrag = () => {
37
- if (this.refs.picker) {
38
- this.refs.picker.setScrollEnabled(false);
39
- }
40
- };
41
-
42
- onEndDrag = () => {
43
- if (this.refs.picker) {
44
- this.refs.picker.setScrollEnabled(true);
20
+ constructor(props) {
21
+ super(props);
22
+ this.data = 0;
45
23
  }
46
- };
47
24
 
48
- onChangeValue = value => {
49
- const {callback} = this.props;
50
- if (typeof callback === 'function') {
51
- callback(value);
52
- }
53
- };
25
+ hide = () => {
26
+ const { onClose, requestClose } = this.props;
27
+ if (requestClose && typeof requestClose === 'function') {
28
+ requestClose(() => {
29
+ if (onClose && typeof onClose === 'function') {
30
+ onClose();
31
+ }
32
+ });
33
+ }
34
+ };
54
35
 
55
- onPressClear = () => {
56
- this.hide();
57
- };
36
+ onBeginDrag = () => {
37
+ if (this.refs.picker) {
38
+ this.refs.picker.setScrollEnabled(false);
39
+ }
40
+ };
58
41
 
59
- onPressChoose = () => {
60
- this.onChangeValue(this.data);
61
- this.hide();
62
- };
42
+ onEndDrag = () => {
43
+ if (this.refs.picker) {
44
+ this.refs.picker.setScrollEnabled(true);
45
+ }
46
+ };
63
47
 
64
- renderRight = () => (
65
- <TouchableOpacity onPress={this.onPressChoose}>
66
- <Text.Paragraph
67
- style={{
68
- fontWeight: 'bold',
69
- color: Colors.pink_05,
70
- }}>
71
- {SwitchLanguage.save}
72
- </Text.Paragraph>
73
- </TouchableOpacity>
74
- );
48
+ onChangeValue = (value) => {
49
+ const { callback } = this.props;
50
+ if (typeof callback === 'function') {
51
+ callback(value);
52
+ }
53
+ };
75
54
 
76
- renderLeftIcon = () => (
77
- <TouchableOpacity onPress={() => this.hide()}>
78
- <Image
79
- source={IconSource.ic_close_x_24}
80
- style={{
81
- width: 25,
82
- height: 25,
83
- tintColor: Colors.black_17,
84
- }}
85
- />
86
- </TouchableOpacity>
87
- );
55
+ onPressClear = () => {
56
+ this.hide();
57
+ };
88
58
 
89
- renderHeader() {
90
- const {title = ''} = this.props;
91
- return (
92
- <View style={styles.header}>
93
- {this.renderLeftIcon()}
94
- <Text style={styles.title}>{title}</Text>
95
- {this.props.typeStyle === 'aboveAction' ? (
96
- this.renderRight()
97
- ) : (
98
- <View style={{width: 25}} />
99
- )}
100
- </View>
101
- );
102
- }
59
+ onPressChoose = () => {
60
+ this.onChangeValue(this.data);
61
+ this.hide();
62
+ };
103
63
 
104
- renderContent() {
105
- const {arrData = [], stylePicker, initValue} = this.props;
106
- return (
107
- <View style={styles.contentStyle}>
108
- <WheelPicker
109
- stylePicker={stylePicker}
110
- bottomOffset={1}
111
- value={initValue}
112
- key="picker"
113
- ref="picker"
114
- arrayValue={arrData}
115
- onBeginDrag={this.onBeginDrag}
116
- onEndDrag={this.onEndDrag}
117
- onValueChange={value => {
118
- this.data = value;
119
- }}
120
- />
121
- </View>
64
+ renderRight = () => (
65
+ <TouchableOpacity onPress={this.onPressChoose}>
66
+ <Text.Title style={{ fontWeight: 'bold', color: Colors.pink_05 }}>
67
+ {SwitchLanguage.save}
68
+ </Text.Title>
69
+ </TouchableOpacity>
122
70
  );
123
- }
124
71
 
125
- render() {
126
- return (
127
- <View style={styles.view}>
128
- {this.renderHeader()}
129
- {this.renderContent()}
130
- {this.props.typeStyle === 'aboveAction' ? null : (
131
- <View style={styles.btnView}>
132
- <Button
133
- style={{flex: 1}}
134
- title={SwitchLanguage.cancel}
135
- buttonStyle={{
136
- backgroundColor: Colors.second_text_color,
137
- }}
138
- onPress={this.onPressClear}
139
- />
140
- <Button
141
- style={{
142
- flex: 1,
143
- marginLeft: 15,
144
- }}
145
- title={SwitchLanguage.choose}
146
- type="primary"
147
- onPress={this.onPressChoose}
72
+ renderLeftIcon = () => (
73
+ <TouchableOpacity onPress={() => this.hide()}>
74
+ <Image
75
+ source={IconSource.ic_close_x_24}
76
+ style={{ width: 25, height: 25, tintColor: Colors.black_17 }}
148
77
  />
149
- </View>
150
- )}
151
- </View>
78
+ </TouchableOpacity>
152
79
  );
153
- }
80
+
81
+ renderHeader() {
82
+ const { title = '' } = this.props;
83
+ return (
84
+ <View style={styles.header}>
85
+ {this.renderLeftIcon()}
86
+ <Text style={styles.title}>{title}</Text>
87
+ {this.props.typeStyle === 'aboveAction' ? (
88
+ this.renderRight()
89
+ ) : (
90
+ <View style={{ width: 25 }} />
91
+ )}
92
+ </View>
93
+ );
94
+ }
95
+
96
+ renderContent() {
97
+ const { arrData = [], stylePicker, initValue } = this.props;
98
+ return (
99
+ <View style={styles.contentStyle}>
100
+ <WheelPicker
101
+ stylePicker={stylePicker}
102
+ bottomOffset={1}
103
+ value={initValue}
104
+ key="picker"
105
+ ref="picker"
106
+ arrayValue={arrData}
107
+ onBeginDrag={this.onBeginDrag}
108
+ onEndDrag={this.onEndDrag}
109
+ onValueChange={(value) => {
110
+ this.data = value;
111
+ }}
112
+ />
113
+ </View>
114
+ );
115
+ }
116
+
117
+ render() {
118
+ return (
119
+ <View style={styles.view}>
120
+ {this.renderHeader()}
121
+ {this.renderContent()}
122
+ {this.props.typeStyle === 'aboveAction' ? null : (
123
+ <View style={styles.btnView}>
124
+ <Button
125
+ style={{ flex: 1 }}
126
+ title={SwitchLanguage.cancel}
127
+ buttonStyle={{
128
+ backgroundColor: Colors.second_text_color,
129
+ }}
130
+ onPress={this.onPressClear}
131
+ />
132
+ <Button
133
+ style={{ flex: 1, marginLeft: 15 }}
134
+ title={SwitchLanguage.choose}
135
+ type="primary"
136
+ onPress={this.onPressChoose}
137
+ />
138
+ </View>
139
+ )}
140
+ </View>
141
+ );
142
+ }
154
143
  }
155
144
 
156
145
  const styles = StyleSheet.create({
157
- container: {
158
- flexDirection: 'row',
159
- width: widthScreen,
160
- alignItems: 'center',
161
- justifyContent: 'center',
162
- },
163
- contentStyle: {
164
- height: 230,
165
- },
166
- column: {
167
- borderWidth: 2,
168
- borderColor: 'red',
169
- },
170
- header: {
171
- flexDirection: 'row',
172
- height: 50,
173
- width: widthScreen,
174
- paddingHorizontal: 16,
175
- alignItems: 'center',
176
- justifyContent: 'space-between',
177
- backgroundColor: '#fff',
178
- borderBottomWidth: 1,
179
- borderColor: '#DADADA',
180
- },
181
- view: {
182
- backgroundColor: 'white',
183
- paddingBottom: 10 + (isIphoneX() ? 10 : 0),
184
- },
185
- title: {
186
- fontWeight: 'bold',
187
- color: Colors.black_17,
188
- flex: 1,
189
- fontSize: 16,
190
- textAlign: 'center',
191
- },
192
- titleCancel: {
193
- fontSize: 17,
194
- color: '#4A90E2',
195
- },
196
- titleConfirm: {
197
- fontSize: 17,
198
- color: '#4A90E2',
199
- textAlign: 'right',
200
- },
201
- btnView: {
202
- flexDirection: 'row',
203
- justifyContent: 'space-between',
204
- marginHorizontal: 15,
205
- height: 60,
206
- alignItems: 'center',
207
- },
146
+ container: {
147
+ flexDirection: 'row',
148
+ width: widthScreen,
149
+ alignItems: 'center',
150
+ justifyContent: 'center',
151
+ },
152
+ contentStyle: {
153
+ height: 230,
154
+ },
155
+ column: {
156
+ borderWidth: 2,
157
+ borderColor: 'red',
158
+ },
159
+ header: {
160
+ flexDirection: 'row',
161
+ height: 50,
162
+ width: widthScreen,
163
+ paddingHorizontal: 16,
164
+ alignItems: 'center',
165
+ justifyContent: 'space-between',
166
+ backgroundColor: '#fff',
167
+ borderBottomWidth: 1,
168
+ borderColor: '#DADADA',
169
+ },
170
+ view: {
171
+ backgroundColor: 'white',
172
+ paddingBottom: 10 + (isIphoneX() ? 10 : 0),
173
+ },
174
+ title: {
175
+ fontWeight: 'bold',
176
+ color: Colors.black_17,
177
+ flex: 1,
178
+ fontSize: 16,
179
+ textAlign: 'center',
180
+ },
181
+ titleCancel: {
182
+ fontSize: 17,
183
+ color: '#4A90E2',
184
+ },
185
+ titleConfirm: {
186
+ fontSize: 17,
187
+ color: '#4A90E2',
188
+ textAlign: 'right',
189
+ },
190
+ btnView: {
191
+ flexDirection: 'row',
192
+ justifyContent: 'space-between',
193
+ marginHorizontal: 15,
194
+ height: 60,
195
+ alignItems: 'center',
196
+ },
208
197
  });