UNPKG

19.7 kBTypeScriptView Raw
1declare namespace FomanticUI {
2 interface Calendar {
3 settings: CalendarSettings;
4
5 /**
6 * Refresh the calendar
7 */
8 (behavior: 'refresh'): JQuery;
9
10 /**
11 * Call the popup module (e.g. passing show will show the calendar popup)
12 */
13 (behavior: 'popup', arguments: any): JQuery;
14
15 /**
16 * Focus the calendar input
17 */
18 (behavior: 'focus'): JQuery;
19
20 /**
21 * Blur the calendar input
22 */
23 (behavior: 'blur'): JQuery;
24
25 /**
26 * Clear the selected date
27 */
28 (behavior: 'clear'): JQuery;
29
30 /**
31 * Get the selected date
32 */
33 (behavior: 'get date'): Date | string;
34
35 /**
36 * Set the selected date.
37 * Pass false to updateInput to disable updating the input.
38 * Pass false to fireChange to disable the onBeforeChange and onChange callbacks for this change
39 */
40 (behavior: 'set date', date: string, updateInput: boolean, fireChange: boolean): JQuery;
41
42 /**
43 * Get the current selection mode (year, month, day, hour, minute)
44 */
45 (behavior: 'get mode'): 'year' | 'month' | 'day' | 'hour' | 'minute';
46
47 /**
48 * Set the current selection mode (year, month, day, hour, minute)
49 */
50 (behavior: 'set mode', mode: 'year' | 'month' | 'day' | 'hour' | 'minute'): JQuery;
51
52 /**
53 * Get the start date for range selection
54 */
55 (behavior: 'get startDate'): Date | string;
56
57 /**
58 * Set the start date for range selection
59 */
60 (behavior: 'set startDate', date: Date | string): JQuery;
61
62 /**
63 * Get the end date for range selection
64 */
65 (behavior: 'get endDate'): Date | string;
66
67 /**
68 * Set the end date for range selection
69 */
70 (behavior: 'set endDate', date: Date | string): JQuery;
71
72 /**
73 * Get the currently focused date
74 */
75 (behavior: 'get focusDate'): Date | string;
76
77 /**
78 * Set the currently focused date
79 */
80 (behavior: 'set focusDate', date: Date | string): JQuery;
81
82 /**
83 * Set the minimal selectable date
84 */
85 (behavior: 'set minDate', date: Date | string): JQuery;
86
87 /**
88 * Set the maximal selectable date
89 */
90 (behavior: 'set maxDate', date: Date | string): JQuery;
91
92 (behavior: 'destroy'): JQuery;
93
94 <K extends keyof CalendarSettings>(behavior: 'setting', name: K, value?: undefined): Partial<Pick<CalendarSettings, keyof CalendarSettings>>;
95 <K extends keyof CalendarSettings>(behavior: 'setting', name: K, value: CalendarSettings[K]): JQuery;
96 (behavior: 'setting', value: Partial<Pick<CalendarSettings, keyof CalendarSettings>>): JQuery;
97 (settings?: Partial<Pick<CalendarSettings, keyof CalendarSettings>>): JQuery;
98 }
99
100 /**
101 * @see {@link https://fomantic-ui.com/modules/calendar.html#/settings}
102 */
103 interface CalendarSettings {
104 // region Toast Settings
105
106 /**
107 * Picker type, can be 'datetime', 'date', 'time', 'month', or 'year'.
108 *
109 * @default 'datetime'
110 */
111 type: 'datetime' | 'date' | 'time' | 'month' | 'year';
112
113 /**
114 * Day for first day column (0 = Sunday).
115 *
116 * @default 0
117 */
118 firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
119
120 /**
121 * Add row(s) to shorter months to keep day calendar height consistent (6 rows).
122 *
123 * @default 'true'
124 */
125 constantHeight: boolean;
126
127 /**
128 * Show a 'today/now' button at the bottom of the calendar.
129 *
130 * @default false
131 */
132 today: boolean;
133
134 /**
135 * Close the popup after selecting a date/time.
136 *
137 * @default false
138 */
139 closable: true;
140
141 /**
142 * Month before day when parsing/converting date from/to text.
143 *
144 * @default true
145 */
146 monthFirst: boolean;
147
148 /**
149 * Set input to readonly on touch devices.
150 *
151 * @default true
152 */
153 touchReadonly: boolean;
154
155 /**
156 * Create the calendar inline instead of inside a popup.
157 *
158 * @default false
159 */
160 inline: boolean;
161
162 /**
163 * Display the week number on the left.
164 *
165 * @default false
166 */
167 showWeekNumbers: boolean;
168
169 /**
170 * Disable some days of the week from selection (0= Sunday, 1=Monday, ...).
171 *
172 * @default []
173 */
174 disabledDaysOfWeek: number[];
175
176 /**
177 * An array of Date-Objects or Objects with given message to show in a popup when hovering over the appropriate date '{date: Date, message: string}'.
178 *
179 * @default []
180 */
181 disabledDates: object[];
182
183 /**
184 * An array of Date-Objects to be enabled for selection. All other dates are disabled.
185 *
186 * @default []
187 */
188 enabledDates: object[];
189
190 /**
191 * An array of Date-Objects or Objects with given message to show in a popup when hovering over the appropriate date
192 * and an individual class for the cell '{date: Date, message: string, class: string}'.
193 *
194 * @default []
195 */
196 eventDates: object[];
197
198 /**
199 * Default class to be added to each cell of an eventDate date element when no specific class is given to the eventDate element.
200 *
201 * @default 'blue'
202 */
203 eventClass: string;
204
205 /**
206 * Choose when to show the popup (defaults to 'focus' for input, 'click' for others).
207 *
208 * @default null
209 */
210 on: null | 'focus' | 'click';
211
212 /**
213 * Date to display initially when no date is selected (null = now).
214 *
215 * @default null
216 */
217 initialDate: null | Date;
218
219 /**
220 * Display mode to start in, can be 'year', 'month', 'day', 'hour', 'minute' (false = 'day').
221 *
222 * @default false
223 */
224 startMode: false | 'year' | 'month' | 'day' | 'hour' | 'minute';
225
226 /**
227 * Minimum date/time that can be selected, dates/times before are disabled.
228 *
229 * @default null
230 */
231 minDate: null | Date;
232
233 /**
234 * Maximum date/time that can be selected, dates/times after are disabled.
235 *
236 * @default null
237 */
238 maxDate: null | Date;
239
240 /**
241 * Show am/pm in time mode.
242 *
243 * @default true
244 */
245 ampm: boolean;
246
247 /**
248 * Disable year selection mode.
249 *
250 * @default false
251 */
252 disableYear: boolean;
253
254 /**
255 * Disable month selection mode.
256 *
257 * @default false
258 */
259 disableMonth: boolean;
260
261 /**
262 * Disable minute selection mode.
263 *
264 * @default false
265 */
266 disableMinute: boolean;
267
268 /**
269 * Format the input text upon input blur and module creation.
270 *
271 * @default true
272 */
273 formatInput: boolean;
274
275 /**
276 * jQuery object or selector for another calendar that represents the start date of a date range.
277 *
278 * @default null
279 */
280 startCalendar: null | JQuery | string;
281
282 /**
283 * jQuery object or selector for another calendar that represents the end date of a date range.
284 *
285 * @default null
286 */
287 endCalendar: null | JQuery | string;
288
289 /**
290 * Show multiple months when in 'day' mode.
291 *
292 * @default 1
293 */
294 multiMonth: number;
295
296 /**
297 * Minimum time gap, can only be 5, 10, 15, 20, 30.
298 *
299 * @default 5
300 */
301 minTimeGap: 5 | 10 | 15 | 20 | 30;
302
303 /**
304 * Starting short year until 99 where it will be assumed to belong to the last century.
305 *
306 * @default 60
307 */
308 centuryBreak: number;
309
310 /**
311 * Century to be added to 2-digit years (00 to 'centuryBreak' -1).
312 *
313 * @default 2000
314 */
315 currentCentury: number;
316
317 /**
318 * Make adjacent days from previous and next month also selectable.
319 *
320 * @default false
321 */
322 selectAdjacentDays: 5 | 10 | 15 | 20 | 30;
323
324 popupOptions: Calendar.PopupSettings;
325
326 text: Calendar.TextSettings;
327
328 // endregion
329
330 // region Callbacks
331
332 /**
333 * Is called before a calendar date changes. 'return false;' will cancel the change.
334 * @since 2.8.0
335 */
336 onBeforeChange(this: JQuery): void;
337
338 /**
339 * Is called after a calendar date has changed.
340 */
341 onChange(this: JQuery): void;
342
343 /**
344 * Is called before a calendar is shown. 'return false;' will prevent the calendar to be shown.
345 */
346 onShow(this: JQuery): void;
347
348 /**
349 * Is called when the calendar is shown.
350 */
351 onVisible(this: JQuery): void;
352
353 /**
354 * Is called before a calendar is hidden. 'return false;' will prevent the calendar to be hidden.
355 */
356 onHide(this: JQuery): void;
357
358 /**
359 * Is called when the calendar is hidden.
360 */
361 onHidden(this: JQuery): void;
362
363 /**
364 * Is called when a cell of the calendar is selected providing its value and current mode.
365 * 'return false;' will prevent the selection.
366 */
367 onSelect(this: JQuery, date: Date, mode: string): void;
368
369 // endregion
370
371 // region DOM Settings
372
373 /**
374 * DOM Selectors used internally.
375 * If the calendars parent node matches the append selector, the calendar is appended to the input field instead of prepended.
376 */
377 selector: Calendar.SelectorSettings;
378
379 /**
380 * Class names used to attach style to state.
381 */
382 className: Calendar.ClassNameSettings;
383
384 /**
385 * Icon names used internally.
386 */
387 regExp: Calendar.RegExpSettings;
388
389 metadata: Calendar.MetadataSettings;
390
391 // endregion
392
393 // region Debug Settings
394
395 /**
396 * Name used in log statements
397 * @default 'Calendar'
398 */
399 name: string;
400
401 /**
402 * Event namespace. Makes sure module teardown does not effect other events attached to an element.
403 * @default 'calendar'
404 */
405 namespace: string;
406
407 /**
408 * Silences all console output including error messages, regardless of other debug settings.
409 * @default false
410 */
411 silent: boolean;
412
413 /**
414 * Debug output to console
415 * @default false
416 */
417 debug: boolean;
418
419 /**
420 * Show console.table output with performance metrics
421 * @default true
422 */
423 performance: boolean;
424
425 /**
426 * Debug output includes all internal behaviors
427 * @default false
428 */
429 verbose: boolean;
430
431 error: Calendar.ErrorSettings;
432
433 // endregion
434 }
435
436 namespace Calendar {
437 type PopupSettings = Partial<Pick<Settings.Popup, keyof Settings.Popup>>;
438 type TextSettings = Partial<Pick<Settings.Texts, keyof Settings.Texts>>;
439 type SelectorSettings = Partial<Pick<Settings.Selectors, keyof Settings.Selectors>>;
440 type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
441 type RegExpSettings = Partial<Pick<Settings.RegExps, keyof Settings.RegExps>>;
442 type MetadataSettings = Partial<Pick<Settings.Metadatas, keyof Settings.Metadatas>>;
443 type ErrorSettings = Partial<Pick<Settings.Errors, keyof Settings.Errors>>;
444
445 namespace Settings {
446 interface Popup {
447 /**
448 * @default 'bottom left'
449 */
450 position: string;
451
452 /**
453 * @default 'bottom left'
454 */
455 lastResort: string;
456
457 /**
458 * @default 'opposite'
459 */
460 prefer: string;
461
462 /**
463 * @default false
464 */
465 hideOnScroll: boolean;
466 }
467
468 interface Texts {
469 /**
470 * @default ['S', 'M', 'T', 'W', 'T', 'F', 'S']
471 */
472 days: string[];
473
474 /**
475 * @default ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
476 */
477 months: string[];
478
479 /**
480 * @default ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
481 */
482 monthsShort: string[];
483
484 /**
485 * @default 'Today'
486 */
487 today: string;
488
489 /**
490 * @default 'Now'
491 */
492 now: string;
493
494 /**
495 * @default 'AM'
496 */
497 am: string;
498
499 /**
500 * @default 'PM'
501 */
502 pm: string;
503
504 /**
505 * @default 'Week'
506 */
507 weekNo: string;
508 }
509
510 interface Selectors {
511 /**
512 * @default '.ui.popup'
513 */
514 popup: string;
515
516 /**
517 * @default 'input'
518 */
519 input: string;
520
521 /**
522 * @default 'input'
523 */
524 activator: string;
525
526 /**
527 * @default '.inline.field,.inline.fields'
528 */
529 append: string;
530 }
531
532 interface ClassNames {
533 /**
534 * @default 'calendar'
535 */
536 calendar: string;
537
538 /**
539 * @default 'active'
540 */
541 active: string;
542
543 /**
544 * @default 'ui popup'
545 */
546 popup: string;
547
548 /**
549 * @default 'ui equal width grid'
550 */
551 grid: string;
552
553 /**
554 * @default 'column'
555 */
556 column: string;
557
558 /**
559 * @default 'ui celled center aligned unstackable table'
560 */
561 table: string;
562
563 /**
564 * @default 'inverted'
565 */
566 inverted: string;
567
568 /**
569 * @default 'prev link'
570 */
571 prev: string;
572
573 /**
574 * @default 'next link'
575 */
576 next: string;
577
578 /**
579 * @default 'chevron left icon'
580 */
581 prevIcon: string;
582
583 /**
584 * @default 'chevron right icon'
585 */
586 nextIcon: string;
587
588 /**
589 * @default 'link'
590 */
591 link: string;
592
593 /**
594 * @default 'link'
595 */
596 cell: string;
597
598 /**
599 * @default 'disabled'
600 */
601 disabledCell: string;
602
603 /**
604 * @default 'disabled'
605 */
606 weekCell: string;
607
608 /**
609 * @default 'adjacent'
610 */
611 adjacentCell: string;
612
613 /**
614 * @default 'active'
615 */
616 activeCell: string;
617
618 /**
619 * @default 'range'
620 */
621 rangeCell: string;
622
623 /**
624 * @default 'focus'
625 */
626 focusCell: string;
627
628 /**
629 * @default 'today'
630 */
631 todayCell: string;
632
633 /**
634 * @default 'today link'
635 */
636 today: string;
637
638 /**
639 * @default 'disabled'
640 */
641 disabled: string;
642 }
643
644 interface RegExps {
645 /**
646 * @default /[^A-Za-z\u00C0-\u024F]+/g
647 */
648 dateWords: RegExp;
649
650 /**
651 * @default /[^\d:]+/g
652 */
653 dateNumbers: RegExp;
654
655 /**
656 * @default /d{1,4}|D{1,2}|M{1,4}|YY(?:YY)?|([Hhmsw])\1?|[ASYa]|"[^"]*"|'[^']*'/g
657 */
658 token: RegExp;
659 }
660
661 interface Metadatas {
662 /**
663 * @default 'date'
664 */
665 date: string;
666
667 /**
668 * @default 'focusDate'
669 */
670 focusDate: string;
671
672 /**
673 * @default 'startDate'
674 */
675 startDate: string;
676
677 /**
678 * @default 'endDate'
679 */
680 endDate: string;
681
682 /**
683 * @default 'minDate'
684 */
685 minDate: string;
686
687 /**
688 * @default 'maxDate'
689 */
690 maxDate: string;
691
692 /**
693 * @default 'mode'
694 */
695 mode: string;
696
697 /**
698 * @default 'type'
699 */
700 type: string;
701
702 /**
703 * @default 'monthOffset'
704 */
705 monthOffset: string;
706
707 /**
708 * @default 'message'
709 */
710 message: string;
711
712 /**
713 * @default 'class'
714 */
715 class: string;
716
717 /**
718 * @default 'inverted'
719 */
720 inverted: string;
721
722 /**
723 * @default 'variation'
724 */
725 variation: string;
726
727 /**
728 * @default 'position'
729 */
730 position: string;
731
732 /**
733 * @default 'month'
734 */
735 month: string;
736
737 /**
738 * @default 'year'
739 */
740 year: string;
741
742 /**
743 * @default 'hours'
744 */
745 hours: string;
746
747 /**
748 * @default 'days'
749 */
750 days: string;
751 }
752
753 interface Errors {
754 /**
755 * @default 'UI Popup, a required component is not included in this page.'
756 */
757 popup: string;
758
759 /**
760 * @default 'The method you called is not defined.'
761 */
762 method: string;
763 }
764 }
765 }
766}