-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathinterface.tsx
More file actions
542 lines (463 loc) Β· 15.3 KB
/
interface.tsx
File metadata and controls
542 lines (463 loc) Β· 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
import type { AlignType, BuildInPlacements } from '@rc-component/trigger';
import type { GenerateConfig } from './generate';
export type NullableDateType<DateType> = DateType | null | undefined;
export type Locale = {
locale: string;
// ======================================================
// == Format ==
// ======================================================
// ==================== Input Format ====================
// Input format
/** @deprecated Please use `fieldDateFormat` instead */
dateFormat?: string;
/** @deprecated Please use `fieldDateTimeFormat` instead */
dateTimeFormat?: string;
/** Input field formatter like YYYY-MM-DD HH:mm:ss */
fieldDateTimeFormat?: string;
/** Input field formatter like YYYY-MM-DD */
fieldDateFormat?: string;
/** Input field formatter like HH:mm:ss */
fieldTimeFormat?: string;
/** Input field formatter like YYYY-MM */
fieldMonthFormat?: string;
/** Input field formatter like YYYY */
fieldYearFormat?: string;
/** Input field formatter like wwww-go */
fieldWeekFormat?: string;
/** Input field formatter like YYYY-Q */
fieldQuarterFormat?: string;
// ===================== Date Panel =====================
// Header Format
/** Display month before year in date panel header */
monthBeforeYear?: boolean;
/** year format in header panel */
yearFormat?: string;
/** month format in header panel */
monthFormat?: string;
// Cell format
/** year format in body panel */
cellYearFormat?: string;
/** quarter format in body panel */
cellQuarterFormat?: string;
/** @deprecated Please use `cellDateFormat` instead */
dayFormat?: string;
/** day format in body panel */
cellDateFormat?: string;
/** meridiem format in body panel */
cellMeridiemFormat?: string;
// ======================================================
// == MISC ==
// ======================================================
today: string;
now: string;
backToToday: string;
ok: string;
timeSelect: string;
dateSelect: string;
weekSelect?: string;
clear: string;
week: string;
month: string;
year: string;
previousMonth: string;
nextMonth: string;
monthSelect: string;
yearSelect: string;
decadeSelect: string;
previousYear: string;
nextYear: string;
previousDecade: string;
nextDecade: string;
previousCentury: string;
nextCentury: string;
shortWeekDays?: string[];
shortMonths?: string[];
};
export type PanelMode = 'time' | 'date' | 'week' | 'month' | 'quarter' | 'year' | 'decade';
export type InternalMode = PanelMode | 'datetime';
export type PickerMode = Exclude<PanelMode, 'datetime' | 'decade'>;
export type DisabledDate<DateType = any> = (
date: DateType,
info: {
type: PanelMode;
/**
* Only work in RangePicker.
* Tell the first date user selected on this range selection.
* This is not care about what field user click.
*/
from?: DateType;
},
) => boolean;
export interface BaseInfo {
range?: 'start' | 'end';
}
export interface CellRenderInfo<DateType> extends BaseInfo {
prefixCls: string;
// The cell wrapper element
originNode: React.ReactElement;
today: DateType;
type: PanelMode;
locale?: Locale;
subType?: 'hour' | 'minute' | 'second' | 'millisecond' | 'meridiem';
}
export type CellRender<DateType, CurrentType = DateType | number | string> = (
current: CurrentType,
info: CellRenderInfo<DateType>,
) => React.ReactNode;
export interface ValueDate<DateType = any> {
label: React.ReactNode;
value: DateType | (() => DateType);
}
// ========================== Time ==========================
export interface DisabledTimes {
disabledHours?: () => number[];
disabledMinutes?: (hour: number) => number[];
disabledSeconds?: (hour: number, minute: number) => number[];
disabledMilliseconds?: (hour: number, minute: number, second: number) => number[];
}
export interface SharedTimeProps<DateType extends object = any> {
/** Only work in picker is `time` */
format?: string;
/** Only work in picker is `time` */
showNow?: boolean;
/** Only work in picker is `time` */
showHour?: boolean;
/** Only work in picker is `time` */
showMinute?: boolean;
/** Only work in picker is `time` */
showSecond?: boolean;
/** Only work in picker is `time` */
showMillisecond?: boolean;
/** Only work in picker is `time` */
use12Hours?: boolean;
/** Only work in picker is `time` */
hourStep?: IntRange<1, 23>;
/** Only work in picker is `time` */
minuteStep?: IntRange<1, 59>;
/** Only work in picker is `time` */
secondStep?: IntRange<1, 59>;
/**
* Only work in picker is `time`.
* Note that too small step will cause performance issue.
*/
millisecondStep?: IntRange<1, 999>;
/** Only work in picker is `time` */
hideDisabledOptions?: boolean;
/** @deprecated Use `defaultOpenValue` instead */
defaultValue?: DateType;
/** Set default value template when empty selection */
defaultOpenValue?: DateType;
/** @deprecated Please use `disabledTime` instead. */
disabledHours?: DisabledTimes['disabledHours'];
/** @deprecated Please use `disabledTime` instead. */
disabledMinutes?: DisabledTimes['disabledMinutes'];
/** @deprecated Please use `disabledTime` instead. */
disabledSeconds?: DisabledTimes['disabledSeconds'];
/** Only work in picker is `time` */
disabledTime?: (date: DateType) => DisabledTimes;
/** Only work in picker is `time` */
changeOnScroll?: boolean;
}
export type RangeTimeProps<DateType extends object = any> = Omit<
SharedTimeProps<DateType>,
'defaultValue' | 'defaultOpenValue' | 'disabledTime'
> & {
/** @deprecated Use `defaultOpenValue` instead. */
defaultValue?: DateType[];
defaultOpenValue?: DateType[];
disabledTime?: (
date: DateType,
range: 'start' | 'end',
info: { from?: DateType },
) => DisabledTimes;
};
// ======================= Components =======================
export type OnPanelChange<DateType> = (value: DateType, mode: PanelMode) => void;
export type LimitDate<DateType extends object = any> =
| DateType
| ((info: {
/**
* Tell the first date user selected on this range selection.
* This is not care about what field user click.
*/
from?: DateType;
}) => DateType | null | undefined);
export interface SharedPanelProps<DateType extends object = any> {
// Style
prefixCls: string;
// Date Library
locale: Locale;
generateConfig: GenerateConfig<DateType>;
// Value
pickerValue: DateType;
onPickerValueChange: (date: DateType) => void;
value?: DateType;
/**
* Should trigger when user select the cell.
* PickerPanel will mark as `value` in single mode,
* Or toggle `values` in multiple mode.
*/
onSelect: (date: DateType) => void;
/**
* Used for `multiple` mode.
* When not `multiple`, it will be `[value]`.
*/
values?: DateType[];
// Mode
onModeChange: (mode: PanelMode, date?: DateType) => void;
// Limitation
disabledDate?: DisabledDate<DateType>;
minDate?: DateType;
maxDate?: DateType;
// Render
cellRender?: CellRender<DateType>;
// Hover
/** @private Only used for RangePicker passing. */
hoverRangeValue: [start: DateType, end: DateType] | null;
/** @private Only used for SinglePicker passing. */
hoverValue: DateType[] | null;
onHover?: (value: DateType | null) => void;
// Time
/**
* Only used for `date` mode.
*/
showTime?: SharedTimeProps<DateType>;
// Week
/**
* Only used for `date` mode.
*/
showWeek?: boolean;
// Icons
prevIcon?: React.ReactNode;
nextIcon?: React.ReactNode;
superPrevIcon?: React.ReactNode;
superNextIcon?: React.ReactNode;
}
export type Components<DateType extends object = any> = Partial<
Record<InternalMode, React.ComponentType<SharedPanelProps<DateType>>> & {
button?: React.ComponentType<any> | string;
input?: React.ComponentType<any> | string;
}
>;
// ========================= Picker =========================
export type CustomFormat<DateType> = (value: DateType, index: number) => string;
export type FormatType<DateType = any> = string | CustomFormat<DateType>;
export type SharedHTMLAttrs = Omit<
React.InputHTMLAttributes<HTMLDivElement>,
| 'value'
| 'defaultValue'
| 'onChange'
| 'placeholder'
| 'id'
| 'onInvalid'
| 'disabled'
| 'onFocus'
| 'onBlur'
| 'onSelect'
| 'min'
| 'max'
| 'onKeyDown'
| 'size'
| 'prefix'
>;
export type PickerFocusEventHandler = (e: React.FocusEvent<HTMLElement>, info: BaseInfo) => void;
export type LegacyOnKeyDown = (
event: React.KeyboardEvent<HTMLElement>,
preventDefault: VoidFunction,
) => void;
export type SemanticName = 'root' | 'prefix' | 'input' | 'suffix';
export type PanelSemanticName = 'root' | 'header' | 'body' | 'content' | 'item' | 'footer';
export interface SharedPickerProps<DateType extends object = any>
extends SharedHTMLAttrs,
Pick<
SharedPanelProps<DateType>,
// Icon
'prevIcon' | 'nextIcon' | 'superPrevIcon' | 'superNextIcon'
> {
// MISC
direction?: 'ltr' | 'rtl';
// Styles
prefixCls?: string;
className?: string;
style?: React.CSSProperties;
rootClassName?: string;
styles?: Partial<Record<SemanticName, React.CSSProperties>> & {
popup?: Partial<Record<PanelSemanticName, React.CSSProperties>>;
};
classNames?: Partial<Record<SemanticName, string>> & {
popup?: Partial<Record<PanelSemanticName, string>>;
};
// Config
locale: Locale;
generateConfig: GenerateConfig<DateType>;
// Picker
picker?: PickerMode;
/** Only work when picker is `date` or `time` */
showTime?: boolean | SharedTimeProps<DateType>;
/** Only work when picker is `date` */
showWeek?: boolean;
/**
* Config the input field parse and format.
* When set `format.type`, it will force user input type with your input,
* it's only support basic format mask: YYYY, MM, DD, HH, mm, ss, SSS.
* Once use config mode, it must be fill with format your config.
*/
format?:
| FormatType<DateType>
| FormatType<DateType>[]
| {
format: string;
type?: 'mask';
};
// Icons
prefix?: React.ReactNode;
suffixIcon?: React.ReactNode;
allowClear?:
| boolean
| {
clearIcon?: React.ReactNode;
};
/** @deprecated Please use `allowClear.clearIcon` instead */
clearIcon?: React.ReactNode;
// Active
onFocus?: PickerFocusEventHandler;
onBlur?: PickerFocusEventHandler;
/** `preventDefault` is deprecated which will remove from future version. */
onKeyDown?: LegacyOnKeyDown;
inputReadOnly?: boolean;
// range
/** Default will always order of selection after submit */
order?: boolean;
// Disabled
disabledDate?: DisabledDate<DateType>;
/** Limit the selectable range. This will limit picker navigation also */
minDate?: DateType;
/** Limit the selectable range. This will limit picker navigation also */
maxDate?: DateType;
// Open
defaultOpenValue?: DateType;
defaultOpen?: boolean;
open?: boolean;
onOpenChange?: (open: boolean) => void;
popupAlign?: AlignType;
getPopupContainer?: (node: HTMLElement) => HTMLElement;
// Popup
placement?: string;
builtinPlacements?: BuildInPlacements;
/**
* By default. Only `time` or `datetime` show the confirm button in panel.
* `true` to make every picker need confirm.
* `false` to trigger change on every time panel closed by the mode = picker.
*/
needConfirm?: boolean;
/**
* @deprecated. This is removed and not work anymore.
* Value will always be update if user type correct date type.
* You can use `needConfirm` for confirm requirement.
*/
changeOnBlur?: boolean;
/**
* When user input invalidate date, keep it in the input field.
* This is only used for strong a11y requirement which do not want modify after blur.
*/
preserveInvalidOnBlur?: boolean;
// Motion
transitionName?: string;
// Render
components?: Components<DateType>;
/** @deprecated Please use `components.input` instead. */
inputRender?: (props: React.InputHTMLAttributes<HTMLInputElement>) => React.ReactNode;
cellRender?: CellRender<DateType>;
/** @deprecated use cellRender instead of dateRender */
dateRender?: (currentDate: DateType, today: DateType) => React.ReactNode;
/** @deprecated use cellRender instead of monthCellRender */
monthCellRender?: (currentDate: DateType, locale: Locale) => React.ReactNode;
/**
* When use `date` picker,
* Show the button to set current datetime.
*/
showNow?: boolean;
/** @deprecated Please use `showNow` instead */
showToday?: boolean;
panelRender?: (originPanel: React.ReactNode) => React.ReactNode;
renderExtraFooter?: (mode: PanelMode) => React.ReactNode;
}
// picker
export interface PickerRef {
nativeElement: HTMLDivElement;
focus: (options?: FocusOptions) => void;
blur: VoidFunction;
}
// rangePicker
export interface RangePickerRef extends Omit<PickerRef, 'focus'> {
focus: (index?: number | (FocusOptions & { index?: number })) => void;
}
// ======================== Selector ========================
export interface OpenConfig {
index?: number;
/**
* Keep open if prev state is open but set close within the same frame.
* This is used for RangePicker input switch to another one.
*/
inherit?: boolean;
/**
* By default. Close popup will delay for one frame. `force` will trigger immediately.
*/
force?: boolean;
}
export type OnOpenChange = (open: boolean, config?: OpenConfig) => void;
export interface SelectorProps<DateType = any> extends SharedHTMLAttrs {
picker: PickerMode;
prefix?: React.ReactNode;
clearIcon?: React.ReactNode;
suffixIcon?: React.ReactNode;
className?: string;
style?: React.CSSProperties;
/** Add `-placeholder` className as a help info */
activeHelp?: boolean;
focused: boolean;
onFocus: (event: React.FocusEvent<HTMLInputElement>, index?: number) => void;
onBlur: (event: React.FocusEvent<HTMLInputElement>, index?: number) => void;
/** Trigger by `enter` key */
onSubmit: VoidFunction;
/** `preventDefault` is deprecated which will remove from future version. */
onKeyDown?: LegacyOnKeyDown;
locale: Locale;
generateConfig: GenerateConfig<DateType>;
// Direction
direction?: 'ltr' | 'rtl';
// Click
onClick: React.MouseEventHandler<HTMLDivElement>;
// Clear
onClear: VoidFunction;
// Change
format: FormatType<DateType>[];
/**
* Convert with user typing for the format template.
* This will force align the input with template mask.
*/
maskFormat?: string;
onInputChange: VoidFunction;
onInvalid: (valid: boolean, index?: number) => void;
/** When user input invalidate date, keep it in the input field */
/**
* By default value in input field will be reset with previous valid value when blur.
* Set to `false` will keep invalid text in input field when blur.
*/
preserveInvalidOnBlur?: boolean;
// Open
open: boolean;
/** Trigger when need open by selector */
onOpenChange: OnOpenChange;
// Invalidate
inputReadOnly?: boolean;
}
// ========================== MISC ==========================
// https://stackoverflow.com/a/39495173; need TypeScript >= 4.5
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
? Acc[number]
: Enumerate<N, [...Acc, Acc['length']]>;
export type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
export type ReplaceListType<List, Type> = {
[P in keyof List]: Type;
};