forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatePicker.js
More file actions
63 lines (55 loc) · 1.5 KB
/
DatePicker.js
File metadata and controls
63 lines (55 loc) · 1.5 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
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react';
import DateTimePicker from '@react-native-community/datetimepicker';
import variable from '../theme/variables/platform';
export class DatePicker extends React.Component {
static defaultProps = {
disabled: false
};
constructor(props) {
super(props);
this.state = {
defaultDate: props.defaultDate ? props.defaultDate : new Date(),
chosenDate:
!props.placeHolderText && props.defaultDate
? props.defaultDate
: undefined
};
}
setDate(date) {
this.setState({ chosenDate: new Date(date) });
if (this.props.onDateChange) {
this.props.onDateChange(date);
}
}
formatChosenDate(date) {
if (this.props.formatChosenDate) {
return this.props.formatChosenDate(date);
}
return [date.getDate(), date.getMonth() + 1, date.getFullYear()].join('/');
}
render() {
const {
locale,
maximumDate,
minimumDate,
timeZoneOffsetInMinutes
} = this.props;
const variables = this.context.theme
? this.context.theme['@@shoutem.theme/themeStyle'].variables
: variable;
return (
<DateTimePicker
date={
this.state.chosenDate ? this.state.chosenDate : this.state.defaultDate
}
onDateChange={date => this.setDate(date)}
minimumDate={minimumDate}
maximumDate={maximumDate}
mode="date"
locale={locale}
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
{...this.props}
/>
);
}
}