@akinon/ui-date-picker 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,516 @@
1
+ import { DO_NOT_USE_OR_YOU_WILL_BE_FIRED_INTERNAL_STYLE } from '@akinon/ui-theme';
2
+ import type { Dayjs } from 'dayjs';
3
+ import { ReactNode } from 'react';
4
+
5
+ /**
6
+ * Interface representing the properties for the DatePickerGroup component.
7
+ */
8
+ export interface IDatePickerGroupProps
9
+ extends DatePickerGeneralProps,
10
+ React.HTMLAttributes<HTMLDivElement> {
11
+ /**
12
+ * Specifies the type of picker: 'date' for DatePicker or 'range' for RangePicker.
13
+ * @default 'date'
14
+ */
15
+ pickerType?: 'date' | 'range';
16
+
17
+ /**
18
+ * Theme type
19
+ * @default dark
20
+ */
21
+ theme?: 'light' | 'dark' | string;
22
+
23
+ /**
24
+ * Customize clear button.
25
+ * @default true
26
+ */
27
+ allowClear?: boolean | { clearIcon?: ReactNode };
28
+
29
+ /**
30
+ * If get focus when component mounted.
31
+ * @default false
32
+ */
33
+ autoFocus?: boolean;
34
+
35
+ /**
36
+ * Custom panels.
37
+ */
38
+ components?: Record<Panel | 'input', React.ComponentType>;
39
+
40
+ /**
41
+ * Determine whether the DatePicker is disabled.
42
+ * @default false
43
+ */
44
+ disabled?: boolean;
45
+
46
+ /**
47
+ * Specify the date that cannot be selected.
48
+ */
49
+ disabledDate?: (
50
+ currentDate: dayjs,
51
+ info: { from?: dayjs; type: Picker }
52
+ ) => boolean;
53
+
54
+ /**
55
+ * To set the date format, support multi-format matching when it is an array, display the first one shall prevail. Refer to dayjs#format.
56
+ * @default rc-picker
57
+ */
58
+ format?: TDPFormatType;
59
+
60
+ /**
61
+ * Auto order date when multiple or range selection.
62
+ * @default true
63
+ */
64
+ order?: boolean;
65
+
66
+ /**
67
+ * To customize the className of the popup calendar.
68
+ */
69
+ popupClassName?: string;
70
+
71
+ /**
72
+ * Not clean input on blur even when the typing is invalid.
73
+ * @default false
74
+ */
75
+ preserveInvalidOnBlur?: boolean;
76
+
77
+ /**
78
+ * To set the container of the floating layer, while the default is to create a div element in body.
79
+ */
80
+ getPopupContainer?: (trigger: HTMLElement) => HTMLElement;
81
+
82
+ /**
83
+ * Set the readonly attribute of the input tag (avoids virtual keyboard on touch devices).
84
+ * @default false
85
+ */
86
+ inputReadOnly?: boolean;
87
+
88
+ /**
89
+ * Localization configuration.
90
+ * @default default
91
+ */
92
+ locale?: object;
93
+
94
+ /**
95
+ * The minimum date, which also limits the range of panel switching.
96
+ */
97
+ minDate?: dayjs;
98
+
99
+ /**
100
+ * The maximum date, which also limits the range of panel switching.
101
+ */
102
+ maxDate?: dayjs;
103
+
104
+ /**
105
+ * The picker panel mode.
106
+ */
107
+ node?: 'time' | 'date' | 'month' | 'year' | 'decade';
108
+
109
+ /**
110
+ * Need click confirm button to trigger value change. Default false when multiple.
111
+ */
112
+ needConfirm?: boolean;
113
+
114
+ /**
115
+ * The custom next icon.
116
+ */
117
+ nextIcon?: ReactNode;
118
+
119
+ /**
120
+ * The open state of picker.
121
+ */
122
+ open?: boolean;
123
+
124
+ /**
125
+ * Customize panel render.
126
+ */
127
+ panelRender?: (panelNode) => ReactNode;
128
+
129
+ /**
130
+ * Set picker type.
131
+ * @default date
132
+ */
133
+ picker?: 'date' | 'week' | 'month' | 'quarter' | 'year';
134
+
135
+ /**
136
+ * The placeholder of date input.
137
+ */
138
+ placeholder?: string | [string, string];
139
+
140
+ /**
141
+ * The position where the selection box pops up.
142
+ * @default bottomLeft
143
+ */
144
+ placement?: 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight' | 'center';
145
+
146
+ /**
147
+ * To customize the style of the popup calendar.
148
+ * @default {}
149
+ */
150
+ popupStyle?: CSSProperties;
151
+
152
+ /**
153
+ * The custom prefix.
154
+ */
155
+ prefix?: ReactNode;
156
+
157
+ /**
158
+ * The preset ranges for quick selection. Since 5.8.0, preset value supports callback function.
159
+ */
160
+ presets?: { label: React.ReactNode; value: Dayjs | (() => Dayjs) }[];
161
+
162
+ /**
163
+ * The custom prev icon.
164
+ */
165
+ prevIcon?: ReactNode;
166
+
167
+ /**
168
+ * To determine the size of the input box, the height of large and small, are 40px and 24px respectively, while default size is 32px.
169
+ */
170
+ size?: 'large' | 'middle' | 'small';
171
+
172
+ /**
173
+ * Set validation status.
174
+ */
175
+ status?: 'error' | 'warning';
176
+
177
+ /**
178
+ * The custom suffix icon.
179
+ */
180
+ suffixIcon?: ReactNode;
181
+
182
+ /**
183
+ * The size of the suffix icon.
184
+ */
185
+ suffixIconSize?: string;
186
+
187
+ /**
188
+ * The color of the suffix icon.
189
+ */
190
+ suffixIconColor?: string;
191
+
192
+ /**
193
+ * The custom super next icon.
194
+ */
195
+ superNextIcon?: ReactNode;
196
+
197
+ /**
198
+ * The custom super prev icon.
199
+ */
200
+ superPrevIcon?: ReactNode;
201
+
202
+ /**
203
+ * The title of the input box.
204
+ */
205
+ inputTitle?: inputTitle;
206
+
207
+ /**
208
+ * Show title of input box.
209
+ * @default false
210
+ */
211
+ showTitle?: boolean;
212
+
213
+ /**
214
+ * The width of the input box
215
+ */
216
+ inputWidth?: string;
217
+
218
+ /**
219
+ * Variants of picker.
220
+ * @default outlined
221
+ */
222
+ variant?: 'outlined' | 'borderless' | 'filled';
223
+
224
+ /**
225
+ * Callback function, can be executed whether the popup calendar is popped up or closed.
226
+ */
227
+ onOpenChange?: (open: boolean) => void;
228
+
229
+ /**
230
+ * Callback when picker panel mode is changed.
231
+ */
232
+ onPanelChange?: (value: Dayjs, mode: string) => void;
233
+
234
+ /**
235
+ * Never use this prop. Akinon design system does not allow custom styles.
236
+ * @ignore
237
+ */
238
+ style?: DO_NOT_USE_OR_YOU_WILL_BE_FIRED_INTERNAL_STYLE;
239
+ }
240
+
241
+ /**
242
+ * Props for the DatePicker component.
243
+ */
244
+ export interface IDatePickerProps
245
+ extends CommonPickerProps,
246
+ PickerValuesProps,
247
+ React.HTMLAttributes<HTMLDivElement> {
248
+ /**
249
+ * To specify the time that cannot be selected.
250
+ */
251
+ disabledTime?: (date: Dayjs) => boolean;
252
+
253
+ /**
254
+ * Show the fast access of current datetime.
255
+ */
256
+ showNow?: boolean;
257
+
258
+ /**
259
+ * To provide an additional time selection
260
+ * @default TimePicker Options
261
+ */
262
+ showTime?: (object | boolean) & {
263
+ /**
264
+ * To set default time of selected date, demo
265
+ * @default dayjs()
266
+ */
267
+ defaultValue?: dayjs;
268
+ };
269
+
270
+ /**
271
+ * Show week info when in DatePicker.
272
+ * @default false
273
+ */
274
+ showWeek?: boolean;
275
+
276
+ /**
277
+ * Callback when click ok button.
278
+ */
279
+ onOk?: () => void;
280
+
281
+ /**
282
+ * Callback function for panel changing.
283
+ */
284
+ onPanelChange?: (value: Dayjs, mode: string) => void;
285
+ }
286
+
287
+ /**
288
+ * Properties for the Range Picker component.
289
+ */
290
+ export interface IRangePickerProps
291
+ extends PickerValuesProps,
292
+ DatePickerGeneralProps,
293
+ React.HTMLAttributes<HTMLDivElement> {
294
+ /**
295
+ * Allow start or end input to be left empty.
296
+ * @default [false, false]
297
+ */
298
+ allowEmpty?: [boolean, boolean];
299
+
300
+ /**
301
+ * To set default date.
302
+ */
303
+ defaultValue?: [dayjs, dayjs];
304
+
305
+ /**
306
+ * If start or end is disabled.
307
+ */
308
+ disabled?: [boolean, boolean];
309
+
310
+ /**
311
+ * To specify the time that cannot be selected.
312
+ */
313
+ disabledTime?: (
314
+ date: dayjs,
315
+ partial: 'start' | 'end',
316
+ info: { from?: dayjs }
317
+ ) => void;
318
+
319
+ /**
320
+ * To set the date format. Refer to dayjs#format.
321
+ * @default YYYY-MM-DD HH:mm:ss
322
+ */
323
+ format?: TDPFormatType;
324
+
325
+ /**
326
+ * Config input ids.
327
+ */
328
+ id?: { start?: string; end?: string };
329
+
330
+ /**
331
+ * The preset ranges for quick selection. Since 5.8.0, preset value supports callback function.
332
+ */
333
+ presets?: { label: React.ReactNode; value: (Dayjs | (() => Dayjs))[] }[];
334
+
335
+ /**
336
+ * Render extra footer in panel.
337
+ */
338
+ renderExtraFooter?: () => React.ReactNode;
339
+
340
+ /**
341
+ * Set separator between inputs.
342
+ * @default <SwapRightOutlined />
343
+ */
344
+ separator?: React.ReactNode;
345
+
346
+ /**
347
+ * To provide an additional time selection.
348
+ * @default ITimePickerProps Options
349
+ */
350
+ showTime?: (object | boolean) & {
351
+ /**
352
+ * To set default time of selected date.
353
+ * @default [dayjs(), dayjs()]
354
+ */
355
+ defaultValue?: dayjs[];
356
+ };
357
+
358
+ /**
359
+ * To set date.
360
+ */
361
+ value?: [dayjs, dayjs];
362
+
363
+ /**
364
+ * Callback function, executed when the start time or the end time of the range is changing. Info argument added in 4.4.0.
365
+ */
366
+ onCalendarChange?: (
367
+ dates: [dayjs, dayjs],
368
+ dateStrings: [string, string],
369
+ info: { range: 'start' | 'end' }
370
+ ) => void;
371
+
372
+ /**
373
+ * Callback function, executed when the selected time is changing.
374
+ */
375
+ onChange?: (dates: [dayjs, dayjs], dateStrings: [string, string]) => void;
376
+
377
+ /**
378
+ * Triggered when the component gets focus.
379
+ */
380
+ onFocus?: (
381
+ event: React.FocusEvent<HTMLDivElement>,
382
+ info: { range: 'start' | 'end' }
383
+ ) => void;
384
+
385
+ /**
386
+ * Triggered when the component loses focus.
387
+ */
388
+ onBlur?: (
389
+ event: React.FocusEvent<HTMLDivElement>,
390
+ info: { range: 'start' | 'end' }
391
+ ) => void;
392
+ }
393
+
394
+ /**
395
+ * Represents the format type for the date picker.
396
+ *
397
+ * This type can be one of the following:
398
+ * - `TDPGeneric`: A generic type for the date picker.
399
+ * - `TDPGenericFn`: A function type for the date picker.
400
+ * - An array of `TDPGeneric` or `TDPGenericFn`.
401
+ * - An object with the following properties:
402
+ * - `format`: A string representing the format.
403
+ * - `type` (optional): A string with the value 'mask'.
404
+ */
405
+
406
+ type TDPGeneric = string;
407
+ type TDPGenericFn = (value: Dayjs) => string;
408
+
409
+ export type TDPFormatType =
410
+ | TDPGeneric
411
+ | TDPGenericFn
412
+ | Array<TDPGeneric | TDPGenericFn>
413
+ | {
414
+ format: string;
415
+ type?: 'mask';
416
+ };
417
+
418
+ interface DatePickerGeneralProps {
419
+ /**
420
+ * Custom rendering function for date cells, >= 5.4.0 use cellRender instead.
421
+ */
422
+ dateRender?: (currentDate: dayjs, today: dayjs) => React.ReactNode;
423
+
424
+ /**
425
+ * Custom rendering function for picker cells.
426
+ */
427
+ cellRender?: (
428
+ current: dayjs,
429
+ info: {
430
+ originNode: React.ReactElement;
431
+ today: DateType;
432
+ range?: 'start' | 'end';
433
+ type: PanelMode;
434
+ locale?: Locale;
435
+ subType?: 'hour' | 'minute' | 'second' | 'meridiem';
436
+ }
437
+ ) => React.ReactNode;
438
+ }
439
+
440
+ interface PickerValuesProps {
441
+ /**
442
+ * Default panel date, will be reset when panel open.
443
+ */
444
+ defaultPickerValue?: dayjs;
445
+
446
+ /**
447
+ * Panel date. Used for controlled switching of panel date. Works with onPanelChange.
448
+ */
449
+ pickerValue?: dayjs;
450
+ }
451
+
452
+ interface CommonPickerProps {
453
+ /**
454
+ * To set default date, if start time or end time is null or undefined, the date range will be an open interval.
455
+ */
456
+ defaultValue?: dayjs;
457
+
458
+ /**
459
+ * To set the date format. Refer to dayjs#format.
460
+ * If format == year @default "YYYY",
461
+ * If format == quarter @default "YYYY-\QQ",
462
+ * If format == month @default "YYYY-MM",
463
+ * If format == week @default "YYYY-wo",
464
+ * If format == date @default "YYYY-MM-DD"
465
+ */
466
+ format?: TDPFormatType;
467
+
468
+ /**
469
+ * Enable multiple selection. Not support showTime.
470
+ * @default false
471
+ */
472
+ multiple?: boolean;
473
+
474
+ /**
475
+ * Render extra footer in panel.
476
+ */
477
+ renderExtraFooter?: () => React.ReactNode;
478
+
479
+ /**
480
+ * To set date.
481
+ */
482
+ value?: dayjs;
483
+
484
+ /**
485
+ * Callback function, can be executed when the selected time is changing.
486
+ * @param {dayjs} date - The selected date.
487
+ * @param {string} dateString - The formatted date string.
488
+ */
489
+ onChange?: (date: dayjs, dateString: string) => void;
490
+ }
491
+
492
+ /**
493
+ * Props for the DatePickerYear component.
494
+ */
495
+ export type IDatePickerYearProps = CommonPickerProps;
496
+
497
+ /**
498
+ * Props for the DatePickerQuarter component.
499
+ */
500
+ export type IDatePickerQuarterProps = CommonPickerProps;
501
+
502
+ /**
503
+ * Props for the DatePickerMonth component.
504
+ */
505
+ export type IDatePickerMonthProps = CommonPickerProps;
506
+
507
+ /**
508
+ * Props for the DatePickerWeek component.
509
+ */
510
+ export interface IDatePickerWeekProps extends CommonPickerProps {
511
+ /**
512
+ * Show week info when in DatePicker
513
+ * @default true
514
+ */
515
+ showWeek?: boolean;
516
+ }
@@ -1,5 +1,22 @@
1
- import type { DatePickerProps as AntDatePickerProps } from 'antd';
2
1
  import * as React from 'react';
3
- export type DatePickerProps = AntDatePickerProps;
4
- export declare const DatePicker: ({ ...restDatePickerProps }: DatePickerProps) => React.JSX.Element;
2
+ import { IDatePickerGroupProps } from './types';
3
+ /**
4
+ * DatePicker component for Akinon UI.
5
+ *
6
+ * The DatePicker component provides a flexible and feature-rich solution for selecting dates, ranges, and times.
7
+ * It supports various configurations, including custom formats, localized options, and enhanced accessibility features.
8
+ * The component integrates seamlessly with the Akinon design system, offering a consistent user experience.
9
+ *
10
+ * Key Features:
11
+ * - Multiple picker types, including date, week, month, quarter, and year.
12
+ * - Customizable placeholder, size, and variant options for styling.
13
+ * - Flexible date and time range selection with validation support.
14
+ * - Event callbacks for value changes, focus, blur, and panel interactions.
15
+ * - Localization support for tailored user experiences.
16
+ *
17
+ * The DatePicker component is designed to cater to both basic and advanced use cases, making it ideal for
18
+ * enterprise-level applications.
19
+ */
20
+ export declare const DatePicker: ({ pickerType, suffixIconColor, suffixIcon, suffixIconSize, showTitle, inputTitle, ...restDatePickerProps }: IDatePickerGroupProps) => React.JSX.Element;
21
+ export type { IDatePickerGroupProps };
5
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,IAAI,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAElE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAEjD,eAAO,MAAM,UAAU,+BAAgC,eAAe,sBAMrE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;;;;;;;;;;;;GAgBG;AAEH,eAAO,MAAM,UAAU,+GAQpB,qBAAqB,sBAidvB,CAAC;AAEF,YAAY,EAAE,qBAAqB,EAAE,CAAC"}