UNPKG

2.61 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
41declare namespace Toast {
42 enum Events {
43 /**
44 * This event fires immediately when the show instance method is called.
45 */
46 show = 'show.bs.toast',
47
48 /**
49 * This event is fired when the toast has been made visible to the user.
50 */
51 shown = 'shown.bs.toast',
52
53 /**
54 * This event is fired immediately when the hide instance method has
55 * been called.
56 */
57 hide = 'hide.bs.toast',
58
59 /**
60 * This event is fired when the toast has finished being hidden from the
61 * user.
62 */
63 hidden = 'hidden.bs.toast',
64 }
65
66 interface Options {
67 /**
68 * Apply a CSS fade transition to the toast
69 *
70 * @default true
71 */
72 animation: boolean;
73
74 /**
75 * Auto hide the toast
76 *
77 * @default true
78 */
79 autohide: boolean;
80
81 /**
82 * Delay hiding the toast (ms)
83 *
84 * @default 5000
85 */
86 delay: number;
87 }
88
89 type jQueryInterface = (config?: Partial<Options> | 'show' | 'hide' | 'dispose') => void;
90}
91
92export default Toast;