2015-05-21 20:36:13 +08:00
|
|
|
require('rc-calendar/assets/index.css');
|
|
|
|
var React = require('react');
|
|
|
|
var Calendar = require('rc-calendar');
|
|
|
|
var DatePicker = Calendar.Picker;
|
|
|
|
var GregorianCalendar = require('gregorian-calendar');
|
|
|
|
var zhCn = require('gregorian-calendar/lib/locale/zh-cn');
|
2015-05-22 12:02:56 +08:00
|
|
|
var CalendarLocale = require('rc-calendar/lib/locale/zh-cn');
|
2015-05-25 17:20:49 +08:00
|
|
|
var DateTimeFormat = require('gregorian-calendar-format');
|
2015-05-21 20:36:13 +08:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
getInitialState: function () {
|
|
|
|
var value = new GregorianCalendar(zhCn);
|
|
|
|
value.setTime(Date.now());
|
|
|
|
return {
|
|
|
|
value: value
|
|
|
|
};
|
|
|
|
},
|
2015-05-25 17:20:49 +08:00
|
|
|
getDefaultProps: function () {
|
|
|
|
return {
|
|
|
|
format: 'yyyy-MM-dd'
|
|
|
|
};
|
|
|
|
},
|
2015-05-26 12:03:49 +08:00
|
|
|
componentDidMount: function () {
|
2015-05-29 15:06:45 +08:00
|
|
|
var state = {};
|
2015-05-26 12:03:49 +08:00
|
|
|
if (this.props.value) {
|
|
|
|
var value = new GregorianCalendar(zhCn);
|
|
|
|
value.setTime(new Date(this.props.value));
|
2015-05-29 15:06:45 +08:00
|
|
|
state.value = value;
|
2015-05-26 12:03:49 +08:00
|
|
|
}
|
2015-05-29 15:06:45 +08:00
|
|
|
state.disabled = this.props.disabled || function() {};
|
|
|
|
this.setState(state);
|
2015-05-26 12:03:49 +08:00
|
|
|
},
|
2015-05-26 13:58:35 +08:00
|
|
|
handleChange: function() {
|
|
|
|
var props = this.props;
|
|
|
|
this.props.onSelect(new Date(this.state.value.getTime()));
|
|
|
|
},
|
2015-05-21 20:36:13 +08:00
|
|
|
render: function () {
|
|
|
|
var calendar = (
|
|
|
|
<Calendar
|
2015-05-29 15:06:45 +08:00
|
|
|
disabledDate={this.state.disabled}
|
2015-05-22 12:02:56 +08:00
|
|
|
locale={CalendarLocale}
|
2015-05-21 20:36:13 +08:00
|
|
|
orient={['top', 'left']}
|
2015-05-25 18:30:06 +08:00
|
|
|
showClear={true} />
|
2015-05-21 20:36:13 +08:00
|
|
|
);
|
|
|
|
return (
|
|
|
|
<DatePicker
|
2015-05-26 16:19:07 +08:00
|
|
|
trigger={<span className="rc-calendar-picker-icon" />}
|
2015-05-28 14:53:23 +08:00
|
|
|
calendar={calendar}
|
|
|
|
formatter={new DateTimeFormat(this.props.format)}
|
|
|
|
value={this.state.value}
|
|
|
|
onChange={this.props.onSelect}>
|
2015-05-26 16:19:07 +08:00
|
|
|
<input className="rc-calendar-picker-input" />
|
2015-05-21 20:36:13 +08:00
|
|
|
</DatePicker>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|