1 |
|
2 | import type { AlignType, BuildInPlacements } from '@rc-component/trigger';
|
3 | import type { GenerateConfig } from './generate';
|
4 | export type NullableDateType<DateType> = DateType | null | undefined;
|
5 | export type Locale = {
|
6 | locale: string;
|
7 |
|
8 | dateFormat?: string;
|
9 |
|
10 | dateTimeFormat?: string;
|
11 |
|
12 | fieldDateTimeFormat?: string;
|
13 |
|
14 | fieldDateFormat?: string;
|
15 |
|
16 | fieldTimeFormat?: string;
|
17 |
|
18 | fieldMonthFormat?: string;
|
19 |
|
20 | fieldYearFormat?: string;
|
21 |
|
22 | fieldWeekFormat?: string;
|
23 |
|
24 | fieldQuarterFormat?: string;
|
25 |
|
26 | monthBeforeYear?: boolean;
|
27 |
|
28 | yearFormat?: string;
|
29 |
|
30 | monthFormat?: string;
|
31 |
|
32 | cellYearFormat?: string;
|
33 |
|
34 | cellQuarterFormat?: string;
|
35 |
|
36 | dayFormat?: string;
|
37 |
|
38 | cellDateFormat?: string;
|
39 |
|
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 | };
|
65 | export type PanelMode = 'time' | 'date' | 'week' | 'month' | 'quarter' | 'year' | 'decade';
|
66 | export type InternalMode = PanelMode | 'datetime';
|
67 | export type PickerMode = Exclude<PanelMode, 'datetime' | 'decade'>;
|
68 | export type DisabledDate<DateType = any> = (date: DateType, info: {
|
69 | type: PanelMode;
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 | from?: DateType;
|
76 | }) => boolean;
|
77 | export interface BaseInfo {
|
78 | range?: 'start' | 'end';
|
79 | }
|
80 | export 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 | }
|
88 | export type CellRender<DateType, CurrentType = DateType | number | string> = (current: CurrentType, info: CellRenderInfo<DateType>) => React.ReactNode;
|
89 | export interface ValueDate<DateType = any> {
|
90 | label: React.ReactNode;
|
91 | value: DateType | (() => DateType);
|
92 | }
|
93 | export 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 | }
|
99 | export interface SharedTimeProps<DateType extends object = any> {
|
100 |
|
101 | format?: string;
|
102 |
|
103 | showNow?: boolean;
|
104 |
|
105 | showHour?: boolean;
|
106 |
|
107 | showMinute?: boolean;
|
108 |
|
109 | showSecond?: boolean;
|
110 |
|
111 | showMillisecond?: boolean;
|
112 |
|
113 | use12Hours?: boolean;
|
114 |
|
115 | hourStep?: IntRange<1, 23>;
|
116 |
|
117 | minuteStep?: IntRange<1, 59>;
|
118 |
|
119 | secondStep?: IntRange<1, 59>;
|
120 | |
121 |
|
122 |
|
123 |
|
124 | millisecondStep?: IntRange<1, 999>;
|
125 |
|
126 | hideDisabledOptions?: boolean;
|
127 |
|
128 | defaultValue?: DateType;
|
129 |
|
130 | defaultOpenValue?: DateType;
|
131 |
|
132 | disabledHours?: DisabledTimes['disabledHours'];
|
133 |
|
134 | disabledMinutes?: DisabledTimes['disabledMinutes'];
|
135 |
|
136 | disabledSeconds?: DisabledTimes['disabledSeconds'];
|
137 |
|
138 | disabledTime?: (date: DateType, range?: 'start' | 'end') => DisabledTimes;
|
139 |
|
140 | changeOnScroll?: boolean;
|
141 | }
|
142 | export type RangeTimeProps<DateType extends object = any> = Omit<SharedTimeProps<DateType>, 'defaultValue' | 'defaultOpenValue'> & {
|
143 |
|
144 | defaultValue?: DateType[];
|
145 | defaultOpenValue?: DateType[];
|
146 | };
|
147 | export type OnPanelChange<DateType> = (value: DateType, mode: PanelMode) => void;
|
148 | export type LimitDate<DateType extends object = any> = DateType | ((info: {
|
149 | |
150 |
|
151 |
|
152 |
|
153 | from?: DateType;
|
154 | }) => DateType | null | undefined);
|
155 | export 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 |
|
164 |
|
165 |
|
166 |
|
167 | onSelect: (date: DateType) => void;
|
168 | |
169 |
|
170 |
|
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 |
|
179 | hoverRangeValue: [start: DateType, end: DateType] | null;
|
180 |
|
181 | hoverValue: DateType[] | null;
|
182 | onHover?: (value: DateType | null) => void;
|
183 | |
184 |
|
185 |
|
186 | showTime?: SharedTimeProps<DateType>;
|
187 | |
188 |
|
189 |
|
190 | showWeek?: boolean;
|
191 | prevIcon?: React.ReactNode;
|
192 | nextIcon?: React.ReactNode;
|
193 | superPrevIcon?: React.ReactNode;
|
194 | superNextIcon?: React.ReactNode;
|
195 | }
|
196 | export 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 | }>;
|
200 | export type SemanticStructure = 'popup';
|
201 | export type CustomFormat<DateType> = (value: DateType) => string;
|
202 | export type FormatType<DateType = any> = string | CustomFormat<DateType>;
|
203 | export type SharedHTMLAttrs = Omit<React.InputHTMLAttributes<HTMLDivElement>, 'value' | 'defaultValue' | 'onChange' | 'placeholder' | 'id' | 'onInvalid' | 'disabled' | 'onFocus' | 'onBlur' | 'onSelect' | 'min' | 'max' | 'onKeyDown' | 'size'>;
|
204 | export type PickerFocusEventHandler = (e: React.FocusEvent<HTMLElement>, info: BaseInfo) => void;
|
205 | export type LegacyOnKeyDown = (event: React.KeyboardEvent<HTMLElement>, preventDefault: VoidFunction) => void;
|
206 | export 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 |
|
217 | showTime?: boolean | SharedTimeProps<DateType>;
|
218 |
|
219 | showWeek?: boolean;
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
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 |
|
235 | clearIcon?: React.ReactNode;
|
236 | onFocus?: PickerFocusEventHandler;
|
237 | onBlur?: PickerFocusEventHandler;
|
238 |
|
239 | onKeyDown?: LegacyOnKeyDown;
|
240 | inputReadOnly?: boolean;
|
241 |
|
242 | order?: boolean;
|
243 | disabledDate?: DisabledDate<DateType>;
|
244 |
|
245 | minDate?: DateType;
|
246 |
|
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 |
|
258 |
|
259 |
|
260 |
|
261 | needConfirm?: boolean;
|
262 | |
263 |
|
264 |
|
265 |
|
266 |
|
267 | changeOnBlur?: boolean;
|
268 | |
269 |
|
270 |
|
271 |
|
272 | preserveInvalidOnBlur?: boolean;
|
273 | transitionName?: string;
|
274 | components?: Components<DateType>;
|
275 |
|
276 | inputRender?: (props: React.InputHTMLAttributes<HTMLInputElement>) => React.ReactNode;
|
277 | cellRender?: CellRender<DateType>;
|
278 |
|
279 | dateRender?: (currentDate: DateType, today: DateType) => React.ReactNode;
|
280 |
|
281 | monthCellRender?: (currentDate: DateType, locale: Locale) => React.ReactNode;
|
282 | |
283 |
|
284 |
|
285 |
|
286 | showNow?: boolean;
|
287 |
|
288 | showToday?: boolean;
|
289 | panelRender?: (originPanel: React.ReactNode) => React.ReactNode;
|
290 | renderExtraFooter?: (mode: PanelMode) => React.ReactNode;
|
291 | }
|
292 | export interface PickerRef {
|
293 | nativeElement: HTMLDivElement;
|
294 | focus: VoidFunction;
|
295 | blur: VoidFunction;
|
296 | }
|
297 | export interface OpenConfig {
|
298 | index?: number;
|
299 | |
300 |
|
301 |
|
302 |
|
303 | inherit?: boolean;
|
304 | |
305 |
|
306 |
|
307 | force?: boolean;
|
308 | }
|
309 | export type OnOpenChange = (open: boolean, config?: OpenConfig) => void;
|
310 | export 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 |
|
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 |
|
322 | onSubmit: VoidFunction;
|
323 |
|
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 |
|
333 |
|
334 |
|
335 | maskFormat?: string;
|
336 | onInputChange: VoidFunction;
|
337 | onInvalid: (valid: boolean, index?: number) => void;
|
338 |
|
339 | |
340 |
|
341 |
|
342 |
|
343 | preserveInvalidOnBlur?: boolean;
|
344 | open: boolean;
|
345 |
|
346 | onOpenChange: OnOpenChange;
|
347 | inputReadOnly?: boolean;
|
348 | }
|
349 | export interface SelectorRef {
|
350 | nativeElement: HTMLDivElement;
|
351 | focus: (index?: number) => void;
|
352 | blur: VoidFunction;
|
353 | }
|
354 | type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
355 | export type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
356 | export type ReplaceListType<List, Type> = {
|
357 | [P in keyof List]: Type;
|
358 | };
|
359 | export {};
|