@ezuikit/control-date-picker 0.0.1-alpha.1 → 1.0.0-beta.1
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.
- package/README.md +62 -0
- package/dist/index.js +3 -229
- package/dist/index.umd.js +8 -379
- package/dist/style.css +5 -0
- package/dist/style.js +6 -0
- package/dist/types/index.d.ts +748 -28
- package/package.json +22 -15
- package/dist/index.mjs +0 -228
package/dist/types/index.d.ts
CHANGED
|
@@ -1,48 +1,768 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { DateTime } from '@ezuikit/utils-tools';
|
|
2
|
+
import Picker, { PickerOptions } from '@skax/picker';
|
|
3
|
+
|
|
4
|
+
interface CalendarLocale {
|
|
5
|
+
year: string;
|
|
6
|
+
month: string;
|
|
7
|
+
weeks: string[];
|
|
8
|
+
months: string[];
|
|
9
|
+
today: string;
|
|
10
|
+
ok: string;
|
|
11
11
|
}
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
+
* Header component for the container.
|
|
15
|
+
* It can be used to render custom content at the bottom of the container.
|
|
16
|
+
* @interface FooterOptions
|
|
17
|
+
* @property {string} [className] - Optional class name to be added to the footer element for custom styling.
|
|
18
|
+
* @property {string | (() => string)} content - The content to be rendered in the footer.
|
|
19
|
+
*
|
|
20
|
+
* It can be a string or a function that returns a string.
|
|
14
21
|
*/
|
|
15
|
-
|
|
22
|
+
interface HeaderOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Optional class name to be added to the footer element for custom styling.
|
|
25
|
+
*/
|
|
26
|
+
className?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Prefix class name to be added to the footer element for custom styling.
|
|
29
|
+
*/
|
|
30
|
+
prefixCls?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 自定义 super prev 按钮图标
|
|
33
|
+
*/
|
|
34
|
+
renderSuperPrevIcon?: string | (() => string);
|
|
35
|
+
/**
|
|
36
|
+
* 自定义 super next 按钮图标
|
|
37
|
+
*/
|
|
38
|
+
renderSuperNextIcon?: string | (() => string);
|
|
39
|
+
/**
|
|
40
|
+
* 显示 super prev 按钮图标
|
|
41
|
+
*/
|
|
42
|
+
showSuperPrevIcon?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 显示 super next 按钮图标
|
|
45
|
+
*/
|
|
46
|
+
showSuperNextIcon?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* 自定义 prev 按钮图标
|
|
49
|
+
*/
|
|
50
|
+
renderPrevIcon?: string | ((locale?: CalendarLocale) => string);
|
|
51
|
+
/**
|
|
52
|
+
* 自定义 next 按钮图标
|
|
53
|
+
*/
|
|
54
|
+
renderNextIcon?: string | ((locale?: CalendarLocale) => string);
|
|
55
|
+
/**
|
|
56
|
+
* 显示 prev 按钮图标
|
|
57
|
+
*/
|
|
58
|
+
showPrevIcon?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* 显示 next 按钮图标
|
|
61
|
+
*/
|
|
62
|
+
showNextIcon?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* 显示 header close 按钮图标
|
|
65
|
+
*/
|
|
66
|
+
showHeaderClose?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 自定义 header close 按钮图标
|
|
69
|
+
*/
|
|
70
|
+
renderHeaderCloseIcon?: string | ((locale?: CalendarLocale) => string);
|
|
71
|
+
/**
|
|
72
|
+
* 显示 header ok 按钮图标
|
|
73
|
+
*/
|
|
74
|
+
showHeaderOk?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* 自定义 header ok 按钮图标
|
|
77
|
+
*/
|
|
78
|
+
renderHeaderOkIcon?: string | ((locale?: CalendarLocale) => string);
|
|
79
|
+
/**
|
|
80
|
+
* 点击Super prev 按钮图标回调
|
|
81
|
+
* @param date
|
|
82
|
+
* @param prev
|
|
83
|
+
*/
|
|
84
|
+
onSuperPrev?: (date?: Date, prev?: Date) => void;
|
|
85
|
+
/**
|
|
86
|
+
* 点击Super next 按钮图标回调
|
|
87
|
+
* @param date
|
|
88
|
+
* @param prev
|
|
89
|
+
*/
|
|
90
|
+
onSuperNext?: (date?: Date, prev?: Date) => void;
|
|
91
|
+
/**
|
|
92
|
+
* 点击 prev 按钮图标回调
|
|
93
|
+
* @param date
|
|
94
|
+
* @param prev
|
|
95
|
+
*/
|
|
96
|
+
onPrev?: (date?: Date, prev?: Date) => void;
|
|
97
|
+
/**
|
|
98
|
+
* 点击 next 按钮图标回调
|
|
99
|
+
* @param date 当前选中日期
|
|
100
|
+
* @param next
|
|
101
|
+
*/
|
|
102
|
+
onNext?: (date?: Date, next?: Date) => void;
|
|
103
|
+
/**
|
|
104
|
+
* 点击 close 按钮图标回调
|
|
105
|
+
* @param date 当前选中日期
|
|
106
|
+
*/
|
|
107
|
+
onClose?: (date?: Date) => void;
|
|
108
|
+
/**
|
|
109
|
+
* 点击 ok 按钮图标回调
|
|
110
|
+
* @param date 当前选中日期
|
|
111
|
+
*/
|
|
112
|
+
onOk?: (date?: Date) => void;
|
|
113
|
+
/** 多语言 */
|
|
114
|
+
locale?: CalendarLocale;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 公共头部组件
|
|
118
|
+
* @param options - Options for the header component.
|
|
119
|
+
* @param {string} options.className - Optional class name to be added to the header element for custom styling.
|
|
120
|
+
* @param {string | (() => string)} options.content - The content to be rendered in the header.
|
|
121
|
+
* It can be a string or a function that returns a string.
|
|
122
|
+
* This function creates a header element with the specified class name and content.
|
|
123
|
+
* It returns a string representing the HTML structure of the header.
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import Header from "./header";
|
|
127
|
+
* const header = new Header({
|
|
128
|
+
* className: "custom-header",
|
|
129
|
+
* prefixCls: "prefix",
|
|
130
|
+
* content: () => "<h1>Header Content</h1>"
|
|
131
|
+
* })
|
|
132
|
+
* @returns {string} The HTML string representing the header element.
|
|
133
|
+
*
|
|
134
|
+
*/
|
|
135
|
+
declare class Header {
|
|
136
|
+
options: Required<HeaderOptions>;
|
|
137
|
+
$header: HTMLElement | null;
|
|
138
|
+
constructor(options: HeaderOptions);
|
|
139
|
+
private _render;
|
|
140
|
+
private _getStrOrFunToStr;
|
|
141
|
+
/**
|
|
142
|
+
* 渲染内容
|
|
143
|
+
* @param html 内容
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
renderContent(html: string): void;
|
|
147
|
+
destroy(): void;
|
|
148
|
+
private _eventListeners;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type PopupContainerEle = HTMLElement | (() => HTMLElement);
|
|
152
|
+
/**
|
|
153
|
+
* ContainerOptions interface for defining options for the Container class.
|
|
154
|
+
*/
|
|
155
|
+
interface ContainerOptions extends HeaderOptions {
|
|
156
|
+
/**
|
|
157
|
+
* A class name to be added to the wrapper element of the content.
|
|
158
|
+
* This allows for custom styling of the container.
|
|
159
|
+
*/
|
|
160
|
+
wrapClassName?: string;
|
|
161
|
+
/**
|
|
162
|
+
* A prefix class name to be added to the container element.
|
|
163
|
+
* This is useful for styling and avoiding class name conflicts.
|
|
164
|
+
*/
|
|
165
|
+
prefixCls?: string;
|
|
166
|
+
/**
|
|
167
|
+
* The locale to be used for localization.
|
|
168
|
+
* It can be a string representing the language code (e.g., "en-US", "zh-CN") or an object containing localized strings.
|
|
169
|
+
* If not provided, it defaults to "en-US".
|
|
170
|
+
*/
|
|
171
|
+
language?: 'en' | 'zh' | string;
|
|
172
|
+
/**
|
|
173
|
+
* An object containing locale strings for different languages.
|
|
174
|
+
* The keys should be language codes (e.g., "en-US", "zh-CN") and the values should be objects containing localized strings.
|
|
175
|
+
*/
|
|
176
|
+
locales?: Record<string, CalendarLocale>;
|
|
177
|
+
/**
|
|
178
|
+
* Whether to render the component in mobile mode.
|
|
179
|
+
*/
|
|
180
|
+
isMobile?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Whether to show the header in the container.
|
|
183
|
+
*/
|
|
184
|
+
showHeader?: boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Container class for creating a content container with options for locale and styling.
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* import Container from "./Container";
|
|
191
|
+
* const container = new Container({
|
|
192
|
+
* getContainer: document.body,
|
|
193
|
+
* wrapClassName: "custom-wrap",
|
|
194
|
+
* prefixCls: "custom-prefix",
|
|
195
|
+
* language: "zh-CN",
|
|
196
|
+
* locales: {
|
|
197
|
+
* "en-US": { today: "Today", cancel: "Cancel" },
|
|
198
|
+
* "zh-CN": { today: "今天", cancel: "取消" },
|
|
199
|
+
* },
|
|
200
|
+
* });
|
|
201
|
+
*/
|
|
202
|
+
declare class Container<T extends ContainerOptions> {
|
|
203
|
+
/**
|
|
204
|
+
* Options for the Container class, including wrapClassName, prefixCls, locale, and LOCALES.
|
|
205
|
+
*/
|
|
206
|
+
readonly options: T;
|
|
207
|
+
/**
|
|
208
|
+
* The popup container element.
|
|
209
|
+
*/
|
|
210
|
+
$popupContainer: HTMLElement;
|
|
211
|
+
/**
|
|
212
|
+
* panel element node.
|
|
213
|
+
*/
|
|
214
|
+
$panel: HTMLDivElement;
|
|
215
|
+
/**
|
|
216
|
+
* body element node.
|
|
217
|
+
*/
|
|
218
|
+
$body: HTMLDivElement;
|
|
219
|
+
/**
|
|
220
|
+
* The container element where the container's content will be appended.
|
|
221
|
+
*/
|
|
16
222
|
$container: HTMLElement;
|
|
17
|
-
options: Required<DatePickerOptions>;
|
|
18
|
-
private _open;
|
|
19
|
-
private _date;
|
|
20
|
-
private _change;
|
|
21
|
-
constructor(container: HTMLElement, options: DatePickerOptions);
|
|
22
|
-
_init(): void;
|
|
23
223
|
/**
|
|
24
|
-
*
|
|
224
|
+
* The language used for localization.
|
|
225
|
+
*/
|
|
226
|
+
language: string;
|
|
227
|
+
/**
|
|
228
|
+
* header.
|
|
229
|
+
*/
|
|
230
|
+
header: Header | null;
|
|
231
|
+
/**
|
|
232
|
+
* The locale object for the current language.
|
|
233
|
+
*/
|
|
234
|
+
locale: CalendarLocale;
|
|
235
|
+
constructor(popupContainer: PopupContainerEle | null, options: ContainerOptions);
|
|
236
|
+
/**
|
|
237
|
+
* set locale
|
|
238
|
+
* @private
|
|
239
|
+
* @returns {void}
|
|
240
|
+
*/
|
|
241
|
+
private _setLocale;
|
|
242
|
+
/**
|
|
243
|
+
* destroy content node
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* container.destroy();
|
|
247
|
+
* ```
|
|
248
|
+
* @returns {void}
|
|
249
|
+
*/
|
|
250
|
+
destroy(): void;
|
|
251
|
+
/**
|
|
252
|
+
* set locale
|
|
253
|
+
* @param {"en-US" | "zh-CN" | L} locale locale
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* container.setLocale("zh-CN");
|
|
257
|
+
* container.setLocale({ today: "今天" });
|
|
258
|
+
* ```
|
|
259
|
+
* @returns {void}
|
|
260
|
+
*/
|
|
261
|
+
setLocale(locale: 'en-US' | 'zh-CN' | string): void;
|
|
262
|
+
protected _onSuperPrev(): void;
|
|
263
|
+
protected _onSuperNext(): void;
|
|
264
|
+
protected _onPrev(): void;
|
|
265
|
+
protected _onNext(): void;
|
|
266
|
+
protected _onClose(): void;
|
|
267
|
+
protected _onOk(): void;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
interface CalendarOptions extends ContainerOptions, Omit<HeaderOptions, "prefixCls" | "content"> {
|
|
271
|
+
/** 当前选中日期 new Date() | "2025-01-01" | "2025-01-01T00:00:00.000Z" | "2025/01/01" */
|
|
272
|
+
current?: Date | string;
|
|
273
|
+
/** 周起始位置 0-6 0:周日 1:周一 2:周二 3:周三 4:周四 5:周五 6:周六 */
|
|
274
|
+
startOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
275
|
+
/** 是否展示头部 */
|
|
276
|
+
showHeader?: boolean;
|
|
277
|
+
/** 自定义 super prev 按钮图标 */
|
|
278
|
+
renderSuperPrevIcon?: HeaderOptions["renderSuperPrevIcon"];
|
|
279
|
+
/** 自定义 super next 按钮图标 */
|
|
280
|
+
renderSuperNextIcon?: HeaderOptions["renderSuperNextIcon"];
|
|
281
|
+
/** 自定义 prev 按钮图标 */
|
|
282
|
+
renderPrevIcon?: HeaderOptions["renderPrevIcon"];
|
|
283
|
+
/** 自定义 next 按钮图标 */
|
|
284
|
+
renderNextIcon?: HeaderOptions["renderNextIcon"];
|
|
285
|
+
/** 展示前一年按钮图标 */
|
|
286
|
+
showSuperPrevIcon?: boolean;
|
|
287
|
+
/** 展示下一年按钮图标 */
|
|
288
|
+
showSuperNextIcon?: boolean;
|
|
289
|
+
/** 展示前一月按钮图标 */
|
|
290
|
+
showPrevIcon?: boolean;
|
|
291
|
+
/** 展示下一月按钮图标 */
|
|
292
|
+
showNextIcon?: boolean;
|
|
293
|
+
/** 徽章点标记日期列表,默认 [], 格式 ["2025-01-01", "2025-01-02", "2025-01-03"] */
|
|
294
|
+
badges?: string[];
|
|
295
|
+
/**
|
|
296
|
+
* 自定义徽章点标记 dom 字符串
|
|
297
|
+
*/
|
|
298
|
+
renderBadge?: string | ((date: Date, dateStr: string) => string);
|
|
299
|
+
/**
|
|
300
|
+
* 徽章点标记日期列表,默认 [], 默认true展示徽章点
|
|
301
|
+
* @param date 日期
|
|
302
|
+
* @param dateStr 日期字符串
|
|
303
|
+
* @returns true 展示徽章点,false不展示徽章点
|
|
304
|
+
*/
|
|
305
|
+
showBadge?: (date: Date, dateStr: string) => boolean;
|
|
306
|
+
/**
|
|
307
|
+
* 自定义year cell render
|
|
308
|
+
* @param date 日期
|
|
309
|
+
* @param dateStr 日期字符串
|
|
25
310
|
*/
|
|
26
|
-
|
|
311
|
+
renderDate?: (date: Date, dateStr: string) => string;
|
|
312
|
+
/**
|
|
313
|
+
* 禁用日期
|
|
314
|
+
* @param date 日期
|
|
315
|
+
* @param dateStr 日期字符串
|
|
316
|
+
*/
|
|
317
|
+
disabledDate?: (date: Date, dateStr: string) => boolean;
|
|
318
|
+
/**
|
|
319
|
+
* 日期变换回调
|
|
320
|
+
* @param date 日期变化
|
|
321
|
+
* @param dateStr 日期字符串
|
|
322
|
+
*/
|
|
323
|
+
onChange?: (date: Date, dateStr: string) => void;
|
|
324
|
+
/**
|
|
325
|
+
* 点击日期日回调
|
|
326
|
+
* @param date 点击的日期
|
|
327
|
+
* @param renderDate 渲染日期
|
|
328
|
+
*/
|
|
329
|
+
onCell?: (date: Date, renderDate: Date) => void;
|
|
330
|
+
/**
|
|
331
|
+
* 点击上一年回调
|
|
332
|
+
* @param current 当前选中的日期
|
|
333
|
+
* @param prev 上一年日期
|
|
334
|
+
*/
|
|
335
|
+
onPrevYear?: (current: Date, prev: Date) => void;
|
|
336
|
+
/**
|
|
337
|
+
* 点击下一年回调
|
|
338
|
+
* @param current 当前选中的日期
|
|
339
|
+
* @param next 下一年日期
|
|
340
|
+
*/
|
|
341
|
+
onNextYear?: (current: Date, next: Date) => void;
|
|
342
|
+
/**
|
|
343
|
+
* 点击上一月回调
|
|
344
|
+
* @param current 当前选中的日期
|
|
345
|
+
* @param prev 上一月日期
|
|
346
|
+
*/
|
|
347
|
+
onPrevMonth?: (current: Date, prev: Date) => void;
|
|
348
|
+
/**
|
|
349
|
+
* 点击下一月回调
|
|
350
|
+
* @param current 当前选中的日期
|
|
351
|
+
* @param next 下一月日期
|
|
352
|
+
*/
|
|
353
|
+
onNextMonth?: (current: Date, next: Date) => void;
|
|
354
|
+
/**
|
|
355
|
+
* 点击年回调,仅当有值才可以触发
|
|
356
|
+
* @param current 当前选中的日期
|
|
357
|
+
* @param renderDate 渲染日期
|
|
358
|
+
*/
|
|
359
|
+
onYear?: (current: Date, renderDate: Date) => void;
|
|
360
|
+
/**
|
|
361
|
+
* 点击月回调,仅当有值才可以触发
|
|
362
|
+
* @param current 当前选中的日期
|
|
363
|
+
* @param renderDate 渲染日期
|
|
364
|
+
* @returns
|
|
365
|
+
*/
|
|
366
|
+
onMonth?: (current: Date, renderDate: Date) => void;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* 日历
|
|
371
|
+
* @param {CalendarOptions} options
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* const calendar = new Calendar(document.getElementById('container'), {
|
|
375
|
+
* startOfWeek: 0,
|
|
376
|
+
* language: 'en',
|
|
377
|
+
* })
|
|
378
|
+
*
|
|
379
|
+
* calendar.setCurrent(new Date());
|
|
380
|
+
* calendar.setCurrent(new Date('2025-01-01'));
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
declare class Calendar extends Container<CalendarOptions> {
|
|
384
|
+
private _current;
|
|
385
|
+
private _renderCurrent;
|
|
386
|
+
static DateTime: typeof DateTime;
|
|
387
|
+
badges: Array<string | Date>;
|
|
388
|
+
/**
|
|
389
|
+
* 日历
|
|
390
|
+
* @param container 容器节点
|
|
391
|
+
* @param options 日历配置项
|
|
392
|
+
*/
|
|
393
|
+
constructor(container: PopupContainerEle, options: CalendarOptions);
|
|
394
|
+
/**
|
|
395
|
+
* 当前选择的日期
|
|
396
|
+
*/
|
|
397
|
+
get current(): Date;
|
|
398
|
+
/**
|
|
399
|
+
* 设置当前设置的日期
|
|
400
|
+
* @param {Date | string} date 当前选择的日期
|
|
401
|
+
* @param {boolean} change 是否触发 onChange, 默认 true
|
|
402
|
+
* @returns {void}
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts
|
|
405
|
+
* calendar.setCurrent(new Date()); // 设置当前选择的日期 支持多种时间格式
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
setCurrent(date?: Date | string, change?: boolean): void;
|
|
409
|
+
/**
|
|
410
|
+
* 更新徽章点
|
|
411
|
+
* @param {Array<string | Date>} badges 徽章点列表
|
|
412
|
+
* @returns {void}
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* calendar.updateBadges([new Date(), new Date('2025-01-01')]);
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
updateBadges(badges: Array<string | Date>): void;
|
|
419
|
+
private _setRenderCurrent;
|
|
420
|
+
private _onCell;
|
|
421
|
+
/**
|
|
422
|
+
* 上一年
|
|
423
|
+
* @override 重写 Container 的 _onSuperPrev
|
|
424
|
+
*/
|
|
425
|
+
protected _onSuperPrev(): void;
|
|
426
|
+
/**
|
|
427
|
+
* 下一年
|
|
428
|
+
* @override 重写 Container 的 _onSuperNext
|
|
429
|
+
*/
|
|
430
|
+
protected _onSuperNext(): void;
|
|
431
|
+
/**
|
|
432
|
+
* 上一月
|
|
433
|
+
* @override 重写 Container 的 _onPrev
|
|
434
|
+
*/
|
|
435
|
+
protected _onPrev(): void;
|
|
436
|
+
/**
|
|
437
|
+
* 下一月
|
|
438
|
+
* @override 重写 Container 的 _onNext
|
|
439
|
+
*/
|
|
440
|
+
protected _onNext(): void;
|
|
441
|
+
/**
|
|
442
|
+
* 头部点击事件
|
|
443
|
+
*/
|
|
444
|
+
private _onHeader;
|
|
445
|
+
/**
|
|
446
|
+
* 点击确定
|
|
447
|
+
* @override 覆盖Container的 _onOk
|
|
448
|
+
*/
|
|
449
|
+
protected _onOk(): void;
|
|
450
|
+
/**
|
|
451
|
+
* 点击关闭
|
|
452
|
+
* @override 覆盖Container的 _onClose
|
|
453
|
+
*/
|
|
454
|
+
protected _onClose(): void;
|
|
455
|
+
/**
|
|
456
|
+
* 渲染
|
|
457
|
+
*/
|
|
458
|
+
private _render;
|
|
459
|
+
/**
|
|
460
|
+
* 渲染日期
|
|
461
|
+
*/
|
|
462
|
+
private _renderDate;
|
|
463
|
+
/**
|
|
464
|
+
* 渲染徽章
|
|
465
|
+
* @param date
|
|
466
|
+
* @param dateStr
|
|
467
|
+
* @returns
|
|
468
|
+
*/
|
|
469
|
+
private _renderBadge;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* 月份选择器配置项
|
|
474
|
+
*/
|
|
475
|
+
interface MonthOptions extends Omit<ContainerOptions, 'showPrevIcon' | 'showNextIcon' | 'renderPrevIcon' | 'renderNextIcon' | 'content'> {
|
|
476
|
+
/** 当前时间 或当前年月份 new Date() | "2025-01" | "2025-01-01" | "2025/01" | "2025/01/01" */
|
|
477
|
+
current?: Date | string;
|
|
478
|
+
/** cell 高度 */
|
|
479
|
+
cellHeight?: number;
|
|
480
|
+
/** cell 宽度 */
|
|
481
|
+
cellWidth?: number;
|
|
482
|
+
/** 展示header */
|
|
483
|
+
showHeader?: boolean;
|
|
484
|
+
/** 自定义 render month cell */
|
|
485
|
+
monthRender?: (date: Date, dateStr: string) => string;
|
|
486
|
+
/** 年份变化时触发 */
|
|
487
|
+
onChange?: (currentDate: Date, currentDateStr: string) => void;
|
|
488
|
+
/** 点击月份触发 */
|
|
489
|
+
onCell?: (currentDate: Date, currentDateStr: string) => void;
|
|
490
|
+
/** 禁用月份, true 禁用 */
|
|
491
|
+
disabledMonth?: (date: Date, month: string) => boolean;
|
|
492
|
+
/**
|
|
493
|
+
* @param currentDate 当前选中的日期
|
|
494
|
+
* @param renderDate 渲染的日期
|
|
495
|
+
*/
|
|
496
|
+
onYear?: (currentDate: Date, renderDate: Date) => void;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* 月历 (12 月)
|
|
500
|
+
* @param popupContainer
|
|
501
|
+
* @param options
|
|
502
|
+
* @returns
|
|
503
|
+
* @example
|
|
504
|
+
* ```ts
|
|
505
|
+
* const month = new Month(document.body, {
|
|
506
|
+
* onChange: (date: Date) => {}
|
|
507
|
+
* })
|
|
508
|
+
* month.setCurrent("2025-01")
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
declare class Month extends Container<MonthOptions> {
|
|
512
|
+
private _current;
|
|
513
|
+
private _renderCurrent;
|
|
514
|
+
/**
|
|
515
|
+
* @param popupContainer 容器节点
|
|
516
|
+
* @param options 配置
|
|
517
|
+
*/
|
|
518
|
+
constructor(popupContainer: PopupContainerEle, options: MonthOptions);
|
|
519
|
+
/**
|
|
520
|
+
* 设置选中月份
|
|
521
|
+
* @param date 日期
|
|
522
|
+
* @param {boolean} change 是否触发 onChange 事件
|
|
523
|
+
* @example
|
|
524
|
+
* ```ts
|
|
525
|
+
* month.setCurrent("2025-01")
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
setCurrent(date?: string | Date, change?: boolean): void;
|
|
529
|
+
/**
|
|
530
|
+
* 当前选中的月份日期
|
|
531
|
+
* @example
|
|
532
|
+
* ```ts
|
|
533
|
+
* month.current
|
|
534
|
+
* ```
|
|
535
|
+
* @returns {Date}
|
|
536
|
+
*/
|
|
537
|
+
get current(): Date;
|
|
538
|
+
/**
|
|
539
|
+
* 设置选中月份
|
|
540
|
+
* @param date 日期
|
|
541
|
+
* @param {boolean} change 是否触发 onChange 事件
|
|
542
|
+
*/
|
|
543
|
+
private _setCurrent;
|
|
544
|
+
private _setRenderCurrent;
|
|
545
|
+
/**
|
|
546
|
+
* 点击确定
|
|
547
|
+
* @override 重写 Container 的 _onOk
|
|
548
|
+
*/
|
|
549
|
+
protected _onOk(): void;
|
|
550
|
+
/**
|
|
551
|
+
* 点击关闭
|
|
552
|
+
* @override 重写 Container 的 _onClose
|
|
553
|
+
*/
|
|
554
|
+
protected _onClose(): void;
|
|
555
|
+
/**
|
|
556
|
+
* 点击月份
|
|
557
|
+
*/
|
|
558
|
+
private _onCell;
|
|
559
|
+
/**
|
|
560
|
+
* 上一年
|
|
561
|
+
* @override 重写 Container 的 _onSuperPrev
|
|
562
|
+
*/
|
|
563
|
+
protected _onSuperPrev(): void;
|
|
564
|
+
/**
|
|
565
|
+
* 下一年
|
|
566
|
+
* @override 重写 Container 的 _onSuperNext
|
|
567
|
+
*/
|
|
568
|
+
protected _onSuperNext(): void;
|
|
569
|
+
/**
|
|
570
|
+
* 点击头部标题
|
|
571
|
+
*/
|
|
572
|
+
private _onHeaderTitle;
|
|
573
|
+
private _setHeader;
|
|
574
|
+
private _setDisabled;
|
|
575
|
+
private _render;
|
|
576
|
+
private _renderMonths;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* 年历 (12 年)配置项
|
|
581
|
+
*/
|
|
582
|
+
interface YearOptions extends Omit<ContainerOptions, 'showPrevIcon' | 'showNextIcon' | 'renderPrevIcon' | 'renderNextIcon'> {
|
|
583
|
+
/** 当前时间 或当前年份 */
|
|
584
|
+
current?: Date | number;
|
|
585
|
+
/** 是否展示头部, 默认 true */
|
|
586
|
+
showHeader?: boolean;
|
|
587
|
+
/**
|
|
588
|
+
* 自定义year cell render
|
|
589
|
+
* @param year 年份
|
|
590
|
+
* @param yearStr 年份字符串
|
|
591
|
+
*/
|
|
592
|
+
yearRender?: (year: Date, yearStr: number) => string;
|
|
593
|
+
/**
|
|
594
|
+
* 年份变化时触发
|
|
595
|
+
* @param year 变化年份(禁用年份不会触发)
|
|
596
|
+
*/
|
|
597
|
+
onChange?: (year: Date) => void;
|
|
598
|
+
/**
|
|
599
|
+
* 点击年份触发
|
|
600
|
+
* @param year 点击年份(包括禁用年份)
|
|
601
|
+
*/
|
|
602
|
+
onCell?: (year: Date) => void;
|
|
603
|
+
/**
|
|
604
|
+
* 禁用年份, true 禁用
|
|
605
|
+
* @param year 当前年份
|
|
606
|
+
* @param yearStr 当前年份字符串
|
|
607
|
+
*/
|
|
608
|
+
disabledYear?: (year: Date, yearStr: number) => boolean;
|
|
609
|
+
/**
|
|
610
|
+
* 点击上一年回调
|
|
611
|
+
* @param current 当前选中的日期
|
|
612
|
+
* @param years 上一个12年
|
|
613
|
+
*/
|
|
614
|
+
onPrevYear?: (current: Date, years: number[]) => void;
|
|
615
|
+
/**
|
|
616
|
+
* 点击下一年回调
|
|
617
|
+
* @param current 当前选中的日期
|
|
618
|
+
* @param years 下一个12年
|
|
619
|
+
*/
|
|
620
|
+
onNextYear?: (current: Date, years: number[]) => void;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* 年历 (12 年)
|
|
624
|
+
* @example
|
|
625
|
+
* ```ts
|
|
626
|
+
* const year = new Year(document.body, {
|
|
627
|
+
* onChange: (date: Date) => {}
|
|
628
|
+
* })
|
|
629
|
+
* year.setCurrent(2023)
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
declare class Year extends Container<YearOptions> {
|
|
633
|
+
_current: Date;
|
|
634
|
+
_renderTenYear: number;
|
|
27
635
|
/**
|
|
28
|
-
* 设置日期, change = true 时触发 onChange 事件
|
|
29
636
|
*
|
|
30
|
-
* @param
|
|
637
|
+
* @param popupContainer 容器节点
|
|
638
|
+
* @param options 年历配置项
|
|
639
|
+
*/
|
|
640
|
+
constructor(popupContainer: PopupContainerEle, options: YearOptions);
|
|
641
|
+
/**
|
|
642
|
+
* 设置当前年份
|
|
643
|
+
* @param year
|
|
31
644
|
* @param change 是否触发 onChange 事件
|
|
645
|
+
* @returns
|
|
646
|
+
* @example
|
|
647
|
+
* ```ts
|
|
648
|
+
* year.setCurrent(2023)
|
|
649
|
+
* ```
|
|
650
|
+
*/
|
|
651
|
+
setCurrent(year: number | Date, change?: boolean): void;
|
|
652
|
+
/**
|
|
653
|
+
* 当前年份
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
656
|
+
* year.current
|
|
657
|
+
* ```
|
|
658
|
+
*/
|
|
659
|
+
get current(): Date;
|
|
660
|
+
private _setCurrent;
|
|
661
|
+
/**
|
|
662
|
+
* 点击确定
|
|
663
|
+
* @override 重写 Container 的 _onOk
|
|
664
|
+
*/
|
|
665
|
+
protected _onOk(): void;
|
|
666
|
+
/**
|
|
667
|
+
* 点击关闭
|
|
668
|
+
* @override 重写 Container 的 _onClose
|
|
32
669
|
*/
|
|
33
|
-
|
|
670
|
+
protected _onClose(): void;
|
|
34
671
|
/**
|
|
35
|
-
*
|
|
672
|
+
* 点击年份
|
|
36
673
|
*/
|
|
37
|
-
|
|
674
|
+
private _onCell;
|
|
38
675
|
/**
|
|
39
|
-
*
|
|
676
|
+
* 上十年
|
|
677
|
+
* @override 重写 Container 的 _onSuperPrev
|
|
40
678
|
*/
|
|
41
|
-
|
|
679
|
+
protected _onSuperPrev(): void;
|
|
680
|
+
/**
|
|
681
|
+
* 下十年
|
|
682
|
+
* @override 重写 Container 的 _onSuperNext
|
|
683
|
+
*/
|
|
684
|
+
protected _onSuperNext(): void;
|
|
685
|
+
private _render;
|
|
686
|
+
private _renderYearList;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* 支持模型类型
|
|
691
|
+
*/
|
|
692
|
+
type DatePickerModeType = 'date' | 'month' | 'year';
|
|
693
|
+
interface DatePickerOptions extends PickerOptions, Omit<CalendarOptions, "onChange" | "onCell" | "onOk" | "onClose"> {
|
|
694
|
+
onChange?: (date: Date, mode: string) => void;
|
|
695
|
+
onCell?: (date: Date, mode: string) => void;
|
|
696
|
+
onPanelOpen?: (open: boolean) => void;
|
|
697
|
+
onOk?: (date: Date, mode: DatePickerModeType) => void;
|
|
698
|
+
onClose?: (date: Date, mode: DatePickerModeType) => void;
|
|
699
|
+
mode: DatePickerModeType;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* date picker
|
|
703
|
+
* @example
|
|
704
|
+
* ```ts
|
|
705
|
+
* const picker = new DatePicker(document.getElementById('picker'), {
|
|
706
|
+
* onChange: (date) => {}
|
|
707
|
+
* })
|
|
708
|
+
* picker.setCurrent(new Date())
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
declare class DatePicker extends Picker {
|
|
712
|
+
options: DatePickerOptions;
|
|
713
|
+
current: Date | null;
|
|
714
|
+
_current: Date | null;
|
|
715
|
+
private _calendar;
|
|
716
|
+
private _month;
|
|
717
|
+
private _year;
|
|
718
|
+
private _currentMode;
|
|
719
|
+
constructor(container: HTMLElement | (() => HTMLElement) | null, options: DatePickerOptions);
|
|
720
|
+
/**
|
|
721
|
+
* 设置时间
|
|
722
|
+
* @param {Date} date
|
|
723
|
+
* @example
|
|
724
|
+
* ```ts
|
|
725
|
+
* picker.setCurrent(2025)
|
|
726
|
+
* picker.setCurrent(new Date())
|
|
727
|
+
* ```
|
|
728
|
+
*/
|
|
729
|
+
setCurrent(date: Date): void;
|
|
730
|
+
/**
|
|
731
|
+
* 更新徽章点
|
|
732
|
+
* @param {Array<string | Date>} badges 徽章点列表
|
|
733
|
+
*/
|
|
734
|
+
updateBadges(badges: Array<string | Date>): void;
|
|
42
735
|
/**
|
|
43
736
|
* 销毁
|
|
737
|
+
* @example
|
|
738
|
+
* ```ts
|
|
739
|
+
* picker.destroy()
|
|
740
|
+
* ```
|
|
44
741
|
*/
|
|
45
742
|
destroy(): void;
|
|
743
|
+
/**
|
|
744
|
+
* 当前最小模式索引, 当模式下标是最小的, 不可以再小
|
|
745
|
+
*/
|
|
746
|
+
private get _minModeIndex();
|
|
747
|
+
private _setCurrent;
|
|
748
|
+
private _switchMode;
|
|
749
|
+
private _hide;
|
|
750
|
+
/**
|
|
751
|
+
* @overload 重置
|
|
752
|
+
* @param open
|
|
753
|
+
*/
|
|
754
|
+
protected _onOpenChange(open: boolean): void;
|
|
755
|
+
private _initCalendar;
|
|
756
|
+
private _initMonth;
|
|
757
|
+
private _initYear;
|
|
758
|
+
private _onOk;
|
|
759
|
+
private _onClose;
|
|
760
|
+
private _onChange;
|
|
761
|
+
private _onCell;
|
|
762
|
+
private _onYear;
|
|
763
|
+
private _onMonth;
|
|
764
|
+
private _removeCurrentTypeClass;
|
|
46
765
|
}
|
|
47
766
|
|
|
48
|
-
export { DatePicker
|
|
767
|
+
export { Calendar, DatePicker, Header, Month, Year };
|
|
768
|
+
export type { CalendarLocale, CalendarOptions, ContainerOptions, DatePickerModeType, DatePickerOptions, HeaderOptions, MonthOptions, PopupContainerEle, YearOptions };
|