ant-design/components/datepicker/index.jsx

48 lines
1.3 KiB
React
Raw Normal View History

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 () {
if (this.props.value) {
var value = new GregorianCalendar(zhCn);
value.setTime(new Date(this.props.value));
this.setState({value: value});
}
},
2015-05-21 20:36:13 +08:00
render: function () {
var state = this.state;
2015-05-25 17:20:49 +08:00
var formatter = new DateTimeFormat(this.props.format);
2015-05-21 20:36:13 +08:00
var calendar = (
<Calendar
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-25 17:20:49 +08:00
formatter={formatter} calendar={calendar}
2015-05-21 20:36:13 +08:00
value={this.state.value} onChange={this.handleChange}>
<input type="text" className="datepicker-input" />
</DatePicker>
);
}
});