link_documentation.py 2.1 KB

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