You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

'use strict';
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');
10 years ago
var CalendarLocale = require('rc-calendar/lib/locale/zh-cn');
10 years ago
var DateTimeFormat = require('gregorian-calendar-format');
10 years ago
// 和顶部文案保持一致
require('gregorian-calendar-format/lib/locale/zh-cn').shortMonths =
['1月', '2月', '3月', '4月', '5月', '6月',
'7月', '8月', '9月', '10月', '11月', '12月'];
10 years ago
var defaultCalendarValue = new GregorianCalendar(zhCn);
defaultCalendarValue.setTime(Date.now());
module.exports = React.createClass({
getInitialState: function () {
return {
value: ''
};
},
10 years ago
getDefaultProps: function () {
return {
format: 'yyyy-MM-dd',
placeholder: '请选择日期'
10 years ago
};
},
componentDidMount: function () {
var state = {};
if (this.props.value) {
var value = new GregorianCalendar(zhCn);
value.setTime(new Date(this.props.value));
state.value = value;
}
state.disabled = this.props.disabled || function() {};
this.setState(state);
},
handleChange: function() {
this.props.onSelect(new Date(this.state.value.getTime()));
},
render: function () {
var calendar = (
<Calendar
disabledDate={this.state.disabled}
10 years ago
locale={CalendarLocale}
orient={['top', 'left']}
10 years ago
defaultValue={defaultCalendarValue}
10 years ago
showTime={this.props.showTime}
prefixCls="ant-calendar"
showOk={this.props.showTime}
10 years ago
showClear={false} />
10 years ago
);
return (
<Datepicker
trigger={<span className="ant-calendar-picker-icon" />}
10 years ago
calendar={calendar}
formatter={new DateTimeFormat(this.props.format)}
value={this.state.value}
prefixCls="ant-calendar-picker"
10 years ago
onChange={this.props.onSelect}>
<input placeholder={this.props.placeholder} className="ant-calendar-picker-input" />
</Datepicker>
10 years ago
);
}
});