flowbite-mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +324 -0
  3. package/build/index.js +975 -0
  4. package/build/server-runner.js +228 -0
  5. package/data/components/accordion.md +860 -0
  6. package/data/components/alerts.md +739 -0
  7. package/data/components/avatar.md +178 -0
  8. package/data/components/badge.md +420 -0
  9. package/data/components/banner.md +145 -0
  10. package/data/components/bottom-navigation.md +513 -0
  11. package/data/components/breadcrumb.md +273 -0
  12. package/data/components/button-group.md +410 -0
  13. package/data/components/buttons.md +405 -0
  14. package/data/components/card.md +711 -0
  15. package/data/components/carousel.md +858 -0
  16. package/data/components/chat-bubble.md +1063 -0
  17. package/data/components/clipboard.md +1029 -0
  18. package/data/components/datepicker.md +673 -0
  19. package/data/components/device-mockups.md +152 -0
  20. package/data/components/drawer.md +1353 -0
  21. package/data/components/dropdowns.md +1925 -0
  22. package/data/components/footer.md +299 -0
  23. package/data/components/forms.md +371 -0
  24. package/data/components/gallery.md +322 -0
  25. package/data/components/indicators.md +262 -0
  26. package/data/components/jumbotron.md +213 -0
  27. package/data/components/kbd.md +217 -0
  28. package/data/components/list-group.md +365 -0
  29. package/data/components/mega-menu.md +558 -0
  30. package/data/components/modal.md +1309 -0
  31. package/data/components/navbar.md +1053 -0
  32. package/data/components/pagination.md +472 -0
  33. package/data/components/popover.md +826 -0
  34. package/data/components/progress.md +95 -0
  35. package/data/components/qr-code.md +280 -0
  36. package/data/components/rating.md +323 -0
  37. package/data/components/sidebar.md +1067 -0
  38. package/data/components/skeleton.md +221 -0
  39. package/data/components/speed-dial.md +1270 -0
  40. package/data/components/spinner.md +222 -0
  41. package/data/components/stepper.md +271 -0
  42. package/data/components/tables.md +3127 -0
  43. package/data/components/tabs.md +808 -0
  44. package/data/components/timeline.md +304 -0
  45. package/data/components/toast.md +341 -0
  46. package/data/components/tooltips.md +524 -0
  47. package/data/components/typography.md +269 -0
  48. package/data/components/video.md +95 -0
  49. package/data/forms/checkbox.md +375 -0
  50. package/data/forms/file-input.md +98 -0
  51. package/data/forms/floating-label.md +185 -0
  52. package/data/forms/input-field.md +222 -0
  53. package/data/forms/number-input.md +1099 -0
  54. package/data/forms/phone-input.md +577 -0
  55. package/data/forms/radio.md +315 -0
  56. package/data/forms/range.md +83 -0
  57. package/data/forms/search-input.md +280 -0
  58. package/data/forms/select.md +259 -0
  59. package/data/forms/textarea.md +155 -0
  60. package/data/forms/timepicker.md +732 -0
  61. package/data/forms/toggle.md +176 -0
  62. package/data/plugins/charts.md +2683 -0
  63. package/data/plugins/datatables.md +1922 -0
  64. package/data/plugins/datepicker.md +5 -0
  65. package/data/plugins/wysiwyg.md +2377 -0
  66. package/data/quickstart.md +169 -0
  67. package/data/theme.md +231 -0
  68. package/data/toc.md +79 -0
  69. package/data/typography/blockquote.md +182 -0
  70. package/data/typography/headings.md +174 -0
  71. package/data/typography/hr.md +74 -0
  72. package/data/typography/images.md +168 -0
  73. package/data/typography/links.md +118 -0
  74. package/data/typography/lists.md +387 -0
  75. package/data/typography/paragraphs.md +186 -0
  76. package/data/typography/text.md +249 -0
  77. package/package.json +71 -0
@@ -0,0 +1,524 @@
1
+ ---
2
+ layout: docs
3
+ title: Tailwind CSS Tooltip - Flowbite
4
+ description: Use the following Tailwind CSS powered tooltips to show extra content when hovering or focusing on an element
5
+ group: components
6
+ toc: true
7
+ requires_js: true
8
+
9
+ previous: Toast
10
+ previousLink: components/toast/
11
+
12
+ next: Typography
13
+ nextLink: components/typography/
14
+ ---
15
+
16
+ Flowbite allows you to use the Tailwind CSS tooltip component to show extra information when hovering or focusing over an element in multiple positions, styles, and animations.
17
+
18
+ Before continuing, make sure that you have the <a href="{{< ref "getting-started/quickstart" >}}">Flowbite JavaScript file</a> included in your project in order to make the tooltip component work.
19
+
20
+ ## Default tooltip example
21
+
22
+ To get started with using tooltips all you need to do is add the `data-tooltip-target="{elementId}"` data attribute to an element where `elementId` is the id of the tooltip component. In the following example you can see the button that will trigger the `tooltip-default` element to be shown when hovered or focused.
23
+
24
+ {{< example class="flex justify-center pt-8" github="components/tooltips.md" show_dark=true >}}
25
+ <button data-tooltip-target="tooltip-default" type="button" class="text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Default tooltip</button>
26
+
27
+ <div id="tooltip-default" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-dark rounded-base shadow-xs opacity-0 tooltip">
28
+ Tooltip content
29
+ <div class="tooltip-arrow" data-popper-arrow></div>
30
+ </div>
31
+ {{< /example >}}
32
+
33
+ ## Tooltip styles
34
+
35
+ You can use choose between dark and light version styles for the tooltip component by changing the utility classes from Tailwind CSS and by applying the `data-tooltip-style="{light|dark}"` data attribute.
36
+
37
+ {{< example class="flex justify-center pt-8 " github="components/tooltips.md" show_dark=true >}}
38
+
39
+ <!-- Light style tooltip -->
40
+
41
+ <button data-tooltip-target="tooltip-light" data-tooltip-style="light" type="button" class="text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Light tooltip</button>
42
+
43
+ <div id="tooltip-light" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-heading bg-neutral-primary-medium border border-default rounded-base shadow-xs opacity-0 tooltip">
44
+ Tooltip content
45
+ <div class="tooltip-arrow" data-popper-arrow></div>
46
+ </div>
47
+
48
+ <!-- Dark style tooltip -->
49
+
50
+ <button data-tooltip-target="tooltip-dark" type="button" class="ms-3 text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Dark tooltip</button>
51
+
52
+ <div id="tooltip-dark" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-dark rounded-base shadow-xs opacity-0 tooltip">
53
+ Tooltip content
54
+ <div class="tooltip-arrow" data-popper-arrow></div>
55
+ </div>
56
+ {{< /example >}}
57
+
58
+ ## Placement
59
+
60
+ The positioning of the tooltip element relative to the triggering element (eg. button, link) can be set using the `data-tooltip-placement="{top|right|bottom|left}"` data attribute.
61
+
62
+ {{< example class="flex flex-wrap justify-center py-8" github="components/tooltips.md" show_dark=true >}}
63
+
64
+ <!-- Show tooltip on top -->
65
+
66
+ <button data-tooltip-target="tooltip-top" data-tooltip-placement="top" type="button" class="mb-2 md:mb-0 text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Tooltip top</button>
67
+
68
+ <div id="tooltip-top" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-dark rounded-base shadow-xs opacity-0 tooltip">
69
+ Tooltip on top
70
+ <div class="tooltip-arrow" data-popper-arrow></div>
71
+ </div>
72
+
73
+ <!-- Show tooltip on right -->
74
+
75
+ <button data-tooltip-target="tooltip-right" data-tooltip-placement="right" type="button" class="ms-3 mb-2 md:mb-0 text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Tooltip right</button>
76
+
77
+ <div id="tooltip-right" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-dark rounded-base shadow-xs opacity-0 tooltip">
78
+ Tooltip on right
79
+ <div class="tooltip-arrow" data-popper-arrow></div>
80
+ </div>
81
+
82
+ <!-- Show tooltip on bottom -->
83
+
84
+ <button data-tooltip-target="tooltip-bottom" data-tooltip-placement="bottom" type="button" class="ms-3 mb-2 md:mb-0 text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Tooltip bottom</button>
85
+
86
+ <div id="tooltip-bottom" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-dark rounded-base shadow-xs opacity-0 tooltip">
87
+ Tooltip on bottom
88
+ <div class="tooltip-arrow" data-popper-arrow></div>
89
+ </div>
90
+
91
+ <!-- Show tooltip on left -->
92
+
93
+ <button data-tooltip-target="tooltip-left" data-tooltip-placement="left" type="button" class="ms-3 mb-2 md:mb-0 text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Tooltip left</button>
94
+
95
+ <div id="tooltip-left" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-dark rounded-base shadow-xs opacity-0 tooltip">
96
+ Tooltip on left
97
+ <div class="tooltip-arrow" data-popper-arrow></div>
98
+ </div>
99
+ {{< /example >}}
100
+
101
+ ## Triggering
102
+
103
+ You can choose the triggering event by using the `data-tooltip-trigger="{hover|click}"` data attributes to choose whether you want to show the tooltip when hovering or clicking on the element. By default this option is set to `hover`.
104
+
105
+ {{< example class="flex justify-center pt-8" github="components/tooltips.md" show_dark=true >}}
106
+
107
+ <!-- Show tooltip on hover -->
108
+
109
+ <button data-tooltip-target="tooltip-hover" data-tooltip-trigger="hover" type="button" class="text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Tooltip hover</button>
110
+
111
+ <div id="tooltip-hover" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-dark rounded-base shadow-xs opacity-0 tooltip">
112
+ Tooltip content
113
+ <div class="tooltip-arrow" data-popper-arrow></div>
114
+ </div>
115
+
116
+ <!-- Show tooltip on click -->
117
+
118
+ <button data-tooltip-target="tooltip-click" data-tooltip-trigger="click" type="button" class="ms-3 text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Tooltip click</button>
119
+
120
+ <div id="tooltip-click" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-dark rounded-base shadow-xs opacity-0 tooltip">
121
+ Tooltip content
122
+ <div class="tooltip-arrow" data-popper-arrow></div>
123
+ </div>
124
+ {{< /example >}}
125
+
126
+ ## Animation
127
+
128
+ You can set tooltip animation styles by using the transition utility classes from Tailwind CSS. Make sure that you add `transition-opacity` and `duration-{x}` to set the animation duration.
129
+
130
+ {{< example class="flex justify-center pt-8" github="components/tooltips.md" show_dark=true >}}
131
+ <button data-tooltip-target="tooltip-animation" type="button" class="text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Animated tooltip</button>
132
+
133
+ <div id="tooltip-animation" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-dark rounded-base shadow-xs opacity-0 tooltip">
134
+ Tooltip content
135
+ <div class="tooltip-arrow" data-popper-arrow></div>
136
+ </div>
137
+ {{< /example >}}
138
+
139
+ ## Disable arrow
140
+
141
+ You can also disable the tooltip arrow by not including the `data-popper-arrow` element.
142
+
143
+ {{< example class="flex justify-center pt-8" github="components/tooltips.md" show_dark=true >}}
144
+ <button data-tooltip-target="tooltip-no-arrow" type="button" class="text-white bg-brand box-border border border-transparent hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-4 py-2.5 focus:outline-none">Default tooltip</button>
145
+
146
+ <div id="tooltip-no-arrow" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-dark rounded-base shadow-xs opacity-0 tooltip">
147
+ Tooltip content
148
+ </div>
149
+ {{< /example >}}
150
+
151
+ ## JavaScript behaviour
152
+
153
+ The **Tooltip** class from Flowbite can be used to create an object that will show a tooltip element relative to the main trigger element, such as a button, based on the parameters, options, and methods that you provide.
154
+
155
+ ### Object parameters
156
+
157
+ Initialize a Tooltip object with the object parameters including the trigger element, the tooltip content element, and extra options to set the positioning and offsets of the tooltip.
158
+
159
+ <div class="relative my-10 overflow-x-auto shadow-xs rounded-base border border-default">
160
+ <table class="w-full text-sm text-left text-body">
161
+ <thead class="bg-neutral-secondary-soft text-heading">
162
+ <tr class="text-xs font-medium uppercase">
163
+ <th scope="col" class="px-6 py-3">
164
+ Parameter
165
+ </th>
166
+ <th scope="col" class="px-6 py-3">
167
+ Type
168
+ </th>
169
+ <th scope="col" class="px-6 py-3">
170
+ Required
171
+ </th>
172
+ <th scope="col" class="px-6 py-3">
173
+ Description
174
+ </th>
175
+ </tr>
176
+ </thead>
177
+ <tbody>
178
+ <tr class="border-b bg-neutral-primary border-default">
179
+ <td class="px-6 py-4 font-medium">
180
+ <code class="text-fg-brand">targetEl</code>
181
+ </td>
182
+ <td class="px-6 py-4">
183
+ Element
184
+ </td>
185
+ <td class="px-6 py-4">
186
+ Required
187
+ </td>
188
+ <td class="px-6 py-4">
189
+ Apply the tooltip content element to show and hide it either using the methods or the hover or click status of the trigger element.
190
+ </td>
191
+ </tr>
192
+ <tr class="border-b bg-neutral-primary border-default">
193
+ <td class="px-6 py-4 font-medium">
194
+ <code class="text-fg-brand">triggerEl</code>
195
+ </td>
196
+ <td class="px-6 py-4">
197
+ Element
198
+ </td>
199
+ <td class="px-6 py-4">
200
+ Required
201
+ </td>
202
+ <td class="px-6 py-4">
203
+ Set an element to trigger the tooltip when clicking or hovering (ie. a button, text).
204
+ </td>
205
+ </tr>
206
+ <tr class="border-b bg-neutral-primary border-default">
207
+ <td class="px-6 py-4 font-medium">
208
+ <code class="text-fg-brand">options</code>
209
+ </td>
210
+ <td class="px-6 py-4">
211
+ Object
212
+ </td>
213
+ <td class="px-6 py-4">
214
+ Optional
215
+ </td>
216
+ <td class="px-6 py-4">
217
+ Use the options parameter to set the positioning of the tooltip element, trigger type, offsets, and more.
218
+ </td>
219
+ </tr>
220
+ <tr class="bg-neutral-primary">
221
+ <td class="px-6 py-4 font-medium">
222
+ <code class="text-fg-brand">instanceOptions</code>
223
+ </td>
224
+ <td class="px-6 py-4">
225
+ Object
226
+ </td>
227
+ <td class="px-6 py-4">
228
+ Optional
229
+ </td>
230
+ <td class="px-6 py-4">
231
+ Object of options that allows you to set a custom ID for the instance that is being added to the <a href="https://flowbite.com/docs/getting-started/javascript/#instance-options" class="underline hover:no-underline">Instance Manager</a> and whether to override or not an existing instance.
232
+ </td>
233
+ </tr>
234
+ </tbody>
235
+ </table>
236
+ </div>
237
+
238
+ ### Options
239
+
240
+ Use the following options as the third parameter for the Tooltip class to set the positioning, offset, and the trigger type (hover or click) for the tooltip element.
241
+
242
+ <div class="relative my-10 overflow-x-auto shadow-xs rounded-base border border-default">
243
+ <table class="w-full text-sm text-left text-body">
244
+ <thead class="bg-neutral-secondary-soft text-heading">
245
+ <tr class="text-xs font-medium uppercase">
246
+ <th scope="col" class="px-6 py-3">
247
+ Option
248
+ </th>
249
+ <th scope="col" class="px-6 py-3">
250
+ Type
251
+ </th>
252
+ <th scope="col" class="px-6 py-3">
253
+ Description
254
+ </th>
255
+ </tr>
256
+ </thead>
257
+ <tbody>
258
+ <tr class="border-b bg-neutral-primary border-default">
259
+ <td class="px-6 py-4 font-medium">
260
+ <code class="text-fg-brand">placement</code>
261
+ </td>
262
+ <td class="px-6 py-4 font-medium">
263
+ String
264
+ </td>
265
+ <td class="px-6 py-4">
266
+ Set the position of the tooltip element relative to the trigger element choosing from <code class="text-fg-brand">top|right|bottom|left</code>.
267
+ </td>
268
+ </tr>
269
+ <tr class="border-b bg-neutral-primary border-default">
270
+ <td class="px-6 py-4 font-medium">
271
+ <code class="text-fg-brand">triggerType</code>
272
+ </td>
273
+ <td class="px-6 py-4 font-medium">
274
+ String
275
+ </td>
276
+ <td class="px-6 py-4">
277
+ Set the event type that will trigger the tooltip content choosing between <code class="text-fg-brand">hover|click|none</code>.
278
+ </td>
279
+ </tr>
280
+ <tr class="border-b bg-neutral-primary border-default">
281
+ <td class="px-6 py-4 font-medium">
282
+ <code class="text-fg-brand">onHide</code>
283
+ </td>
284
+ <td class="px-6 py-4 font-medium">
285
+ Function
286
+ </td>
287
+ <td class="px-6 py-4">
288
+ Set a callback function when the tooltip is hidden.
289
+ </td>
290
+ </tr>
291
+ <tr class="border-b bg-neutral-primary border-default">
292
+ <td class="px-6 py-4 font-medium">
293
+ <code class="text-fg-brand">onShow</code>
294
+ </td>
295
+ <td class="px-6 py-4 font-medium">
296
+ Function
297
+ </td>
298
+ <td class="px-6 py-4">
299
+ Set a callback function when the tooltip is shown.
300
+ </td>
301
+ </tr>
302
+ <tr class="bg-neutral-primary">
303
+ <td class="px-6 py-4 font-medium">
304
+ <code class="text-fg-brand">onToggle</code>
305
+ </td>
306
+ <td class="px-6 py-4 font-medium">
307
+ Function
308
+ </td>
309
+ <td class="px-6 py-4">
310
+ Set a callback function when the tooltip visibility is toggled.
311
+ </td>
312
+ </tr>
313
+ </tbody>
314
+ </table>
315
+ </div>
316
+
317
+ ### Methods
318
+
319
+ Use the methods from the Tooltip object to programmatically show or hide the tooltip from JavaScript.
320
+
321
+ <div class="relative my-10 overflow-x-auto shadow-xs rounded-base border border-default">
322
+ <table class="w-full text-sm text-left text-body">
323
+ <thead class="bg-neutral-secondary-soft text-heading">
324
+ <tr class="text-xs font-medium uppercase">
325
+ <th scope="col" class="px-6 py-3">
326
+ Method
327
+ </th>
328
+ <th scope="col" class="px-6 py-3">
329
+ Description
330
+ </th>
331
+ </tr>
332
+ </thead>
333
+ <tbody>
334
+ <tr class="border-b bg-neutral-primary border-default">
335
+ <td class="px-6 py-4 font-medium">
336
+ <code class="text-fg-brand">show()</code>
337
+ </td>
338
+ <td class="px-6 py-4">
339
+ Use this method on the Tooltip object to show the tooltip content.
340
+ </td>
341
+ </tr>
342
+ <tr class="border-b bg-neutral-primary border-default">
343
+ <td class="px-6 py-4 font-medium">
344
+ <code class="text-fg-brand">hide()</code>
345
+ </td>
346
+ <td class="px-6 py-4">
347
+ Use this method on the Tooltip object to hide the tooltip content.
348
+ </td>
349
+ </tr>
350
+ <tr class="border-b bg-neutral-primary border-default">
351
+ <td class="px-6 py-4 font-medium">
352
+ <code class="text-fg-brand">toggle()</code>
353
+ </td>
354
+ <td class="px-6 py-4">
355
+ Use this method on the Tooltip object to toggle the visibility of the tooltip content.
356
+ </td>
357
+ </tr>
358
+ <tr class="border-b bg-neutral-primary border-default">
359
+ <td class="px-6 py-4 font-medium">
360
+ <code class="text-fg-brand">updateOnShow(callback)</code>
361
+ </td>
362
+ <td class="px-6 py-4">
363
+ Use this method to set a custom callback function when the tooltip has been shown.
364
+ </td>
365
+ </tr>
366
+ <tr class="border-b bg-neutral-primary border-default">
367
+ <td class="px-6 py-4 font-medium">
368
+ <code class="text-fg-brand">updateOnHide(callback)</code>
369
+ </td>
370
+ <td class="px-6 py-4">
371
+ Use this method to set a custom callback function when the tooltip has been hidden.
372
+ </td>
373
+ </tr>
374
+ <tr class="border-b bg-neutral-primary border-default">
375
+ <td class="px-6 py-4 font-medium">
376
+ <code class="text-fg-brand">updateOnToggle(callback)</code>
377
+ </td>
378
+ <td class="px-6 py-4">
379
+ Use this method to set a custom callback function when the tooltip visibility has been toggled.
380
+ </td>
381
+ </tr>
382
+ </tbody>
383
+ </table>
384
+ </div>
385
+
386
+ ### Example
387
+
388
+ Check out the following JavaScript example to learn how to initialize, set the options, and use the methods for the Tooltip object.
389
+
390
+ First of all, set the target element as the tooltip itself and the trigger element which can be a button or text element.
391
+
392
+ After that you can also set the options object to change the placement and trigger type of the tooltip, alongside with the callback functions.
393
+
394
+ {{< code lang="javascript" file="tooltip.js" icon="file" >}}
395
+ // set the tooltip content element
396
+ const $targetEl = document.getElementById('tooltipContent');
397
+
398
+ // set the element that trigger the tooltip using hover or click
399
+ const $triggerEl = document.getElementById('tooltipButton');
400
+
401
+ // options with default values
402
+ const options = {
403
+ placement: 'bottom',
404
+ triggerType: 'hover',
405
+ onHide: () => {
406
+ console.log('tooltip is shown');
407
+ },
408
+ onShow: () => {
409
+ console.log('tooltip is hidden');
410
+ },
411
+ onToggle: () => {
412
+ console.log('tooltip is toggled');
413
+ },
414
+ };
415
+
416
+
417
+ // instance options with default values
418
+ const instanceOptions = {
419
+ id: 'tooltipContent',
420
+ override: true
421
+ };
422
+ {{< /code >}}
423
+
424
+ Create a new Tooltip object based on the options above.
425
+
426
+ {{< code lang="javascript" file="tooltip.js" icon="file" >}}
427
+ import { Tooltip } from 'flowbite';
428
+
429
+ /*
430
+ * $targetEl: required
431
+ * $triggerEl: required
432
+ * options: optional
433
+ */
434
+ const tooltip = new Tooltip($targetEl, $triggerEl, options, instanceOptions);
435
+ {{< /code >}}
436
+
437
+ Use the `show` and `hide` methods on the Tooltip object to programmatically show and hide the tooltip element using JavaScript.
438
+
439
+ {{< code lang="javascript" >}}
440
+ // show the tooltip
441
+ tooltip.show();
442
+
443
+ // hide the tooltip
444
+ tooltip.hide();
445
+
446
+ // toggle the tooltip
447
+ tooltip.toggle();
448
+
449
+ // destroy tooltip object (removes event listeners and off-canvas Popper.js)
450
+ tooltip.destroy();
451
+
452
+ // re-initialize tooltip object
453
+ tooltip.init();
454
+ {{< /code >}}
455
+
456
+ ### HTML Markup
457
+
458
+ Use the following HTML code for the JavaScript example above.
459
+
460
+ {{< code lang="html" file="tooltip.html" icon="file" >}}
461
+ <button
462
+ id="tooltipButton"
463
+ type="button"
464
+ class="rounded-lg bg-blue-700 px-5 py-2.5 text-center text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">
465
+ Default tooltip
466
+ </button>
467
+ <div
468
+ id="tooltipContent"
469
+ role="tooltip"
470
+ class="tooltip invisible absolute z-10 inline-block rounded-lg bg-gray-900 px-3 py-2 text-sm font-medium text-white opacity-0 shadow-xs transition-opacity duration-300 dark:bg-gray-700"
471
+ >
472
+ Tooltip content
473
+ <div class="tooltip-arrow" data-popper-arrow></div>
474
+ </div>
475
+ {{< /code >}}
476
+
477
+ ### TypeScript
478
+
479
+ If you're using the <a href="{{< ref "getting-started/typescript" >}}">TypeScript configuration</a> from Flowbite then you can import the types for the Tooltip class, parameters and its options.
480
+
481
+ Here's an example that applies the types from Flowbite to the code above:
482
+
483
+ {{< code lang="typescript" file="tooltip.ts" icon="file" >}}
484
+ import { Tooltip } from 'flowbite';
485
+ import type { TooltipOptions, TooltipInterface } from 'flowbite';
486
+ import type { InstanceOptions } from 'flowbite';
487
+
488
+ // set the tooltip content element
489
+ const $targetEl: HTMLElement = document.getElementById('tooltipContent');
490
+
491
+ // set the element that trigger the tooltip using hover or click
492
+ const $triggerEl: HTMLElement = document.getElementById('tooltipButton');
493
+
494
+ // options with default values
495
+ const options: TooltipOptions = {
496
+ placement: 'top',
497
+ triggerType: 'hover',
498
+ onHide: () => {
499
+ console.log('tooltip is shown');
500
+ },
501
+ onShow: () => {
502
+ console.log('tooltip is hidden');
503
+ },
504
+ onToggle: () => {
505
+ console.log('tooltip is toggled');
506
+ },
507
+ };
508
+
509
+ // instance options with default values
510
+ const instanceOptions: InstanceOptions = {
511
+ id: 'tooltipContent',
512
+ override: true
513
+ };
514
+
515
+ /*
516
+ * targetEl: required
517
+ * triggerEl: required
518
+ * options: optional
519
+ */
520
+ const tooltip: TooltipInterface = new Tooltip($targetEl, $triggerEl, options, instanceOptions);
521
+
522
+ // show the tooltip
523
+ tooltip.show();
524
+ {{< /code >}}