From e22fbe70e5358dfd7f08803ca48bb35e1a99a495 Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Thu, 21 Dec 2017 17:06:59 +0800 Subject: [PATCH] Add RangePickerState interface --- components/date-picker/RangePicker.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/components/date-picker/RangePicker.tsx b/components/date-picker/RangePicker.tsx index 0b4b56ea0c..4fc8619dc6 100644 --- a/components/date-picker/RangePicker.tsx +++ b/components/date-picker/RangePicker.tsx @@ -8,6 +8,15 @@ import Icon from '../icon'; import warning from '../_util/warning'; 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 { const [start, end] = value; // value could be an empty array, then we should not reset showDate @@ -39,7 +48,7 @@ function isEmptyArray(arr: any) { return false; } -export default class RangePicker extends React.Component { +export default class RangePicker extends React.Component { static defaultProps = { prefixCls: 'ant-calendar', allowClear: true, @@ -97,7 +106,7 @@ export default class RangePicker extends React.Component { handleChange = (value: moment.Moment[]) => { const props = this.props; if (!('value' in props)) { - this.setState(({ showDate }: { showDate: boolean }) => ({ + this.setState(({ showDate }) => ({ value, showDate: getShowDateFromValue(value) || showDate, })); @@ -119,7 +128,7 @@ export default class RangePicker extends React.Component { } } - handleShowDateChange = (showDate: boolean) => this.setState({ showDate }); + handleShowDateChange = (showDate: RangePickerValue) => this.setState({ showDate }); handleHoverChange = (hoverValue: any) => this.setState({ hoverValue });