1 | import * as Popper from "@popperjs/core";
|
2 | import BaseComponent, { GetInstanceFactory, GetOrCreateInstanceFactory } from "./base-component";
|
3 |
|
4 | declare class Tooltip extends BaseComponent {
|
5 | static getInstance: GetInstanceFactory<Tooltip>;
|
6 |
|
7 | |
8 |
|
9 |
|
10 |
|
11 | static getOrCreateInstance: GetOrCreateInstanceFactory<Tooltip>;
|
12 |
|
13 | static jQueryInterface: Tooltip.jQueryInterface;
|
14 |
|
15 | static NAME: "tooltip";
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 | static Default: Tooltip.Options;
|
23 |
|
24 | static Event: Record<
|
25 | | "CLICK"
|
26 | | "FOCUSIN"
|
27 | | "FOCUSOUT"
|
28 | | "HIDDEN"
|
29 | | "HIDE"
|
30 | | "INSERTED"
|
31 | | "MOUSEENTER"
|
32 | | "MOUSELEAVE"
|
33 | | "SHOW"
|
34 | | "SHOWN",
|
35 | string
|
36 | >;
|
37 |
|
38 | static DefaultType: Record<keyof Tooltip.Options, string>;
|
39 | constructor(element: string | Element, options?: Partial<Tooltip.Options>);
|
40 |
|
41 | static SetContentFunction: Tooltip.SetContentFunction;
|
42 |
|
43 | /**
|
44 | * Reveals an element’s tooltip. Returns to the caller before the
|
45 | * tooltip has actually been shown (i.e. before the shown.bs.tooltip
|
46 | * event occurs). This is considered a “manual” triggering of the
|
47 | * tooltip. Tooltips with zero-length titles are never displayed.
|
48 | */
|
49 | show(): void;
|
50 |
|
51 | /**
|
52 | * Hides an element’s tooltip. Returns to the caller before the tooltip
|
53 | * has actually been hidden (i.e. before the hidden.bs.tooltip event
|
54 | * occurs). This is considered a “manual” triggering of the tooltip.
|
55 | */
|
56 | hide(): void;
|
57 |
|
58 | /**
|
59 | * Toggles an element’s tooltip. Returns to the caller before the
|
60 | * tooltip has actually been shown or hidden (i.e. before the
|
61 | * shown.bs.tooltip or hidden.bs.tooltip event occurs). This is
|
62 | * considered a “manual” triggering of the tooltip.
|
63 | */
|
64 | toggle(event?: any): void;
|
65 |
|
66 | /**
|
67 | * Gives an element’s tooltip the ability to be shown. Tooltips are
|
68 | * enabled by default.
|
69 | */
|
70 | enable(): void;
|
71 |
|
72 | /**
|
73 | * Removes the ability for an element’s tooltip to be shown. The tooltip
|
74 | * will only be able to be shown if it is re-enabled.
|
75 | */
|
76 | disable(): void;
|
77 |
|
78 | /**
|
79 | * Toggles the ability for an element’s tooltip to be shown or hidden.
|
80 | */
|
81 | toggleEnabled(): void;
|
82 |
|
83 | /**
|
84 | * Updates the position of an element’s tooltip.
|
85 | */
|
86 | update(): void;
|
87 |
|
88 | /**
|
89 | * Gives a way to change the tooltip’s content after its initialization.
|
90 | */
|
91 | setContent(content?: Record<string, string | Element | Tooltip.SetContentFunction | null>): void;
|
92 | }
|
93 |
|
94 | declare namespace Tooltip {
|
95 | enum Events {
|
96 | |
97 |
|
98 |
|
99 | show = "show.bs.tooltip",
|
100 |
|
101 | |
102 |
|
103 |
|
104 |
|
105 | shown = "shown.bs.tooltip",
|
106 |
|
107 | |
108 |
|
109 |
|
110 |
|
111 | hide = "hide.bs.tooltip",
|
112 |
|
113 | |
114 |
|
115 |
|
116 |
|
117 | hidden = "hidden.bs.tooltip",
|
118 |
|
119 | |
120 |
|
121 |
|
122 |
|
123 | inserted = "inserted.bs.tooltip",
|
124 | }
|
125 |
|
126 | type Offset = [number, number];
|
127 |
|
128 | type OffsetFunction = () => Offset;
|
129 |
|
130 | type PopoverPlacement = "auto" | "top" | "bottom" | "left" | "right";
|
131 |
|
132 | type PopperConfigFunction = (defaultBsPopperConfig: Popper.Options) => Partial<Popper.Options>;
|
133 |
|
134 | interface Options {
|
135 | |
136 |
|
137 |
|
138 |
|
139 |
|
140 | animation: boolean;
|
141 |
|
142 | |
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 | container: string | Element | false;
|
152 |
|
153 | |
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | delay: number | { show: number; hide: number };
|
162 |
|
163 | |
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | html: boolean;
|
175 |
|
176 | |
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | placement: PopoverPlacement | (() => PopoverPlacement);
|
188 |
|
189 | /**
|
190 | * If a selector is provided, tooltip objects will be delegated to the
|
191 | * specified targets. In practice, this is used to also apply tooltips
|
192 | * to dynamically added DOM elements (jQuery.on support).
|
193 | *
|
194 | * @default false
|
195 | */
|
196 | selector: string | false;
|
197 |
|
198 | /**
|
199 | * Base HTML to use when creating the tooltip.
|
200 | *
|
201 | * The tooltip's title will be injected into the .tooltip-inner.
|
202 | *
|
203 | * .tooltip-arrow will become the tooltip's arrow.
|
204 | *
|
205 | * The outermost wrapper element should have the .tooltip class and
|
206 | * role="tooltip".
|
207 | *
|
208 | * @default '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
|
209 | */
|
210 | template: string;
|
211 |
|
212 | /**
|
213 | * Default title value if title attribute isn't present.
|
214 | *
|
215 | * If a function is given, it will be called with its this reference set
|
216 | * to the element that the popover is attached to.
|
217 | *
|
218 | * @default ''
|
219 | */
|
220 | title: string | Element | JQuery | ((this: HTMLElement) => string | Element | JQuery);
|
221 |
|
222 | /**
|
223 | * How tooltip is triggered - click | hover | focus | manual. You may
|
224 | * pass multiple triggers; separate them with a space.
|
225 | *
|
226 | * 'manual' indicates that the tooltip will be triggered
|
227 | * programmatically via the .tooltip('show'), .tooltip('hide') and
|
228 | * .tooltip('toggle') methods; this value cannot be combined with any
|
229 | * other trigger.
|
230 | *
|
231 | * 'hover' on its own will result in tooltips that cannot be triggered
|
232 | * via the keyboard, and should only be used if alternative methods for
|
233 | * conveying the same information for keyboard users is present.
|
234 | *
|
235 | * @default 'hover focus'
|
236 | */
|
237 | trigger:
|
238 | | "click"
|
239 | | "hover"
|
240 | | "focus"
|
241 | | "manual"
|
242 | | "click hover"
|
243 | | "click focus"
|
244 | | "hover focus"
|
245 | | "click hover focus";
|
246 |
|
247 | /**
|
248 | * Offset of the tooltip relative to its target.
|
249 | *
|
250 | * When a function is used to determine the offset, it is called with an
|
251 | * object containing the popper placement, the reference, and popper
|
252 | * rects as its first argument. The triggering element DOM node is
|
253 | * passed as the second argument. The function must return an array with
|
254 | * two numbers: [skidding, distance].
|
255 | *
|
256 | * @see {@link https://popper.js.org/docs/v2/modifiers/offset}
|
257 | * @default [0, 0]
|
258 | */
|
259 | offset: Offset | string | OffsetFunction;
|
260 |
|
261 | /**
|
262 | * Allow to specify which position Popper will use on fallback.
|
263 | *
|
264 | * @see {@link https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements}
|
265 | * @default ['top', 'right', 'bottom', 'left']
|
266 | */
|
267 | fallbackPlacements: string[];
|
268 |
|
269 | /**
|
270 | * Overflow constraint boundary of the popover. Accepts the values of
|
271 | * 'viewport', 'window', 'scrollParent', or an HTMLElement reference
|
272 | * (JavaScript only).
|
273 | *
|
274 | * @see {@link https://popper.js.org/docs/v1/#modifiers..preventOverflow.boundariesElement}
|
275 | * @default 'scrollParent'
|
276 | */
|
277 | boundary: Popper.Boundary;
|
278 |
|
279 | /**
|
280 | * Add classes to the tooltip when it is shown. Note that these classes
|
281 | * will be added in addition to any classes specified in the template.
|
282 | * To add multiple classes, separate them with spaces: 'class-1
|
283 | * class-2'.
|
284 | *
|
285 | * You can also pass a function that should return a single string
|
286 | * containing additional class names.
|
287 | *
|
288 | * @default ''
|
289 | */
|
290 | customClass?: string | (() => string) | undefined;
|
291 |
|
292 | /**
|
293 | * Enable or disable the sanitization. If activated 'template' and
|
294 | * 'title' options will be sanitized.
|
295 | *
|
296 | * @default true
|
297 | */
|
298 | sanitize: boolean;
|
299 |
|
300 | /**
|
301 | * Object which contains allowed attributes and tags
|
302 | *
|
303 | * @see {@link https://v5.getbootstrap.com/docs/5.0/getting-started/javascript/#sanitizer}
|
304 | */
|
305 | allowList: Record<keyof HTMLElementTagNameMap | "*", Array<string | RegExp>>;
|
306 |
|
307 | /**
|
308 | * Here you can supply your own sanitize function. This can be useful if
|
309 | * you prefer to use a dedicated library to perform sanitization.
|
310 | *
|
311 | * @default null
|
312 | */
|
313 | // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
314 | sanitizeFn: () => void | null;
|
315 |
|
316 | |
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | popperConfig: Partial<Popper.Options> | PopperConfigFunction | null;
|
329 | }
|
330 |
|
331 | type SetContentFunction = () => string | Element | (() => string | Element | null) | null;
|
332 |
|
333 | type jQueryInterface = (
|
334 | config?:
|
335 | | Partial<Options>
|
336 | | "show"
|
337 | | "hide"
|
338 | | "toggle"
|
339 | | "enable"
|
340 | | "disable"
|
341 | | "toggleEnabled"
|
342 | | "update"
|
343 | | "setContent"
|
344 | | "dispose",
|
345 | ) => JQuery;
|
346 | }
|
347 |
|
348 | export default Tooltip;
|