mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
Add RangePickerState interface
This commit is contained in:
parent
191f0c41fc
commit
e22fbe70e5
@ -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<any, any> {
|
||||
export default class RangePicker extends React.Component<any, RangePickerState> {
|
||||
static defaultProps = {
|
||||
prefixCls: 'ant-calendar',
|
||||
allowClear: true,
|
||||
@ -97,7 +106,7 @@ export default class RangePicker extends React.Component<any, any> {
|
||||
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<any, any> {
|
||||
}
|
||||
}
|
||||
|
||||
handleShowDateChange = (showDate: boolean) => this.setState({ showDate });
|
||||
handleShowDateChange = (showDate: RangePickerValue) => this.setState({ showDate });
|
||||
|
||||
handleHoverChange = (hoverValue: any) => this.setState({ hoverValue });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user