|
@ -8,6 +8,15 @@ import Icon from '../icon'; |
|
|
import warning from '../_util/warning'; |
|
|
import warning from '../_util/warning'; |
|
|
import callMoment from '../_util/callMoment'; |
|
|
import callMoment from '../_util/callMoment'; |
|
|
|
|
|
|
|
|
|
|
|
type RangePickerValue = moment.Moment[]; |
|
|
|
|
|
|
|
|
|
|
|
export interface RangePickerState { |
|
|
|
|
|
value?: RangePickerValue; |
|
|
|
|
|
showDate?: RangePickerValue; |
|
|
|
|
|
open?: boolean; |
|
|
|
|
|
hoverValue?: RangePickerValue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function getShowDateFromValue(value: moment.Moment[]): moment.Moment[] | undefined { |
|
|
function getShowDateFromValue(value: moment.Moment[]): moment.Moment[] | undefined { |
|
|
const [start, end] = value; |
|
|
const [start, end] = value; |
|
|
// value could be an empty array, then we should not reset showDate
|
|
|
// value could be an empty array, then we should not reset showDate
|
|
@ -39,7 +48,7 @@ function isEmptyArray(arr: any) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export default class RangePicker extends React.Component<any, any> { |
|
|
export default class RangePicker extends React.Component<any, RangePickerState> { |
|
|
static defaultProps = { |
|
|
static defaultProps = { |
|
|
prefixCls: 'ant-calendar', |
|
|
prefixCls: 'ant-calendar', |
|
|
allowClear: true, |
|
|
allowClear: true, |
|
@ -97,7 +106,7 @@ export default class RangePicker extends React.Component<any, any> { |
|
|
handleChange = (value: moment.Moment[]) => { |
|
|
handleChange = (value: moment.Moment[]) => { |
|
|
const props = this.props; |
|
|
const props = this.props; |
|
|
if (!('value' in props)) { |
|
|
if (!('value' in props)) { |
|
|
this.setState(({ showDate }: { showDate: boolean }) => ({ |
|
|
this.setState(({ showDate }) => ({ |
|
|
value, |
|
|
value, |
|
|
showDate: getShowDateFromValue(value) || showDate, |
|
|
showDate: getShowDateFromValue(value) || showDate, |
|
|
})); |
|
|
})); |
|
@ -119,7 +128,7 @@ export default class RangePicker extends React.Component<any, any> { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
handleShowDateChange = (showDate: boolean) => this.setState({ showDate }); |
|
|
handleShowDateChange = (showDate: RangePickerValue) => this.setState({ showDate }); |
|
|
|
|
|
|
|
|
handleHoverChange = (hoverValue: any) => this.setState({ hoverValue }); |
|
|
handleHoverChange = (hoverValue: any) => this.setState({ hoverValue }); |
|
|
|
|
|
|
|
|