-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDatePicker.js
More file actions
51 lines (46 loc) · 1.36 KB
/
DatePicker.js
File metadata and controls
51 lines (46 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React from 'react';
import PropTypes from 'prop-types';
import { View, StyleSheet, Text } from 'react-native';
import ReactDatePicker from 'react-native-datepicker';
const DEFAULT_DATETIME_FORMAT = 'YYYY-MM-DD h:mm a';
const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD';
const CONFIRM_BUTTON_TEXT = 'Confirm';
const CANCEL_BUTTON_TEXT = 'Cancel';
export default function Datepicker(props) {
const {
name, value, meta, style, onChangeInputValue, isMandatory
} = props;
return (
<View style={style}>
<Text style={styles.text}>{`${meta.text || meta.title} ${isMandatory ? '*' : ''}`}</Text>
<ReactDatePicker
key={name}
style={styles.date}
date={value}
mode={meta.isDateTime ? "datetime" : "date"}
format={meta.isDateTime ? DEFAULT_DATETIME_FORMAT : DEFAULT_DATE_FORMAT}
confirmBtnText={CONFIRM_BUTTON_TEXT}
cancelBtnText={CANCEL_BUTTON_TEXT}
onDateChange={onChangeInputValue}
disabled={meta.disabled === true ? true : false}
/>
</View>
);
}
const styles = StyleSheet.create({
text: {
margin: 10,
},
date: {
width: '97%',
marginLeft: 10,
},
});
Datepicker.propTypes = {
name: PropTypes.string.isRequired,
meta: PropTypes.object.isRequired,
value: PropTypes.string,
style: PropTypes.object,
onChangeInputValue: PropTypes.func,
isMandatory: PropTypes.bool
};