link_documentation.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from nicegui import ui
  2. from ....style import link_target
  3. from ...model import UiElementDocumentation
  4. class LinkDocumentation(UiElementDocumentation, element=ui.link):
  5. def main_demo(self) -> None:
  6. ui.link('NiceGUI on GitHub', 'https://github.com/zauberzeug/nicegui')
  7. def more(self) -> None:
  8. @self.demo('Navigate on large pages', '''
  9. To jump to a specific location within a page you can place linkable anchors with `ui.link_target('target_name')`
  10. or simply pass a NiceGUI element as link target.
  11. ''')
  12. def same_page_links():
  13. navigation = ui.row()
  14. # ui.link_target('target_A')
  15. link_target('target_A', '-10px') # HIDE
  16. ui.label(
  17. 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, '
  18. 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
  19. )
  20. link_target('target_B', '70px') # HIDE
  21. label_B = ui.label(
  22. 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. '
  23. 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. '
  24. 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
  25. )
  26. with navigation:
  27. ui.link('Goto A', '#target_A')
  28. # ui.link('Goto B', label_B)
  29. ui.link('Goto B', '#target_B') # HIDE
  30. @self.demo('Links to other pages', '''
  31. You can link to other pages by providing the link target as path or function reference.
  32. ''')
  33. def link_to_other_page():
  34. @ui.page('/some_other_page')
  35. def my_page():
  36. ui.label('This is another page')
  37. ui.label('Go to other page')
  38. ui.link('... with path', '/some_other_page')
  39. ui.link('... with function reference', my_page)
  40. @self.demo('Link from images and other elements', '''
  41. By nesting elements inside a link you can make the whole element clickable.
  42. This works with all elements but is most useful for non-interactive elements like
  43. [ui.image](/documentation/image), [ui.avatar](/documentation/image) etc.
  44. ''')
  45. def link_from_elements():
  46. with ui.link(target='https://github.com/zauberzeug/nicegui'):
  47. ui.image('https://picsum.photos/id/41/640/360').classes('w-64')