forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pikaday.d.ts
305 lines (250 loc) · 7.98 KB
/
pikaday.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
// Type definitions for pikaday
// Project: https://github.com/dbushell/Pikaday
// Definitions by: Rudolph Gottesheim <http://midnight-design.at/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../moment/moment.d.ts" />
declare class Pikaday {
el: HTMLElement;
constructor(options: Pikaday.PikadayOptions);
/**
* Extends the existing configuration options for Pikaday object with the options provided.
* Can be used to change/extend the configurations on runtime.
* @param options full/partial configuration options.
* @returns {} extended configurations.
*/
config(options: Pikaday.PikadayOptions): Pikaday.PikadayOptions;
/**
* Returns the selected date in a string format. If Moment.js exists
* (recommended) then Pikaday can return any format that Moment
* understands, otherwise you're stuck with JavaScript's default.
*/
toString(format?: string): string;
/**
* Returns a JavaScript Date object for the selected day, or null if
* no date is selected.
*/
getDate(): Date;
/**
* Set the current selection. This will be restricted within the bounds
* of minDate and maxDate options if they're specified. A boolean (true)
* can optionally be passed as the second parameter to prevent triggering
* of the onSelect callback, allowing the date to be set silently.
*/
setDate(date: string | Date, triggerOnSelect?: boolean): void;
/**
* Returns a Moment.js object for the selected date (Moment must be
* loaded before Pikaday).
*/
getMoment(): moment.Moment;
/**
* Set the current selection with a Moment.js object (see setDate).
*/
setMoment(moment: any): void;
/**
* Change the current view to see a specific date.
*/
gotoDate(date: Date): void;
/**
* Shortcut for picker.gotoDate(new Date())
*/
gotoToday(): void;
/**
* Change the current view by month (0: January, 1: Februrary, etc).
*/
gotoMonth(monthIndex: number): void;
/**
* Go to the next month (this will change year if necessary).
*/
nextMonth(): void;
/**
* Go to the previous month (this will change year if necessary).
*/
prevMonth(): void;
/**
* Change the year being viewed.
*/
gotoYear(year: number): void;
/**
* Update the minimum/earliest date that can be selected.
*/
setMinDate(date: Date): void;
/**
* Update the maximum/latest date that can be selected.
*/
setMaxDate(date: Date): void;
/**
* Update the range start date. For using two Pikaday instances to
* select a date range.
*/
setStartRange(date: Date): void;
/**
* Update the range end date. For using two Pikaday instances to select
* a date range.
*/
setEndRange(date: Date): void;
/**
* Update the HTML.
*/
draw(force: boolean): void;
/**
* Returns true if the picker is visible.
*/
isVisible(): boolean;
/**
* Make the picker visible.
*/
show(): void;
/**
* Hide the picker making it invisible.
*/
hide(): void;
/**
* Recalculate and change the position of the picker.
*/
adjustPosition(): void;
/**
* Hide the picker and remove all event listeners - no going back!
*/
destroy(): void;
}
// merge the Pikaday class declaration with a module
declare namespace Pikaday {
interface PikadayI18nConfig {
previousMonth: string;
nextMonth: string;
months: string[];
weekdays: string[];
weekdaysShort: string[];
}
interface PikadayOptions {
/**
* Bind the datepicker to a form field.
*/
field?: HTMLElement;
/**
* The default output format for toString() and field value.
* Requires Moment.js for custom formatting.
*/
format?: string;
/**
* Use a different element to trigger opening the datepicker.
* Default: field element.
*/
trigger?: HTMLElement;
/**
* Automatically show/hide the datepicker on field focus.
* Default: true if field is set.
*/
bound?: boolean;
/**
* Preferred position of the datepicker relative to the form field
* (e.g. 'top right'). Automatic adjustment may occur to avoid
* displaying outside the viewport. Default: 'bottom left'.
*/
position?: string;
/**
* Can be set to false to not reposition the datepicker within the
* viewport, forcing it to take the configured position. Default: true.
*/
reposition?: boolean;
/**
* DOM node to render calendar into, see container example.
* Default: undefined.
*/
container?: HTMLElement;
/**
* The initial date to view when first opened.
*/
defaultDate?: Date;
/**
* Make the defaultDate the initial selected value.
*/
setDefaultDate?: boolean;
/**
* First day of the week (0: Sunday, 1: Monday, etc).
*/
firstDay?: number;
/**
* The earliest date that can be selected (this should be a native
* Date object - e.g. new Date() or moment().toDate()).
*/
minDate?: Date;
/**
* The latest date that can be selected (this should be a native
* Date object - e.g. new Date() or moment().toDate()).
*/
maxDate?: Date;
/**
* Disallow selection of Saturdays and Sundays.
*/
disableWeekends?: boolean;
/**
* Callback function that gets passed a Date object for each day
* in view. Should return true to disable selection of that day.
*/
disableDayFn?: (date: Date) => boolean;
/**
* Number of years either side (e.g. 10) or array of upper/lower range
* (e.g. [1900, 2015]).
*/
yearRange?: number | number[];
/**
* Show the ISO week number at the head of the row. Default: false.
*/
showWeekNumber?: boolean;
/**
* Reverse the calendar for right-to-left languages. Default: false.
*/
isRTL?: boolean;
/**
* Language defaults for month and weekday names.
*/
i18n?: PikadayI18nConfig;
/**
* Additional text to append to the year in the title.
*/
yearSuffix?: string;
/**
* Render the month after the year in the title. Default: false.
*/
showMonthAfterYear?: boolean;
/**
* Render days of the calendar grid that fall in the next or previous months to the current month instead of rendering an empty table cell. Default: false.
*/
showDaysInNextAndPreviousMonths?: boolean;
/**
* Number of visible calendars.
*/
numberOfMonths?: number;
/**
* When numberOfMonths is used, this will help you to choose where the
* main calendar will be (default left, can be set to right). Only used
* for the first display or when a selected date is not already visible.
*/
mainCalendar?: string;
/**
* Define a class name that can be used as a hook for styling different
* themes. Default: null.
*/
theme?: string;
/**
* Callback function for when a date is selected.
*/
onSelect?: (date: Date) => void;
/**
* Callback function for when the picker becomes visible.
*/
onOpen?: () => void;
/**
* Callback function for when the picker is hidden.
*/
onClose?: () => void;
/**
* Callback function for when the picker draws a new month.
*/
onDraw?: () => void;
}
}
declare module "pikaday" {
export = Pikaday;
}