mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-01 05:06:53 +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 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 });
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user