tooltip_documentation.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.tooltip)
  4. def tooltips_demo():
  5. with ui.button(icon='thumb_up'):
  6. ui.tooltip('I like this').classes('bg-green')
  7. @doc.demo('Tooltip method', '''
  8. Instead of nesting a tooltip element inside another element, you can also use the `tooltip` method.
  9. ''')
  10. def tooltip_method_demo():
  11. ui.label('Tooltips...').tooltip('...are shown on mouse over')
  12. @doc.demo('Tooltip with HTML', '''
  13. You can use HTML in tooltips by nesting a `ui.html` element.
  14. ''')
  15. def tooltip_html_demo():
  16. with ui.label('HTML...'):
  17. with ui.tooltip():
  18. ui.html('<b>b</b>, <em>em</em>, <u>u</u>, <s>s</s>')
  19. @doc.demo('Tooltip with other content', '''
  20. You can use HTML in tooltips.
  21. ''')
  22. def tooltip_with_other_content():
  23. with ui.label('Mountains...'):
  24. with ui.tooltip().classes('bg-transparent'):
  25. ui.image('https://picsum.photos/id/377/640/360').classes('w-64')
  26. @doc.demo('Tooltip on HTML and Markdown', '''
  27. Some elements like `ui.html` and `ui.markdown` do not support nested elements.
  28. In this case, you can nest such elements inside a container element with a tooltip.
  29. ''')
  30. def tooltip_on_html_and_markdown():
  31. with ui.element().tooltip('...with a tooltip!'):
  32. ui.html('This is <u>HTML</u>...')
  33. doc.reference(ui.tooltip)