UNPKG

5 kBTypeScriptView Raw
1import BaseComponent, { GetInstanceFactory, GetOrCreateInstanceFactory } from './base-component';
2import Tooltip from './tooltip';
3
4declare class Popover extends BaseComponent {
5 static getInstance: GetInstanceFactory<Popover>;
6
7 /**
8 * Static method which allows you to get the popover instance associated with
9 * a DOM element, or create a new one in case it wasn’t initialised
10 */
11 static getOrCreateInstance: GetOrCreateInstanceFactory<Popover, Partial<Popover.Options>>;
12
13 static jQueryInterface: Popover.jQueryInterface;
14
15 static NAME: 'popover';
16
17 /**
18 * Default settings of this plugin
19 *
20 * @link https://getbootstrap.com/docs/5.0/getting-started/javascript/#default-settings
21 */
22 static Default: Popover.Options;
23
24 static DefaultType: Record<keyof Popover.Options, string>;
25
26 static Event: Record<
27 | 'CLICK'
28 | 'FOCUSIN'
29 | 'FOCUSOUT'
30 | 'HIDDEN'
31 | 'HIDE'
32 | 'INSERTED'
33 | 'MOUSEENTER'
34 | 'MOUSELEAVE'
35 | 'SHOW'
36 | 'SHOWN',
37 string
38 >;
39 constructor(element: string | Element, options?: Partial<Popover.Options>);
40
41 /**
42 * Reveals an element’s popover. Returns to the caller before the
43 * popover has actually been shown (i.e. before the shown.bs.popover
44 * event occurs). This is considered a “manual” triggering of the
45 * popover. Popovers whose title and content are both zero-length are
46 * never displayed.
47 */
48 show(): void;
49
50 /**
51 * Hides an element’s popover. Returns to the caller before the popover
52 * has actually been hidden (i.e. before the hidden.bs.popover event
53 * occurs). This is considered a “manual” triggering of the popover.
54 */
55 hide(): void;
56
57 /**
58 * Toggles an element’s popover. Returns to the caller before the
59 * popover has actually been shown or hidden (i.e. before the
60 * shown.bs.popover or hidden.bs.popover event occurs). This is
61 * considered a “manual” triggering of the popover.
62 */
63 toggle(): void;
64
65 /**
66 * Gives an element’s popover the ability to be shown. Popovers are
67 * enabled by default.
68 */
69 enable(): void;
70
71 /**
72 * Removes the ability for an element’s popover to be shown. The popover
73 * will only be able to be shown if it is re-enabled.
74 */
75 disable(): void;
76
77 /**
78 * Toggles the ability for an element’s popover to be shown or hidden.
79 */
80 toggleEnabled(): void;
81
82 /**
83 * Updates the position of an element’s popover.
84 */
85 update(): void;
86}
87
88declare namespace Popover {
89 enum Events {
90 /**
91 * This event fires immediately when the show instance method is called.
92 */
93 show = 'show.bs.popover',
94
95 /**
96 * This event is fired when the popover has been made visible to the
97 * user (will wait for CSS transitions to complete).
98 */
99 shown = 'shown.bs.popover',
100
101 /**
102 * This event is fired immediately when the hide instance method has
103 * been called.
104 */
105 hide = 'hide.bs.popover',
106
107 /**
108 * This event is fired when the popover has finished being hidden from
109 * the user (will wait for CSS transitions to complete).
110 */
111 hidden = 'hidden.bs.popover',
112
113 /**
114 * This event is fired after the show.bs.popover event when the popover
115 * template has been added to the DOM.
116 */
117 inserted = 'inserted.bs.popover',
118 }
119
120 type PopperConfigFunction = (defaultBsPopperConfig: Options) => Partial<Options>;
121
122 interface Options extends Omit<Tooltip.Options, 'popperConfig'> {
123 /**
124 * Default content value if data-content attribute isn't present.
125 *
126 * If a function is given, it will be called with its this reference set
127 * to the element that the popover is attached to.
128 *
129 * @default ''
130 */
131 content: string | Element | JQuery | ((this: HTMLElement) => string | Element | JQuery);
132
133 /**
134 * To change Bootstrap's default Popper.js config
135 *
136 * When a function is used to create the Popper configuration, it's
137 * called with an object that contains the Bootstrap's default Popper
138 * configuration. It helps you use and merge the default with your own
139 * configuration. The function must return a configuration object for
140 * Popper.
141 *
142 * @see {@link https://popper.js.org/docs/v2}
143 * @default null
144 */
145 popperConfig: Partial<Options> | PopperConfigFunction | null;
146 }
147
148 type jQueryInterface = (
149 config?:
150 | Partial<Options>
151 | 'show'
152 | 'hide'
153 | 'toggle'
154 | 'enable'
155 | 'disable'
156 | 'toggleEnabled'
157 | 'update'
158 | 'dispose',
159 ) => void;
160}
161
162export default Popover;