UNPKG

14.2 kBTypeScriptView Raw
1/// <reference types="react" />
2import type { AlignType, BuildInPlacements } from '@rc-component/trigger';
3import type { GenerateConfig } from './generate';
4export type NullableDateType<DateType> = DateType | null | undefined;
5export type Locale = {
6 locale: string;
7 /** @deprecated Please use `fieldDateFormat` instead */
8 dateFormat?: string;
9 /** @deprecated Please use `fieldDateTimeFormat` instead */
10 dateTimeFormat?: string;
11 /** Input field formatter like YYYY-MM-DD HH:mm:ss */
12 fieldDateTimeFormat?: string;
13 /** Input field formatter like YYYY-MM-DD */
14 fieldDateFormat?: string;
15 /** Input field formatter like HH:mm:ss */
16 fieldTimeFormat?: string;
17 /** Input field formatter like YYYY-MM */
18 fieldMonthFormat?: string;
19 /** Input field formatter like YYYY */
20 fieldYearFormat?: string;
21 /** Input field formatter like wwww-go */
22 fieldWeekFormat?: string;
23 /** Input field formatter like YYYY-Q */
24 fieldQuarterFormat?: string;
25 /** Display month before year in date panel header */
26 monthBeforeYear?: boolean;
27 /** year format in header panel */
28 yearFormat?: string;
29 /** month format in header panel */
30 monthFormat?: string;
31 /** year format in body panel */
32 cellYearFormat?: string;
33 /** quarter format in body panel */
34 cellQuarterFormat?: string;
35 /** @deprecated Please use `cellDateFormat` instead */
36 dayFormat?: string;
37 /** day format in body panel */
38 cellDateFormat?: string;
39 /** meridiem format in body panel */
40 cellMeridiemFormat?: string;
41 today: string;
42 now: string;
43 backToToday: string;
44 ok: string;
45 timeSelect: string;
46 dateSelect: string;
47 weekSelect?: string;
48 clear: string;
49 month: string;
50 year: string;
51 previousMonth: string;
52 nextMonth: string;
53 monthSelect: string;
54 yearSelect: string;
55 decadeSelect: string;
56 previousYear: string;
57 nextYear: string;
58 previousDecade: string;
59 nextDecade: string;
60 previousCentury: string;
61 nextCentury: string;
62 shortWeekDays?: string[];
63 shortMonths?: string[];
64};
65export type PanelMode = 'time' | 'date' | 'week' | 'month' | 'quarter' | 'year' | 'decade';
66export type InternalMode = PanelMode | 'datetime';
67export type PickerMode = Exclude<PanelMode, 'datetime' | 'decade'>;
68export type DisabledDate<DateType = any> = (date: DateType, info: {
69 type: PanelMode;
70 /**
71 * Only work in RangePicker.
72 * Tell the first date user selected on this range selection.
73 * This is not care about what field user click.
74 */
75 from?: DateType;
76}) => boolean;
77export interface BaseInfo {
78 range?: 'start' | 'end';
79}
80export interface CellRenderInfo<DateType> extends BaseInfo {
81 prefixCls: string;
82 originNode: React.ReactElement;
83 today: DateType;
84 type: PanelMode;
85 locale?: Locale;
86 subType?: 'hour' | 'minute' | 'second' | 'millisecond' | 'meridiem';
87}
88export type CellRender<DateType, CurrentType = DateType | number | string> = (current: CurrentType, info: CellRenderInfo<DateType>) => React.ReactNode;
89export interface ValueDate<DateType = any> {
90 label: React.ReactNode;
91 value: DateType | (() => DateType);
92}
93export interface DisabledTimes {
94 disabledHours?: () => number[];
95 disabledMinutes?: (hour: number) => number[];
96 disabledSeconds?: (hour: number, minute: number) => number[];
97 disabledMilliseconds?: (hour: number, minute: number, second: number) => number[];
98}
99export interface SharedTimeProps<DateType extends object = any> {
100 /** Only work in picker is `time` */
101 format?: string;
102 /** Only work in picker is `time` */
103 showNow?: boolean;
104 /** Only work in picker is `time` */
105 showHour?: boolean;
106 /** Only work in picker is `time` */
107 showMinute?: boolean;
108 /** Only work in picker is `time` */
109 showSecond?: boolean;
110 /** Only work in picker is `time` */
111 showMillisecond?: boolean;
112 /** Only work in picker is `time` */
113 use12Hours?: boolean;
114 /** Only work in picker is `time` */
115 hourStep?: IntRange<1, 23>;
116 /** Only work in picker is `time` */
117 minuteStep?: IntRange<1, 59>;
118 /** Only work in picker is `time` */
119 secondStep?: IntRange<1, 59>;
120 /**
121 * Only work in picker is `time`.
122 * Note that too small step will cause performance issue.
123 */
124 millisecondStep?: IntRange<1, 999>;
125 /** Only work in picker is `time` */
126 hideDisabledOptions?: boolean;
127 /** @deprecated Use `defaultOpenValue` instead */
128 defaultValue?: DateType;
129 /** Set default value template when empty selection */
130 defaultOpenValue?: DateType;
131 /** @deprecated Please use `disabledTime` instead. */
132 disabledHours?: DisabledTimes['disabledHours'];
133 /** @deprecated Please use `disabledTime` instead. */
134 disabledMinutes?: DisabledTimes['disabledMinutes'];
135 /** @deprecated Please use `disabledTime` instead. */
136 disabledSeconds?: DisabledTimes['disabledSeconds'];
137 /** Only work in picker is `time` */
138 disabledTime?: (date: DateType, range?: 'start' | 'end') => DisabledTimes;
139 /** Only work in picker is `time` */
140 changeOnScroll?: boolean;
141}
142export type RangeTimeProps<DateType extends object = any> = Omit<SharedTimeProps<DateType>, 'defaultValue' | 'defaultOpenValue'> & {
143 /** @deprecated Use `defaultOpenValue` instead. */
144 defaultValue?: DateType[];
145 defaultOpenValue?: DateType[];
146};
147export type OnPanelChange<DateType> = (value: DateType, mode: PanelMode) => void;
148export type LimitDate<DateType extends object = any> = DateType | ((info: {
149 /**
150 * Tell the first date user selected on this range selection.
151 * This is not care about what field user click.
152 */
153 from?: DateType;
154}) => DateType | null | undefined);
155export interface SharedPanelProps<DateType extends object = any> {
156 prefixCls: string;
157 locale: Locale;
158 generateConfig: GenerateConfig<DateType>;
159 pickerValue: DateType;
160 onPickerValueChange: (date: DateType) => void;
161 value?: DateType;
162 /**
163 * Should trigger when user select the cell.
164 * PickerPanel will mark as `value` in single mode,
165 * Or toggle `values` in multiple mode.
166 */
167 onSelect: (date: DateType) => void;
168 /**
169 * Used for `multiple` mode.
170 * When not `multiple`, it will be `[value]`.
171 */
172 values?: DateType[];
173 onModeChange: (mode: PanelMode, date?: DateType) => void;
174 disabledDate?: DisabledDate<DateType>;
175 minDate?: DateType;
176 maxDate?: DateType;
177 cellRender?: CellRender<DateType>;
178 /** @private Only used for RangePicker passing. */
179 hoverRangeValue: [start: DateType, end: DateType] | null;
180 /** @private Only used for SinglePicker passing. */
181 hoverValue: DateType[] | null;
182 onHover?: (value: DateType | null) => void;
183 /**
184 * Only used for `date` mode.
185 */
186 showTime?: SharedTimeProps<DateType>;
187 /**
188 * Only used for `date` mode.
189 */
190 showWeek?: boolean;
191 prevIcon?: React.ReactNode;
192 nextIcon?: React.ReactNode;
193 superPrevIcon?: React.ReactNode;
194 superNextIcon?: React.ReactNode;
195}
196export type Components<DateType extends object = any> = Partial<Record<InternalMode, React.ComponentType<SharedPanelProps<DateType>>> & {
197 button?: React.ComponentType<any> | string;
198 input?: React.ComponentType<any> | string;
199}>;
200export type SemanticStructure = 'popup';
201export type CustomFormat<DateType> = (value: DateType) => string;
202export type FormatType<DateType = any> = string | CustomFormat<DateType>;
203export type SharedHTMLAttrs = Omit<React.InputHTMLAttributes<HTMLDivElement>, 'value' | 'defaultValue' | 'onChange' | 'placeholder' | 'id' | 'onInvalid' | 'disabled' | 'onFocus' | 'onBlur' | 'onSelect' | 'min' | 'max' | 'onKeyDown' | 'size'>;
204export type PickerFocusEventHandler = (e: React.FocusEvent<HTMLElement>, info: BaseInfo) => void;
205export type LegacyOnKeyDown = (event: React.KeyboardEvent<HTMLElement>, preventDefault: VoidFunction) => void;
206export interface SharedPickerProps<DateType extends object = any> extends SharedHTMLAttrs, Pick<SharedPanelProps<DateType>, 'prevIcon' | 'nextIcon' | 'superPrevIcon' | 'superNextIcon'> {
207 direction?: 'ltr' | 'rtl';
208 prefixCls?: string;
209 className?: string;
210 style?: React.CSSProperties;
211 styles?: Partial<Record<SemanticStructure, React.CSSProperties>>;
212 classNames?: Partial<Record<SemanticStructure, string>>;
213 locale: Locale;
214 generateConfig: GenerateConfig<DateType>;
215 picker?: PickerMode;
216 /** Only work when picker is `date` or `time` */
217 showTime?: boolean | SharedTimeProps<DateType>;
218 /** Only work when picker is `date` */
219 showWeek?: boolean;
220 /**
221 * Config the input field parse and format.
222 * When set `format.type`, it will force user input type with your input,
223 * it's only support basic format mask: YYYY, MM, DD, HH, mm, ss, SSS.
224 * Once use config mode, it must be fill with format your config.
225 */
226 format?: FormatType<DateType> | FormatType<DateType>[] | {
227 format: string;
228 type?: 'mask';
229 };
230 suffixIcon?: React.ReactNode;
231 allowClear?: boolean | {
232 clearIcon?: React.ReactNode;
233 };
234 /** @deprecated Please use `allowClear.clearIcon` instead */
235 clearIcon?: React.ReactNode;
236 onFocus?: PickerFocusEventHandler;
237 onBlur?: PickerFocusEventHandler;
238 /** `preventDefault` is deprecated which will remove from future version. */
239 onKeyDown?: LegacyOnKeyDown;
240 inputReadOnly?: boolean;
241 /** Default will always order of selection after submit */
242 order?: boolean;
243 disabledDate?: DisabledDate<DateType>;
244 /** Limit the selectable range. This will limit picker navigation also */
245 minDate?: DateType;
246 /** Limit the selectable range. This will limit picker navigation also */
247 maxDate?: DateType;
248 defaultOpenValue?: DateType;
249 defaultOpen?: boolean;
250 open?: boolean;
251 onOpenChange?: (open: boolean) => void;
252 popupAlign?: AlignType;
253 getPopupContainer?: (node: HTMLElement) => HTMLElement;
254 placement?: string;
255 builtinPlacements?: BuildInPlacements;
256 /**
257 * By default. Only `time` or `datetime` show the confirm button in panel.
258 * `true` to make every picker need confirm.
259 * `false` to trigger change on every time panel closed by the mode = picker.
260 */
261 needConfirm?: boolean;
262 /**
263 * @deprecated. This is removed and not work anymore.
264 * Value will always be update if user type correct date type.
265 * You can use `needConfirm` for confirm requirement.
266 */
267 changeOnBlur?: boolean;
268 /**
269 * When user input invalidate date, keep it in the input field.
270 * This is only used for strong a11y requirement which do not want modify after blur.
271 */
272 preserveInvalidOnBlur?: boolean;
273 transitionName?: string;
274 components?: Components<DateType>;
275 /** @deprecated Please use `components.input` instead. */
276 inputRender?: (props: React.InputHTMLAttributes<HTMLInputElement>) => React.ReactNode;
277 cellRender?: CellRender<DateType>;
278 /** @deprecated use cellRender instead of dateRender */
279 dateRender?: (currentDate: DateType, today: DateType) => React.ReactNode;
280 /** @deprecated use cellRender instead of monthCellRender */
281 monthCellRender?: (currentDate: DateType, locale: Locale) => React.ReactNode;
282 /**
283 * When use `date` picker,
284 * Show the button to set current datetime.
285 */
286 showNow?: boolean;
287 /** @deprecated Please use `showNow` instead */
288 showToday?: boolean;
289 panelRender?: (originPanel: React.ReactNode) => React.ReactNode;
290 renderExtraFooter?: (mode: PanelMode) => React.ReactNode;
291}
292export interface PickerRef {
293 nativeElement: HTMLDivElement;
294 focus: VoidFunction;
295 blur: VoidFunction;
296}
297export interface OpenConfig {
298 index?: number;
299 /**
300 * Keep open if prev state is open but set close within the same frame.
301 * This is used for RangePicker input switch to another one.
302 */
303 inherit?: boolean;
304 /**
305 * By default. Close popup will delay for one frame. `force` will trigger immediately.
306 */
307 force?: boolean;
308}
309export type OnOpenChange = (open: boolean, config?: OpenConfig) => void;
310export interface SelectorProps<DateType = any> extends SharedHTMLAttrs {
311 picker: PickerMode;
312 clearIcon?: React.ReactNode;
313 suffixIcon?: React.ReactNode;
314 className?: string;
315 style?: React.CSSProperties;
316 /** Add `-placeholder` className as a help info */
317 activeHelp?: boolean;
318 focused: boolean;
319 onFocus: (event: React.FocusEvent<HTMLInputElement>, index?: number) => void;
320 onBlur: (event: React.FocusEvent<HTMLInputElement>, index?: number) => void;
321 /** Trigger by `enter` key */
322 onSubmit: VoidFunction;
323 /** `preventDefault` is deprecated which will remove from future version. */
324 onKeyDown?: LegacyOnKeyDown;
325 locale: Locale;
326 generateConfig: GenerateConfig<DateType>;
327 direction?: 'ltr' | 'rtl';
328 onClick: React.MouseEventHandler<HTMLDivElement>;
329 onClear: VoidFunction;
330 format: FormatType<DateType>[];
331 /**
332 * Convert with user typing for the format template.
333 * This will force align the input with template mask.
334 */
335 maskFormat?: string;
336 onInputChange: VoidFunction;
337 onInvalid: (valid: boolean, index?: number) => void;
338 /** When user input invalidate date, keep it in the input field */
339 /**
340 * By default value in input field will be reset with previous valid value when blur.
341 * Set to `false` will keep invalid text in input field when blur.
342 */
343 preserveInvalidOnBlur?: boolean;
344 open: boolean;
345 /** Trigger when need open by selector */
346 onOpenChange: OnOpenChange;
347 inputReadOnly?: boolean;
348}
349export interface SelectorRef {
350 nativeElement: HTMLDivElement;
351 focus: (index?: number) => void;
352 blur: VoidFunction;
353}
354type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
355export type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
356export type ReplaceListType<List, Type> = {
357 [P in keyof List]: Type;
358};
359export {};