UNPKG

2.72 kBTypeScriptView Raw
1import BaseComponent, { GetInstanceFactory, GetOrCreateInstanceFactory } from './base-component';
2
3declare class Toast extends BaseComponent {
4 /**
5 * Static method which allows you to get the toast instance associated
6 * with a DOM element
7 */
8 static getInstance: GetInstanceFactory<Toast>;
9
10 /**
11 * Static method which allows you to get the scrollspy instance associated with a
12 * DOM element, or create a new one in case it wasn’t initialised
13 */
14 static getOrCreateInstance: GetOrCreateInstanceFactory<Toast, Partial<Toast.Options>>;
15
16 static jQueryInterface: Toast.jQueryInterface;
17
18 /**
19 * Default settings of this plugin
20 *
21 * @link https://getbootstrap.com/docs/5.0/getting-started/javascript/#default-settings
22 */
23 static Default: Toast.Options;
24 constructor(element: string | Element, options?: Partial<Toast.Options>);
25
26 /**
27 * Reveals an element’s toast. Returns to the caller before the toast has actually
28 * been shown (i.e. before the shown.bs.toast event occurs).
29 * You have to manually call this method, instead your toast won’t show.
30 */
31 show(): void;
32
33 /**
34 * Hides an element’s toast. Returns to the caller before the toast has actually
35 * been hidden (i.e. before the hidden.bs.toast event occurs).
36 * You have to manually call this method if you made autohide to false.
37 */
38 hide(): void;
39
40 /**
41 * Returns a boolean according to toast’s visibility state.
42 */
43 isShown(): boolean;
44}
45
46declare namespace Toast {
47 enum Events {
48 /**
49 * This event fires immediately when the show instance method is called.
50 */
51 show = 'show.bs.toast',
52
53 /**
54 * This event is fired when the toast has been made visible to the user.
55 */
56 shown = 'shown.bs.toast',
57
58 /**
59 * This event is fired immediately when the hide instance method has
60 * been called.
61 */
62 hide = 'hide.bs.toast',
63
64 /**
65 * This event is fired when the toast has finished being hidden from the
66 * user.
67 */
68 hidden = 'hidden.bs.toast',
69 }
70
71 interface Options {
72 /**
73 * Apply a CSS fade transition to the toast
74 *
75 * @default true
76 */
77 animation: boolean;
78
79 /**
80 * Auto hide the toast
81 *
82 * @default true
83 */
84 autohide: boolean;
85
86 /**
87 * Delay hiding the toast (ms)
88 *
89 * @default 5000
90 */
91 delay: number;
92 }
93
94 type jQueryInterface = (config?: Partial<Options> | 'show' | 'hide' | 'dispose') => JQuery;
95}
96
97export default Toast;