UNPKG

14.8 kBTypeScriptView Raw
1declare namespace FomanticUI {
2 interface Popup {
3 settings: PopupSettings;
4
5 /**
6 * Shows popup.
7 */
8 (behavior: 'show'): JQuery;
9
10 /**
11 * Hides popup.
12 */
13 (behavior: 'hide'): JQuery;
14
15 /**
16 * Hides all visible pop ups on the page.
17 */
18 (behavior: 'hide all'): JQuery;
19
20 /**
21 * Returns current popup dom element.
22 */
23 (behavior: 'get popup'): JQuery;
24
25 /**
26 * Changes current popup content.
27 */
28 (behavior: 'change content', html: string): JQuery;
29
30 /**
31 * Toggles visibility of popup.
32 */
33 (behavior: 'toggle'): JQuery;
34
35 /**
36 * Returns whether popup is visible.
37 */
38 (behavior: 'is visible'): boolean;
39
40 /**
41 * Returns whether popup is hidden.
42 */
43 (behavior: 'is hidden'): boolean;
44
45 /**
46 * Returns whether popup is created and inserted into the page.
47 */
48 (behavior: 'exists'): boolean;
49
50 /**
51 * Adjusts popup when content size changes (only necessary for centered popups).
52 */
53 (behavior: 'reposition'): JQuery;
54
55 /**
56 * Repositions a popup.
57 */
58 (behavior: 'set position', position: number): JQuery;
59
60 /**
61 * Removes popup from the page.
62 */
63 (behavior: 'remove popup'): JQuery;
64
65 /**
66 * Removes popup from the page and removes all events.
67 */
68 (behavior: 'destroy'): JQuery;
69
70 <K extends keyof PopupSettings>(behavior: 'setting', name: K, value?: undefined, ): Partial<Pick<PopupSettings, keyof PopupSettings>>;
71 <K extends keyof PopupSettings>(behavior: 'setting', name: K, value: PopupSettings[K]): JQuery;
72 (behavior: 'setting', value: Partial<Pick<PopupSettings, keyof PopupSettings>>): JQuery;
73 (settings?: Partial<Pick<PopupSettings, keyof PopupSettings>>): JQuery;
74 }
75
76 /**
77 * @see {@link https://fomantic-ui.com/modules/popup.html#/settings}
78 */
79 interface PopupSettings {
80 // region Popup Settings
81
82 /**
83 * Can specify a DOM element that should be used as the popup.
84 * This is useful for including a pre-formatted popup.
85 * @default false
86 */
87 popup: false | string;
88
89 /**
90 * Whether all other popups should be hidden when this popup is opened.
91 * @default false
92 */
93 exclusive: boolean;
94
95 /**
96 * Whether to move popup to same offset container as target element when popup already exists on the page.
97 * Using a popup inside of an element without 'overflow:visible', like a sidebar, may require you to set this to 'false'.
98 * @default true
99 */
100 movePopup: boolean;
101
102 /**
103 * Whether popup should attach 'mutationObservers' to automatically run destroy when the element is removed from the page's DOM.
104 * @default true
105 */
106 observeChanges: boolean;
107
108 /**
109 * When the popup surpasses the boundary of this element, it will attempt to find another display position.
110 * @default window
111 */
112 boundary: Window | string;
113
114 /**
115 * Selector or jquery object specifying where the popup should be created.
116 * @default 'body'
117 */
118 context: string | JQuery;
119
120 /**
121 * Will automatically hide a popup on scroll event in this context.
122 * @default window
123 */
124 scrollContext: Window | string;
125
126 /**
127 * Number of pixels that a popup is allowed to appear outside the boundaries of its context.
128 * This allows for permissible rounding errors when an element is against the edge of its 'context'.
129 * @default 2
130 */
131 jitter: number;
132
133 /**
134 * Position that the popup should appear.
135 * @default 'top left'
136 */
137 position: string;
138
139 /**
140 * If given position should be used, regardless if popup fits.
141 * @default false
142 */
143 forcePosition: boolean;
144
145 /**
146 * If a popup is inline it will be created next to current element, allowing for local css rules to apply.
147 * It will not be removed from the DOM after being hidden.
148 * Otherwise popups will appended to body and removed after being hidden.
149 * @default false
150 */
151 inline: boolean;
152
153 /**
154 * Whether popup contents should be preserved in the page after being hidden, allowing it to re-appear slightly faster on subsequent loads.
155 * @default false
156 */
157 preserve: boolean;
158
159 /**
160 * Can be set to 'adjacent' or 'opposite' to prefer adjacent or opposite position if popup cannot fit on screen.
161 * @default 'opposite'
162 */
163 prefer: 'opposite' | 'adjacent';
164
165 /**
166 * When set to 'false', a popup will not appear and produce an error message if it cannot entirely fit on page.
167 * Setting this to a position like, 'right center' forces the popup to use this position as a last resort even if it is partially offstage.
168 * Setting this to 'true' will use the last attempted position.
169 * @default false
170 */
171 lastResort: boolean | string;
172
173 /**
174 * Event used to trigger popup.
175 * Can be either 'focus', 'click', 'hover', or 'manual'.
176 * Manual popups must be triggered with '$('.element').popup('show');'.
177 * @default 'hover'
178 */
179 on: 'hover' | 'focus' | 'click' | 'manual';
180
181 /**
182 * Delay in milliseconds before showing or hiding a popup on hover or focus.
183 * @default {}
184 */
185 delay: object; // TODO
186
187 /**
188 * Named transition to use when animating menu in and out.
189 * Alternatively you can provide an object to set individual values for hide/show transitions as well as hide/show duration.
190 * @default 'scale'
191 */
192 transition: string | object;
193
194 /**
195 * Duration of animation events.
196 * The value will be ignored when individual hide/show duration values are provided via the 'transition' setting.
197 * @default 200
198 */
199 duration: number;
200
201 /**
202 * When a target element is less than 2x this amount, the popup will appear with the arrow centered on the target element, instead of with the popup edge matching the target's edge.
203 * @default 20
204 */
205 arrowPixelsFromEdge: number;
206
207 /**
208 * Whether popup should set fluid popup variation width on load to avoid 'width: 100%' including padding.
209 * @default true
210 */
211 setFluidWidth: boolean;
212
213 /**
214 * Whether popup should not close on hover (useful for popup navigation menus).
215 * @default false
216 */
217 hoverable: boolean;
218
219 /**
220 * Whether popup should hide when clicking on the page, 'auto' only hides for popups without on: 'hover'.
221 * @default true
222 */
223 closable: boolean | 'auto';
224
225 /**
226 * When using on: 'hover' whether 'touchstart' events should be added to allow the popup to be triggered.
227 * @default true
228 */
229 addTouchEvents: boolean;
230
231 /**
232 * Whether popup should hide on scroll or touchmove, 'auto' only hides for popups without on: 'click'.
233 * Set this to 'false' to prevent mobile browsers from closing popups when you tap inside input fields.
234 * @default 'auto'
235 */
236 hideOnScroll: 'auto' | boolean;
237
238 /**
239 * If a selector or jQuery object is specified this allows the popup to be positioned relative to that element.
240 * @default false
241 */
242 target: false | string | JQuery;
243
244 /**
245 * Offset for distance of popup from element.
246 * @default 0
247 */
248 distanceAway: number;
249
250 /**
251 * Offset in pixels from calculated position.
252 * @default 0
253 */
254 offset: number;
255
256 /**
257 * Number of iterations before giving up search for popup position when a popup cannot fit on screen.
258 * @default 15
259 */
260 maxSearchDepth: number;
261
262 // endregion
263
264 // region Callbacks
265
266 /**
267 * Callback on popup element creation, with created popup.
268 */
269 onCreate(this: JQuery): void;
270
271 /**
272 * Callback immediately before Popup is removed from DOM.
273 */
274 onRemove(this: JQuery): void;
275
276 /**
277 * Callback before popup is shown.
278 * Returning 'false' from this callback will cancel the popup from showing.
279 */
280 onShow(this: JQuery): boolean;
281
282 /**
283 * Callback after popup is shown.
284 */
285 onVisible(this: JQuery): void;
286
287 /**
288 * Callback before popup is hidden.
289 * Returning 'false' from this callback will cancel the popup from hiding.
290 */
291 onHide(this: JQuery): boolean;
292
293 /**
294 * Callback after popup is hidden.
295 */
296 onHidden(this: JQuery): void;
297
298 /**
299 * Callback after popup cannot be placed on screen.
300 */
301 onUnplaceable(this: JQuery): void;
302
303 // endregion
304
305 // region Content Settings
306
307 /**
308 * Popup variation to use, can use multiple variations with a space delimiter.
309 */
310 variation: string;
311
312 /**
313 * Content to display.
314 */
315 content: string;
316
317 /**
318 * Title to display alongside content.
319 */
320 title: string;
321
322 /**
323 * HTML content to display instead of preformatted title and content.
324 */
325 html: string;
326
327 // endregion
328
329 // region DOM Settings
330
331 /**
332 * DOM Selectors used internally.
333 * Selectors used to find parts of a module.
334 */
335 selector: Popup.SelectorSettings;
336
337 /**
338 * Class names used to determine element state.
339 */
340 metadata: Popup.MetadataSettings;
341
342 /**
343 * Class names used to determine element state.
344 */
345 className: Popup.ClassNameSettings;
346
347 // endregion
348
349 // region Debug Settings
350
351 /**
352 * Name used in log statements
353 * @default 'Popup'
354 */
355 name: string;
356
357 /**
358 * Event namespace. Makes sure module teardown does not effect other events attached to an element.
359 * @default 'popup'
360 */
361 namespace: string;
362
363 /**
364 * Silences all console output including error messages, regardless of other debug settings.
365 * @default false
366 */
367 silent: boolean;
368
369 /**
370 * Debug output to console
371 * @default false
372 */
373 debug: boolean;
374
375 /**
376 * Show console.table output with performance metrics
377 * @default true
378 */
379 performance: boolean;
380
381 /**
382 * Debug output includes all internal behaviors
383 * @default false
384 */
385 verbose: boolean;
386
387 error: Popup.ErrorSettings;
388
389 // endregion
390 }
391
392 namespace Popup {
393 type SelectorSettings = Partial<Pick<Settings.Selectors, keyof Settings.Selectors>>;
394 type MetadataSettings = Partial<Pick<Settings.Metadatas, keyof Settings.Metadatas>>;
395 type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
396 type ErrorSettings = Partial<Pick<Settings.Errors, keyof Settings.Errors>>;
397
398 namespace Settings {
399 interface Selectors {
400 /**
401 * @default '.ui.popup'
402 */
403 popup: string;
404 }
405
406 interface Metadatas {
407 /**
408 * @default 'activator'
409 */
410 activator: string;
411
412 /**
413 * @default 'content'
414 */
415 content: string;
416
417 /**
418 * @default 'html'
419 */
420 html: string;
421
422 /**
423 * @default 'offset'
424 */
425 offset: string;
426
427 /**
428 * @default 'position'
429 */
430 position: string;
431
432 /**
433 * @default 'title'
434 */
435 title: string;
436
437 /**
438 * @default 'variation'
439 */
440 variation: string;
441 }
442
443 interface ClassNames {
444 /**
445 * @default 'active'
446 */
447 active: string;
448
449 /**
450 * @default 'basic'
451 */
452 basic: string;
453
454 /**
455 * @default 'animating'
456 */
457 animating: string;
458
459 /**
460 * @default 'dropdown'
461 */
462 dropdown: string;
463
464 /**
465 * @default 'fluid'
466 */
467 fluid: string;
468
469 /**
470 * @default 'loading'
471 */
472 loading: string;
473
474 /**
475 * @default 'ui popup'
476 */
477 popup: string;
478
479 /**
480 * @default 'top left center bottom right'
481 */
482 position: string;
483
484 /**
485 * @default 'visible'
486 */
487 visible: string;
488
489 /**
490 * @default 'visible'
491 */
492 popupVisible: string;
493 }
494
495 interface Errors {
496 /**
497 * @default 'The position you specified is not a valid position'
498 */
499 invalidPosition: string;
500
501 /**
502 * @default 'Popup does not fit within the boundaries of the viewport'
503 */
504 cannotPlace: string;
505
506 /**
507 * @default 'The method you called is not defined.'
508 */
509 method: string;
510
511 /**
512 * @default 'This module requires ui transitions'
513 */
514 noTransition: string;
515
516 /**
517 * @default 'The target or popup you specified does not exist on the page'
518 */
519 notFound: string;
520 }
521 }
522 }
523}