Skip to content

Commit a03991c

Browse files
authored
fix(types): better declaration files
This is the first round of fixes/improvements for type declarations of Fomantic. Some properties and methods were missing, some were too restrictive.
1 parent 3564140 commit a03991c

16 files changed

+573
-79
lines changed

types/fomantic-ui-api.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ declare namespace FomanticUI {
125125
*/
126126
on: string;
127127

128+
/**
129+
* Object containing all templates endpoints
130+
* @default {}
131+
*/
132+
api: {[key: string]: string};
133+
128134
/**
129135
* Can be set to 'local' to cache successful returned AJAX responses when using a JSON API.
130136
* This helps avoid server roundtrips when API endpoints will return the same results when accessed repeatedly.
@@ -137,7 +143,7 @@ declare namespace FomanticUI {
137143
* UI state will be applied to this element, defaults to triggering element.
138144
* @default false
139145
*/
140-
stateContext: false | JQuery;
146+
stateContext: false | string | JQuery<any>;
141147

142148
/**
143149
* Whether to encode parameters with 'encodeURIComponent' before adding into url string.
@@ -259,7 +265,7 @@ declare namespace FomanticUI {
259265
* Method for transmitting request to server.
260266
* @default 'get'
261267
*/
262-
method: 'get' | 'post' | 'put' | 'delete' | 'head' | 'options' | 'patch';
268+
method: Uppercase<'get' | 'post' | 'put' | 'delete' | 'head' | 'options' | 'patch'> | Lowercase<'get' | 'post' | 'put' | 'delete' | 'head' | 'options' | 'patch'>;
263269

264270
/**
265271
* Expected data type of response.

types/fomantic-ui-calendar.d.ts

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ declare namespace FomanticUI {
3737
* Pass false to updateInput to disable updating the input.
3838
* Pass false to fireChange to disable the onBeforeChange and onChange callbacks for this change
3939
*/
40-
(behavior: 'set date', date: string, updateInput: boolean, fireChange: boolean): JQuery;
40+
(behavior: 'set date', date: Date | string | null, updateInput?: boolean, fireChange?: boolean): JQuery;
4141

4242
/**
4343
* Get the current selection mode (year, month, day, hour, minute)
@@ -82,12 +82,12 @@ declare namespace FomanticUI {
8282
/**
8383
* Set the minimal selectable date
8484
*/
85-
(behavior: 'set minDate', date: Date | string): JQuery;
85+
(behavior: 'set minDate', date: Date | string | null): JQuery;
8686

8787
/**
8888
* Set the maximal selectable date
8989
*/
90-
(behavior: 'set maxDate', date: Date | string): JQuery;
90+
(behavior: 'set maxDate', date: Date | string | null): JQuery;
9191

9292
(behavior: 'destroy'): JQuery;
9393

@@ -214,7 +214,7 @@ declare namespace FomanticUI {
214214
*
215215
* @default null
216216
*/
217-
initialDate: null | Date;
217+
initialDate: Date | string | null;
218218

219219
/**
220220
* Display mode to start in, can be 'year', 'month', 'day', 'hour', 'minute' (false = 'day').
@@ -319,12 +319,14 @@ declare namespace FomanticUI {
319319
*
320320
* @default false
321321
*/
322-
selectAdjacentDays: 5 | 10 | 15 | 20 | 30;
322+
selectAdjacentDays: boolean;
323323

324324
popupOptions: Calendar.PopupSettings;
325325

326326
text: Calendar.TextSettings;
327327

328+
formatter: Calendar.FormatterSettings;
329+
328330
// endregion
329331

330332
// region Callbacks
@@ -333,12 +335,12 @@ declare namespace FomanticUI {
333335
* Is called before a calendar date changes. 'return false;' will cancel the change.
334336
* @since 2.8.0
335337
*/
336-
onBeforeChange(this: JQuery): void;
338+
onBeforeChange(this: JQuery, date?: Date, text?: string, mode?: string): void;
337339

338340
/**
339341
* Is called after a calendar date has changed.
340342
*/
341-
onChange(this: JQuery): void;
343+
onChange(this: JQuery, date?: Date): void;
342344

343345
/**
344346
* Is called before a calendar is shown. 'return false;' will prevent the calendar to be shown.
@@ -364,7 +366,7 @@ declare namespace FomanticUI {
364366
* Is called when a cell of the calendar is selected providing its value and current mode.
365367
* 'return false;' will prevent the selection.
366368
*/
367-
onSelect(this: JQuery, date: Date, mode: string): void;
369+
onSelect(this: JQuery, date?: Date, mode?: string): void;
368370

369371
// endregion
370372

@@ -436,6 +438,7 @@ declare namespace FomanticUI {
436438
namespace Calendar {
437439
type PopupSettings = Partial<Pick<Settings.Popup, keyof Settings.Popup>>;
438440
type TextSettings = Partial<Pick<Settings.Texts, keyof Settings.Texts>>;
441+
type FormatterSettings = Partial<Pick<Settings.Formatters, keyof Settings.Formatters>>;
439442
type SelectorSettings = Partial<Pick<Settings.Selectors, keyof Settings.Selectors>>;
440443
type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
441444
type RegExpSettings = Partial<Pick<Settings.RegExps, keyof Settings.RegExps>>;
@@ -471,6 +474,16 @@ declare namespace FomanticUI {
471474
*/
472475
days: string[];
473476

477+
/**
478+
* @default ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
479+
*/
480+
dayNamesShort: string[];
481+
482+
/**
483+
* @default ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
484+
*/
485+
dayNames: string[];
486+
474487
/**
475488
* @default ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
476489
*/
@@ -507,6 +520,78 @@ declare namespace FomanticUI {
507520
weekNo: string;
508521
}
509522

523+
interface Formatters {
524+
/**
525+
*
526+
*/
527+
yearHeader(date: Date, settings?: CalendarSettings): string;
528+
529+
/**
530+
* @default 'YYYY'
531+
*/
532+
monthHeader: string;
533+
534+
/**
535+
* @default 'MMMM YYYY'
536+
*/
537+
dayHeader: string;
538+
539+
/**
540+
* @default 'MMMM D, YYYY'
541+
*/
542+
hourHeader: string;
543+
544+
/**
545+
* @default 'MMMM D, YYYY'
546+
*/
547+
minuteHeader: string;
548+
549+
/**
550+
* @default 'MMMM D, YYYY'
551+
*/
552+
dayColumnHeader(day: number, settings: CalendarSettings): string;
553+
554+
/**
555+
* @default 'MMMM D, YYYY h:mm A'
556+
*/
557+
datetime: string;
558+
559+
/**
560+
* @default 'MMMM D, YYYY'
561+
*/
562+
date: string;
563+
564+
/**
565+
* @default 'h:mm A'
566+
*/
567+
time: string;
568+
569+
/**
570+
* @default 'h:mm A'
571+
*/
572+
cellTime: string;
573+
574+
/**
575+
* @default 'MMMM YYYY'
576+
*/
577+
month: string;
578+
579+
/**
580+
* @default 'YYYY'
581+
*/
582+
year: string;
583+
584+
/**
585+
*
586+
*/
587+
today(settings: CalendarSettings): string;
588+
589+
/**
590+
*
591+
*/
592+
cell(cell: string, date: Date, cellOptions: any): any
593+
}
594+
510595
interface Selectors {
511596
/**
512597
* @default '.ui.popup'

types/fomantic-ui-checkbox.d.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ declare namespace FomanticUI {
3232
*/
3333
(behavior: 'enable'): JQuery;
3434

35+
/**
36+
* Disable interaction with a checkbox.
37+
*/
38+
(behavior: 'disable'): JQuery;
39+
3540
/**
3641
* Set a checkbox state to checked without callbacks.
3742
*/
@@ -82,6 +87,11 @@ declare namespace FomanticUI {
8287
*/
8388
(behavior: 'is unchecked'): boolean;
8489

90+
/**
91+
* Returns whether element is not determinate.
92+
*/
93+
(behavior: 'is indeterminate'): boolean;
94+
8595
/**
8696
* Returns whether element is able to be changed.
8797
*/
@@ -175,22 +185,22 @@ declare namespace FomanticUI {
175185
/**
176186
* Callback before a checkbox is checked. Can cancel change by returning 'false'.
177187
*/
178-
beforeChecked(this: JQuery): void | false;
188+
beforeChecked(this: JQuery): void | Promise<void> | boolean;
179189

180190
/**
181191
* Callback before a checkbox is set to indeterminate. Can cancel change by returning 'false'.
182192
*/
183-
beforeIndeterminate(this: JQuery): void | false;
193+
beforeIndeterminate(this: JQuery): void | Promise<void> | false;
184194

185195
/**
186196
* Callback before a checkbox is set to determinate. Can cancel change by returning 'false'.
187197
*/
188-
beforeDeterminate(this: JQuery): void | false;
198+
beforeDeterminate(this: JQuery): void | Promise<void> | false;
189199

190200
/**
191201
* Callback before a checkbox is unchecked. Can cancel change by returning 'false'.
192202
*/
193-
beforeUnchecked(this: JQuery): void | false;
203+
beforeUnchecked(this: JQuery): void | Promise<void> | false;
194204

195205
/**
196206
* Callback after a checkbox is enabled.

types/fomantic-ui-dropdown.d.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare namespace FomanticUI {
66
* Recreates dropdown menu from passed values.
77
* values should be an object with the following structure: { values: [ {value, text, name} ] }.
88
*/
9-
(behavior: 'setup menu', values: object): void;
9+
(behavior: 'setup menu', values: object): JQuery;
1010

1111
/**
1212
* Changes dropdown to use new values.
@@ -17,7 +17,7 @@ declare namespace FomanticUI {
1717
/**
1818
* Refreshes all cached selectors and data
1919
*/
20-
(behavior: 'refresh'): void;
20+
(behavior: 'refresh'): JQuery;
2121

2222
/**
2323
* Toggles current visibility of dropdown
@@ -29,20 +29,20 @@ declare namespace FomanticUI {
2929
* If a function is provided to callback, it's called after the dropdown-menu is shown.
3030
* Set preventFocus to true if you don't want the dropdown field to focus after the menu is shown
3131
*/
32-
(behavior: 'show', callback: Function, preventFocus: boolean): void;
32+
(behavior: 'show', callback?: Function, preventFocus?: boolean): void;
3333

3434
/**
3535
* Hides dropdown.
3636
* If a function is provided to callback, it's called after the dropdown-menu is hidden.
3737
* Set preventBlur to true if you don't want the dropdown field to blur after the menu is hidden
3838
*/
39-
(behavior: 'hide', callback:Function, preventBlur: boolean): void;
39+
(behavior: 'hide', callback?: Function, preventBlur?: boolean): void;
4040

4141
/**
4242
* Clears dropdown of selection.
4343
* Set preventChangeTrigger to true to omit the change event (default: false).
4444
*/
45-
(behavior: 'clear', preventChangeTrigger: boolean): void;
45+
(behavior: 'clear', preventChangeTrigger?: boolean): JQuery;
4646

4747
/**
4848
* Hides all other dropdowns that is not current dropdown
@@ -53,7 +53,7 @@ declare namespace FomanticUI {
5353
* Restores dropdown text and value to its value on page load.
5454
* Set preventChangeTrigger to true to omit the change event (default: false).
5555
*/
56-
(behavior: 'restore defaults', preventChangeTrigger: boolean): void;
56+
(behavior: 'restore defaults', preventChangeTrigger?: boolean): void;
5757

5858
/**
5959
* Restores dropdown text to its value on page load
@@ -79,33 +79,28 @@ declare namespace FomanticUI {
7979
* Sets value as selected.
8080
* Set preventChangeTrigger to true to omit the change event (default: false).
8181
*/
82-
(behavior: 'set selected', value: string, preventChangeTrigger: boolean): void;
82+
(behavior: 'set selected', value: string | string[], preventChangeTrigger?: boolean, keepSearchTerm?: boolean): JQuery;
8383

8484
/**
8585
* Remove value from selected
8686
*/
8787
(behavior: 'remove selected', value: string): void;
8888

89-
/**
90-
* Adds a group of values as selected
91-
*/
92-
(behavior: 'set selected', values: string[]): void;
93-
9489
/**
9590
* Sets selected values to exactly specified values, removing current selection
9691
*/
97-
(behavior: 'set exactly', values: string[]): void;
92+
(behavior: 'set exactly', values: string[]): JQuery;
9893

9994
/**
10095
* Sets dropdown text to a value
10196
*/
102-
(behavior: 'text', text: string): void;
97+
(behavior: 'set text', text: string): JQuery;
10398

10499
/**
105100
* Sets dropdown input to value (does not update display state).
106101
* Set preventChangeTrigger to true to omit the change event (default: false).
107102
*/
108-
(behavior: 'set value', value: string, preventChangeTrigger: boolean): void;
103+
(behavior: 'set value', value: string, preventChangeTrigger?: boolean): JQuery;
109104

110105
/**
111106
* Returns current dropdown text
@@ -265,7 +260,7 @@ declare namespace FomanticUI {
265260
* @see {@link https://fomantic-ui.com/behaviors/api.html#/settings}
266261
* @default false
267262
*/
268-
apiSettings: false | APISettings | JQueryAjaxSettings;
263+
apiSettings: false | Partial<Pick<APISettings, keyof APISettings>> | Partial<Pick<JQueryAjaxSettings, keyof JQueryAjaxSettings>>;
269264

270265
/**
271266
* Whether dropdown should select new option when using keyboard shortcuts.
@@ -506,7 +501,7 @@ declare namespace FomanticUI {
506501
* Is called after a dropdown value changes.
507502
* Receives the name and value of selection and the active menu element.
508503
*/
509-
onChange(value: string, text: string, $choice: JQuery): void;
504+
onChange(value?: string, text?: string, $choice?: JQuery): void;
510505

511506
/**
512507
* Is called after a dropdown selection is added using a multiple select dropdown, only receives the added value.

0 commit comments

Comments
 (0)