forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpickadate.d.ts
474 lines (384 loc) · 13.9 KB
/
pickadate.d.ts
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
// Type definitions for pickadate.js 3.5.4
// Project: https://github.com/amsul/pickadate.js
// Definitions by: Adi Dahiya <https://github.com/adidahiya>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module Pickadate {
export interface Api {
/**
* Clear the value in the picker's input element.
*/
clear(): Pickadate.Api;
/**
* Close the picker.
*
* @param keepFocus whether to retain focus on the input element (default: false)
*/
close(keepFocus?: boolean): Pickadate.Api;
/**
* Get the properties, objects, and states of the picker.
*
* @param field one of [ "value", "select", "highlight", "view", "min", "max", "open", "start", "id", "disable", "enable" ]
* @param format string formatter (available for certain fields)
*/
get(field: string, format?: string): any;
/**
* Returns the string value of the picker’s input element.
*/
get(field: "value"): string;
/**
* Returns a boolean value of whether the picker is open or not.
*/
get(field: "open"): boolean;
/**
* Returns a boolean value of whether the picker has started or not.
*/
get(field: "start"): boolean;
/**
* Returns a unique string that is the ID of the picker and it’s element. If the element has no ID, it is set to something random.
*/
get(field: "id"): string;
/**
* "enable" and "disable" work together to determine which item objects to disable on the picker.
*
* "enable" returns 1 to represent a base enabled state, meaning that specific dates or times are disabled and all others are enabled;
* or -1 to indicate a base disabled state, meaning that specific dates or times are enabled and all others are disabled.
*/
get(field: "enable"): number;
/**
* If "enable" is 1, returns the collection of dates or times to disable. If "enable" is -1, returns the collection of dates or
* times to *not* disable.
*/
get(field: "disable"): any;
/**
* Unbind callbacks that are bound using the `on` method.
* @param methodName one of [ "open, "close", "render", "start", "stop", "set" ]
*/
off(methodName: string, ...moreMethodNames: string[]): Pickadate.Api;
/**
* Attach an event handler for the picker. Only "set" events callbacks receive a "context" object.
*
* @param methodName event to attach handler to, one of [ "open", "close", "render", "start", "stop", or "set" ]
* @param callback event handler
*/
on(methodName: string, callback: (context?: any) => void): Pickadate.Api;
/**
* Open the picker.
*
* @param keepFocus whether to focus the input element (default: true)
*/
open(keepFocus?: boolean): Pickadate.Api;
/**
* Refresh the picker after adding something to the holder.
* By default, only the "face" of the picker (i.e. the box element), has its contents re-rendered.
*
* @param fromRoot whether to render the entire picker from the root up (default: false)
*/
render(fromRoot?: boolean): Pickadate.Api;
/**
* Set the properties, objects, and states of the picker.
*
* @param field one of [ "clear", "select", "highlight", "view", "min", "max", "disable", "enable", "interval" ]
* @param value the thing you want to set
*/
set(field: string, value: any, options?: {[key: string]: any}): Pickadate.Api;
/**
* Batch set picker options after initialization.
*/
set(values: {[field: string]: any}, options?: {[key: string]: any}): Pickadate.Api;
/**
* Rebuild the picker.
*/
start(): Pickadate.Api;
/**
* Destroy the picker.
*/
stop(): Pickadate.Api;
/**
* Trigger a picker event.
* @param eventName the event to trigger
*/
trigger(eventName: string): Pickadate.Api;
/**
* The picker's relative <input> element.
*/
$node: JQuery;
/**
* The picker's relative root holder element.
*/
$root: JQuery;
/**
* The picker's relative hidden element, which is undefined if there's no formatSubmit option.
* This is meant to be mostly for internal use.
*/
_hidden: JQuery;
}
export interface DateApi extends Api {
get(field: string, format?: string): any;
/**
* Returns the item object or formatted string of the date that is visually selected.
* Defaults to null when there’s no value.
*/
get(field: "select"): DateItem;
get(field: "select", format: string): string;
/**
* Returns the item object or formatted string of the date that is visually highlighted.
* Defaults to "today" when there’s no value.
*/
get(field: "highlight"): DateItem;
get(field: "highlight", format: string): string;
/**
* Returns the item object or formatted string of the date that determines the current view.
* Defaults to the first day of the current month when there’s no value.
*/
get(field: "view"): DateItem;
get(field: "view", format: string): string;
/**
* Returns the item object or formatted string of the date that determines the lower limit.
* Defaults to a -Infinity item object when it is not explicitly set in the options or through the picker’s API.
*/
get(field: "min"): DateItem;
get(field: "min", format: string): string;
/**
* Returns the item object or formatted string of the date that determines the upper limit.
* Defaults to an Infinity item object when it is not explicitly set in the options or through the picker’s API.
*/
get(field: "max"): DateItem;
get(field: "max", format: string): string;
}
export interface DateItem {
// The full year.
year: number;
// The month with zero-as-index.
month: number;
// The date of the month.
date: number;
// The day of the week with zero-as-index.
day: number;
// The underlying JavaScript Date object.
obj: Date;
// The "pick" value used for comparisons.
pick: number;
}
export interface DateOptions {
// String and translations
monthsFull?: string[];
monthsShort?: string[];
weekdaysFull?: string[];
weekdaysShort?: string[]
showMonthsShort?: boolean;
showWeekdaysFull?: boolean;
// Button labels (if falsy, the corresponding button is disabled)
today?: string;
clear?: string;
close?: string;
// Accessibility labels
labelMonthNext?: string;
labelMonthPrev?: string;
labelMonthSelect?: string;
labelYearSelect?: string;
// Formats
format?: string;
formatSubmit?: string;
hiddenPrefix?: string;
hiddenSuffix?: string;
hiddenName?: string;
// Editable input
editable?: boolean;
// Number of months to show in the month selection dropdown OR a boolean
selectMonths?: any;
// Number of years to show in the month selection dropdown OR a boolean
selectYears?: any;
// First day of the week
firstDay?: number
// Disable dates (elements can be Dates, [YEAR, MONTH, DATE] arrays, or integers of the week)
disable?: any[];
// Root container selector (string) or element (JQuery)
container?: any;
// Events
onStart?: () => void;
onRender?: () => void;
onOpen?: () => void;
onClose?: () => void;
onSet?: (context: {[key: string]: any}) => void;
onStop?: () => void;
// Classes
klass?: DateKlassOptions;
}
export interface DateKlassOptions {
// The element states
input?: string;
active?: string;
// The root picker and states
picker?: string;
opened?: string;
focused?: string;
// The picker holder
holder?: string;
// The picker frame, wrapper, and box
frame?: string;
wrap?: string;
box?: string;
// The picker header
header?: string;
// Month navigation
navPrev?: string;
navNext?: string;
navDisabled?: string;
// Month & year labels
month?: string;
year?: string;
// Month & year dropdowns
selectMonth?: string;
selectYear?: string;
// Table of dates
table?: string;
// Weekday labels
weekdays?: string;
// Day states
day?: string;
disabled?: string;
selected?: string;
highlighted?: string;
now?: string;
infocus?: string;
outfocus?: string;
// The picker footer
footer?: string;
// Today, clear, & close buttons
buttonClear?: string;
buttonClose?: string;
buttonToday?: string
}
export interface TimeApi extends Api {
get(field: string, format?: string): any;
/**
* Returns the item object or formatted string of the date that is visually selected.
* Defaults to null when there’s no value.
*/
get(field: "select"): TimeItem;
get(field: "select", format: string): string;
/**
* Returns the item object or formatted string of the date that is visually highlighted.
* Defaults to "now" when there’s no value.
*/
get(field: "highlight"): TimeItem;
get(field: "highlight", format: string): string;
/**
* Returns the item object or formatted string of the date that determines the current view.
* Defaults to "now" when there’s no value.
*/
get(field: "view"): TimeItem;
get(field: "view", format: string): string;
/**
* Returns the item object or formatted string of the date that determines the lower limit.
* Defaults to a -Infinity item object when it is not explicitly set in the options or through the picker’s API.
*/
get(field: "min"): TimeItem;
get(field: "min", format: string): string;
/**
* Returns the item object or formatted string of the date that determines the upper limit.
* Defaults to an Infinity item object when it is not explicitly set in the options or through the picker’s API.
*/
get(field: "max"): TimeItem;
get(field: "max", format: string): string;
}
export interface TimeItem {
// Hour of the day from 0 to 23.
hour: number;
// The minutes of the hour from 0 to 59 (based on the interval).
mins: number;
// The "pick" value used for comparisons.
pick: number;
}
export interface TimeOptions {
// Translations and clear button
clear?: string;
// Formats
format?: string;
formatLabel?: string;
formatSubmit?: string;
hiddenPrefix?: string;
hiddenSuffix?: string;
// Editable input
editable?: boolean;
// Time intervals
interval?: number;
// Time limits (can be Dates, arrays formatted as [HOUR, MINUTE], integers, or booleans)
min?: any;
max?: any;
// Disable dates (elements can be Dates, [YEAR, MONTH, DATE] arrays, or integers of the week)
disable?: any[];
// Root container selector (string) or element (JQuery)
container?: any;
// Events
onStart?: () => void;
onRender?: () => void;
onOpen?: () => void;
onClose?: () => void;
onSet?: (context: {[key: string]: any}) => void;
onStop?: () => void;
// Classes
klass?: TimeKlassOptions;
}
export interface TimeKlassOptions {
// The element states
input?: string;
active?: string;
// The root picker and states
picker?: string;
opened?: string;
focused?: string;
// The picker holder
holder?: string;
// The picker frame, wrapper, and box
frame?: string;
wrap?: string;
box?: string;
// List of times
list?: string;
listItem?: string;
// Time states
disabled?: string;
selected?: string;
highlighted?: string;
viewset?: string;
now?: string;
// Clear button
buttonClear?: string;
}
}
interface JQuery {
/**
* Access the API object after initialization.
*/
pickadate(keyword: "picker"): Pickadate.DateApi;
pickadate(objectName: "$node"): JQuery;
pickadate(objectName: "$root"): JQuery;
pickadate(objectName: "_hidden"): JQuery;
/**
* Invoke API methods after picker initialization.
* @param methodName
* @param arguments any arguments to pass to the method
*/
pickadate(methodName: string, ...arguments: any[]): any;
/**
* Initialize a date picker.
* @returns the original JQuery selection
*/
pickadate(options?: Pickadate.DateOptions): JQuery;
pickatime(keyword: "picker"): Pickadate.TimeApi;
pickatime(objectName: "$node"): JQuery;
pickatime(objectName: "$root"): JQuery;
pickatime(objectName: "_hidden"): JQuery;
/**
* Invoke API methods after picker initialization.
* @param methodName
* @param arguments any arguments to pass to the method
*/
pickatime(methodName: string, ...arguments: any[]): any;
/**
* Initialize a time picker.
* @returns the original JQuery selection
*/
pickatime(options?: Pickadate.TimeOptions): JQuery;
}