ant-design/components/date-picker/index.tsx

99 lines
3.3 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import * as moment from 'moment';
import RcCalendar from 'rc-calendar';
2015-10-20 16:47:55 +08:00
import MonthCalendar from 'rc-calendar/lib/MonthCalendar';
2016-03-30 09:50:44 +08:00
import createPicker from './createPicker';
2016-03-30 10:52:15 +08:00
import wrapPicker from './wrapPicker';
import RangePicker from './RangePicker';
import WeekPicker from './WeekPicker';
import { TimePickerProps } from '../time-picker';
2015-08-25 17:27:38 +08:00
2016-09-13 15:31:29 +08:00
export interface PickerProps {
prefixCls?: string;
inputPrefixCls?: string;
format?: string;
disabled?: boolean;
allowClear?: boolean;
2017-06-27 15:32:18 +08:00
className?: string;
style?: React.CSSProperties;
popupStyle?: React.CSSProperties;
locale?: any;
size?: 'large' | 'small' | 'default';
getCalendarContainer?: (triggerNode: Element) => HTMLElement;
open?: boolean;
onOpenChange?: (status: boolean) => void;
disabledDate?: (current: moment.Moment) => boolean;
renderExtraFooter?: () => React.ReactNode;
dateRender?: (current: moment.Moment, today: moment.Moment) => React.ReactNode;
}
2016-09-13 15:31:29 +08:00
export interface SinglePickerProps {
value?: moment.Moment;
defaultValue?: moment.Moment;
defaultPickerValue?: moment.Moment;
onChange?: (date: moment.Moment, dateString: string) => void;
}
export interface DatePickerProps extends PickerProps, SinglePickerProps {
className?: string;
showTime?: TimePickerProps | boolean;
showToday?: boolean;
open?: boolean;
disabledTime?: (current: moment.Moment) => {
disabledHours?: () => number[],
disabledMinutes?: () => number[],
disabledSeconds?: () => number[],
};
2016-10-21 16:27:26 +08:00
onOpenChange?: (status: boolean) => void;
onOk?: (selectedTime: moment.Moment) => void;
2016-11-14 10:57:52 +08:00
placeholder?: string;
}
const DatePicker = wrapPicker(createPicker(RcCalendar)) as React.ClassicComponentClass<DatePickerProps>;
export interface MonthPickerProps extends PickerProps, SinglePickerProps {
className?: string;
2016-11-14 10:57:52 +08:00
placeholder?: string;
}
const MonthPicker = wrapPicker(createPicker(MonthCalendar), 'YYYY-MM');
export interface RangePickerProps extends PickerProps {
className?: string;
value?: [moment.Moment, moment.Moment];
defaultValue?: [moment.Moment, moment.Moment];
defaultPickerValue?: [moment.Moment, moment.Moment];
onChange?: (dates: [moment.Moment, moment.Moment], dateStrings: [string, string]) => void;
onCalendarChange?: (dates: [moment.Moment, moment.Moment], dateStrings: [string, string]) => void;
onOk?: (selectedTime: moment.Moment) => void;
showTime?: TimePickerProps | boolean;
ranges?: {
[range: string]: moment.Moment[],
};
2017-02-23 13:18:06 +08:00
placeholder?: [string, string];
mode?: string | string[];
disabledTime?: (current: moment.Moment, type: string) => {
disabledHours?: () => number[],
disabledMinutes?: () => number[],
disabledSeconds?: () => number[],
};
onPanelChange?: (value?: moment.Moment[], mode?: string | string[]) => void;
}
2015-08-24 14:30:08 +08:00
export interface WeexPickerProps extends PickerProps, SinglePickerProps {
className?: string;
placeholder?: string;
}
Object.assign(DatePicker, {
2017-07-06 23:06:21 +08:00
RangePicker: wrapPicker(RangePicker),
MonthPicker,
WeekPicker: wrapPicker(WeekPicker, 'YYYY-Wo'),
});
2015-08-24 14:30:08 +08:00
export interface DatePickerDecorator extends React.ClassicComponentClass<DatePickerProps> {
RangePicker: React.ClassicComponentClass<RangePickerProps>;
MonthPicker: React.ClassicComponentClass<MonthPickerProps>;
WeekPicker: React.ClassicComponentClass<WeexPickerProps>;
}
export default DatePicker as DatePickerDecorator;