|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import moment from 'moment';
|
|
|
|
import MonthCalendar from 'rc-calendar/lib/MonthCalendar';
|
|
|
|
import RcDatePicker from 'rc-calendar/lib/Picker';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import omit from 'omit.js';
|
|
|
|
import assign from 'object-assign';
|
|
|
|
import Icon from '../icon';
|
|
|
|
import { getLocaleCode } from '../_util/getLocale';
|
|
|
|
import warning from '../_util/warning';
|
|
|
|
|
|
|
|
export interface PickerProps {
|
|
|
|
value?: moment.Moment;
|
|
|
|
prefixCls: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function createPicker(TheCalendar): any {
|
|
|
|
return class CalenderWrapper extends React.Component<any, any> {
|
|
|
|
static contextTypes = {
|
|
|
|
antLocale: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-calendar',
|
|
|
|
allowClear: true,
|
|
|
|
showToday: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
const value = props.value || props.defaultValue;
|
|
|
|
if (value && !moment.isMoment(value)) {
|
|
|
|
throw new Error(
|
|
|
|
'The value/defaultValue of DatePicker or MonthPicker must be ' +
|
|
|
|
'a moment object after `antd@2.0`, see: http://u.ant.design/date-picker-value',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
this.state = {
|
|
|
|
value,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps: PickerProps) {
|
|
|
|
if ('value' in nextProps) {
|
|
|
|
this.setState({
|
|
|
|
value: nextProps.value,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderFooter = (...args) => {
|
|
|
|
const { prefixCls, renderExtraFooter } = this.props;
|
|
|
|
return renderExtraFooter ? (
|
|
|
|
<div className={`${prefixCls}-footer-extra`}>
|
|
|
|
{renderExtraFooter(...args)}
|
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearSelection = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
this.handleChange(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange = (value) => {
|
|
|
|
const props = this.props;
|
|
|
|
if (!('value' in props)) {
|
|
|
|
this.setState({ value });
|
|
|
|
}
|
|
|
|
props.onChange(value, (value && value.format(props.format)) || '');
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { value } = this.state;
|
|
|
|
const props = omit(this.props, ['onChange']);
|
|
|
|
const { prefixCls, locale } = props;
|
|
|
|
|
|
|
|
const placeholder = ('placeholder' in props)
|
|
|
|
? props.placeholder : locale.lang.placeholder;
|
|
|
|
|
|
|
|
const disabledTime = props.showTime ? props.disabledTime : null;
|
|
|
|
|
|
|
|
const calendarClassName = classNames({
|
|
|
|
[`${prefixCls}-time`]: props.showTime,
|
|
|
|
[`${prefixCls}-month`]: MonthCalendar === TheCalendar,
|
|