DatePicker.js
1.2 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
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import moment from 'moment';
import DateTimeField from './datetime/DateTimeField';
import cx from 'classnames';
import s from './Custom.scss';
class DatePicker extends React.Component {
constructor(props) {
super(props);
this.onChange=this.onChange.bind(this);
this.state={
today:new Date()
}
}
static propTypes = {
'onChange':PropTypes.func,
'defaultValue':PropTypes.string
}
static defaultProps={
defaultValue:'',
onChange: (x) => {
console.log(x);
}
}
onChange(data){
const {onChange}=this.props;
onChange(data);
}
render(){
const {today}=this.state;
const {defaultValue}=this.props;
const value=moment(defaultValue).isValid()?moment(defaultValue).format('x'):moment(today).format('x');
return (
<div className={cx(s.datetime_picker_wrap)}>
<DateTimeField dateTime={value} mode='date' onChange={this.onChange} />
</div>)
}
}
export default DatePicker;