UNPKG

13.2 kBTypeScriptView Raw
1declare namespace FomanticUI {
2 interface Progress {
3 settings: ProgressSettings;
4
5 /**
6 * Sets current percent of progress to value.
7 * If using a total will convert from percent to estimated value.
8 * 'percent' can be array of percent like '[20,30,50]', comma-separated string like '20,30,50' for `.ui.multiple.progress`.
9 */
10 (behavior: 'set percent', percent: number | [] | string): JQuery;
11
12 /**
13 * Sets progress to specified value.
14 * Will automatically calculate percent from total.
15 * value can be array of values like '[5,3,10]', comma-separated string like '5,3,10' for `.ui.multiple.progress`.
16 */
17 (behavior: 'set progress', value: number | [] | string): JQuery;
18
19 /**
20 * Increments progress by increment value, if not passed a value will use random amount specified in settings.
21 */
22 (behavior: 'increment', incrementValue: number): JQuery;
23
24 /**
25 * Decrements progress by decrement value, if not passed a value will use random amount specified in settings.
26 */
27 (behavior: 'decrement', decrementValue: number): JQuery;
28
29 /**
30 * Immediately updates progress to value, ignoring progress animation interval delays.
31 * 'value' can be array of values like '[5,3,10]', comma-separated string like '5,3,10' for `.ui.multiple.progress`.
32 */
33 (behavior: 'update progress', value: number | [] | string): JQuery;
34
35 /**
36 * Finishes progress and sets loaded to 100%.
37 * Set 'keepState' to 'true' (default 'false') to stop the active animation only without setting the progress to 100%.
38 */
39 (behavior: 'complete', keepState: boolean): JQuery;
40
41 /**
42 * Resets progress to zero.
43 */
44 (behavior: 'reset'): JQuery;
45
46 /**
47 * Set total to a new value.
48 */
49 (behavior: 'set total', total: number): JQuery;
50
51 /**
52 * Replaces templated string with value, total, percent left and percent.
53 */
54 (behavior: 'get text', text: string): JQuery;
55
56 /**
57 * Returns normalized value inside acceptable range specified by total.
58 */
59 (behavior: 'get normalized value', value: number): JQuery;
60
61 /**
62 * Returns percent as last specified.
63 */
64 (behavior: 'get percent'): number;
65
66 /**
67 * Returns current progress value.
68 */
69 (behavior: 'get value'): number;
70
71 /**
72 * Returns total.
73 */
74 (behavior: 'get total'): number;
75
76 /**
77 * Returns whether progress is completed.
78 */
79 (behavior: 'is complete'): boolean;
80
81 /**
82 * Returns whether progress was a success.
83 */
84 (behavior: 'is success'): boolean;
85
86 /**
87 * Returns whether progress is in warning state.
88 */
89 (behavior: 'is warning'): boolean;
90
91 /**
92 * Returns whether progress is in error state.
93 */
94 (behavior: 'is error'): boolean;
95
96 /**
97 * Returns whether progress is in active state.
98 */
99 (behavior: 'is active'): boolean;
100
101 /**
102 * Sets progress to active state.
103 */
104 (behavior: 'set active'): JQuery;
105
106 /**
107 * Sets progress to warning state. Set 'keepState' to 'true' (default 'false') to keep the progressbar state and the current percentage without raising it up to 100%.
108 */
109 (behavior: 'set warning', text: string, keepState: boolean): JQuery;
110
111 /**
112 * Sets progress to success state. Set 'keepState' to 'true' (default 'false') to keep the progressbar state and the current percentage without raising it up to 100%.
113 */
114 (behavior: 'set success', text: string, keepState: boolean): JQuery;
115
116 /**
117 * Sets progress to error state. Set 'keepState' to 'true' (default 'false') to keep the progressbar state and the current percentage without raising it up to 100%.
118 */
119 (behavior: 'set error', text: string, keepState: boolean): JQuery;
120
121 /**
122 * Changes progress animation speed.
123 */
124 (behavior: 'set duration', value: number): JQuery;
125
126 /**
127 * Sets progress exterior label to text.
128 */
129 (behavior: 'set label', text: string): JQuery;
130
131 /**
132 * Sets progress bar label to text.
133 */
134 (behavior: 'set bar label', text: string): JQuery;
135
136 /**
137 * Removes progress to active state.
138 */
139 (behavior: 'remove active'): JQuery;
140
141 /**
142 * Removes progress to warning state.
143 */
144 (behavior: 'remove warning'): JQuery;
145
146 /**
147 * Removes progress to success state.
148 */
149 (behavior: 'remove success'): JQuery;
150
151 /**
152 * Removes progress to error state.
153 */
154 (behavior: 'remove error'): JQuery;
155
156 /**
157 * Destroys instance and removes all events.
158 */
159 (behavior: 'destroy'): JQuery;
160
161 <K extends keyof ProgressSettings>(behavior: 'setting', name: K, value?: undefined, ): Partial<Pick<ProgressSettings, keyof ProgressSettings>>;
162 <K extends keyof ProgressSettings>(behavior: 'setting', name: K, value: ProgressSettings[K]): JQuery;
163 (behavior: 'setting', value: Partial<Pick<ProgressSettings, keyof ProgressSettings>>): JQuery;
164 (settings?: Partial<Pick<ProgressSettings, keyof ProgressSettings>>): JQuery;
165 }
166
167 /**
168 * @see {@link https://fomantic-ui.com/modules/progress.html#/settings}
169 */
170 interface ProgressSettings {
171 // region Progress Settings
172
173 /**
174 * Whether success state should automatically trigger when progress completes.
175 * @default true
176 */
177 autoSuccess: boolean;
178
179 /**
180 * Whether progress should automatically show activity when incremented.
181 * @default true
182 */
183 showActivity: boolean;
184
185 /**
186 * When set to 'true', values that calculate to above 100% or below 0% will be adjusted.
187 * When set to 'false', inappropriate values will produce an error.
188 * @default true
189 */
190 limitValues: boolean;
191
192 /**
193 * Can be set to either to display progress as 'percent' or 'ratio'.
194 * Matches up to corresponding text template with the same name.
195 * @default 'percent'
196 */
197 label: 'percent' | 'ratio';
198
199 /**
200 * When incrementing without value, sets range for random increment value.
201 * @default {}
202 */
203 random: object;
204
205 /**
206 * Decimal point precision for calculated progress.
207 * @default 0
208 */
209 precision: number;
210
211 /**
212 * Setting a total value will make each call to increment get closer to this total (i.e. 1/20, 2/20 etc).
213 * @default false
214 */
215 total: false | number;
216
217 /**
218 * Sets current value, when total is specified, this is used to calculate a ratio of the total, with percent this should be the overall percent.
219 * @default false
220 */
221 value: false | number;
222
223 // endregion
224
225 // region Callbacks
226
227 /**
228 * Callback on percentage change.
229 */
230 onChange(this: JQuery, percent: number, value: number, total: number): void;
231
232 /**
233 * Callback on success state.
234 */
235 onSuccess(this: JQuery, total: number): void;
236
237 /**
238 * Callback on active state.
239 */
240 onActive(this: JQuery, value: number, total: number): void;
241
242 /**
243 * Callback on error state.
244 */
245 onError(this: JQuery, value: number, total: number): void;
246
247 /**
248 * Callback on warning state.
249 */
250 onWarning(this: JQuery, value: number, total: number): void;
251
252 // endregion
253
254 // region DOM Settings
255
256 /**
257 * DOM Selectors used internally.
258 * Selectors used to find parts of a module.
259 */
260 selector: Progress.SelectorSettings;
261
262 /**
263 * Class names used to determine element state.
264 */
265 className: Progress.ClassNameSettings;
266
267 /**
268 *
269 */
270 text: Progress.TextSettings;
271
272 /**
273 * Regular expressions used by module
274 */
275 regExp: Progress.RegExpSettings;
276
277 /**
278 * Regular expressions used by module
279 */
280 metadata: Progress.MetadataSettings;
281
282 // endregion
283
284 // region Debug Settings
285
286 /**
287 * Name used in log statements
288 * @default 'Progress'
289 */
290 name: string;
291
292 /**
293 * Event namespace. Makes sure module teardown does not effect other events attached to an element.
294 * @default 'progress'
295 */
296 namespace: string;
297
298 /**
299 * Silences all console output including error messages, regardless of other debug settings.
300 * @default false
301 */
302 silent: boolean;
303
304 /**
305 * Debug output to console
306 * @default false
307 */
308 debug: boolean;
309
310 /**
311 * Show console.table output with performance metrics
312 * @default true
313 */
314 performance: boolean;
315
316 /**
317 * Debug output includes all internal behaviors
318 * @default false
319 */
320 verbose: boolean;
321
322 error: Progress.ErrorSettings;
323
324 // endregion
325 }
326
327 namespace Progress {
328 type SelectorSettings = Partial<Pick<Settings.Selectors, keyof Settings.Selectors>>;
329 type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
330 type TextSettings = Partial<Pick<Settings.Texts, keyof Settings.Texts>>;
331 type RegExpSettings = Partial<Pick<Settings.RegExps, keyof Settings.RegExps>>;
332 type MetadataSettings = Partial<Pick<Settings.Metadatas, keyof Settings.Metadatas>>;
333 type ErrorSettings = Partial<Pick<Settings.Errors, keyof Settings.Errors>>;
334
335 namespace Settings {
336 interface Selectors {
337 /**
338 * @default '> .bar'
339 */
340 bar: string;
341
342 /**
343 * @default '> .label'
344 */
345 label: string;
346
347 /**
348 * @default '.bar > .progress'
349 */
350 progress: string;
351 }
352
353 interface ClassNames {
354 /**
355 * @default 'active'
356 */
357 active: string;
358
359 /**
360 * @default 'error'
361 */
362 error: string;
363
364 /**
365 * @default 'success'
366 */
367 success: string;
368
369 /**
370 * @default 'warning'
371 */
372 warning: string;
373 }
374
375 interface Texts {
376 /**
377 * @default false
378 */
379 active: boolean | string;
380
381 /**
382 * @default false
383 */
384 error: boolean | string;
385
386 /**
387 * @default false
388 */
389 success: boolean | string;
390
391 /**
392 * @default false
393 */
394 warning: boolean | string;
395
396 /**
397 * @default '{percent}%''
398 */
399 percent: string;
400
401 /**
402 * @default '{value} of {total}'
403 */
404 ratio: string;
405
406 /**
407 * @default []
408 */
409 bars: string[];
410 }
411
412 interface RegExps {
413 /**
414 * @default /\{\$*[A-z0-9]+\}/g
415 */
416 variable: RegExp;
417 }
418
419 interface Metadatas {
420 /**
421 * @default 'percent'
422 */
423 percent: string;
424
425 /**
426 * @default 'total'
427 */
428 total: string;
429
430 /**
431 * @default 'value'
432 */
433 value: string;
434 }
435
436 interface Errors {
437 /**
438 * @default 'The method you called is not defined.'
439 */
440 method: string;
441
442 /**
443 * @default 'Progress value is non numeric'
444 */
445 nonNumeric: string;
446
447 /**
448 * @default 'Value specified is above 100%'
449 */
450 tooHigh: string;
451
452 /**
453 * @default 'Value specified is below 0%'
454 */
455 tooLow: string;
456 }
457 }
458 }
459}