1
0

tooltip_documentation.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. Note that with this method you cannot apply additional properties (props) or styling directly to the tooltip.
  10. If you need custom styling or properties, nest a `ui.tooltip` element instead.
  11. ''')
  12. def tooltip_method_demo():
  13. ui.label('Tooltips...').tooltip('...are shown on mouse over')
  14. @doc.demo('Tooltip with HTML', '''
  15. You can use HTML in tooltips by nesting a `ui.html` element.
  16. ''')
  17. def tooltip_html_demo():
  18. with ui.label('HTML...'):
  19. with ui.tooltip():
  20. ui.html('<b>b</b>, <em>em</em>, <u>u</u>, <s>s</s>')
  21. @doc.demo('Tooltip with other content', '''
  22. Other elements like `ui.images` can also be nested inside a tooltip.
  23. ''')
  24. def tooltip_with_other_content():
  25. with ui.label('Mountains...'):
  26. with ui.tooltip().classes('bg-transparent'):
  27. ui.image('https://picsum.photos/id/377/640/360').classes('w-64')
  28. @doc.demo('Tooltip on HTML and Markdown', '''
  29. Some elements like `ui.html` and `ui.markdown` do not support nested elements.
  30. In this case, you can nest such elements inside a container element with a tooltip.
  31. ''')
  32. def tooltip_on_html_and_markdown():
  33. with ui.element().tooltip('...with a tooltip!'):
  34. ui.html('This is <u>HTML</u>...')
  35. @doc.demo('Tooltip for the upload element', '''
  36. Components like `ui.upload` do not support tooltips directly.
  37. You can wrap them in a `ui.element` to add tooltips and props.
  38. ''')
  39. def simple_upload_with_tooltip_demo():
  40. with ui.element():
  41. ui.upload(on_upload=lambda e: ui.notify(f'Uploaded {e.name}')).classes('w-72')
  42. ui.tooltip('Upload files').props('delay=1000 transition-show=rotate')
  43. doc.reference(ui.tooltip)