section_page_layout.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from nicegui import ui
  2. from . import (
  3. card_documentation,
  4. carousel_documentation,
  5. column_documentation,
  6. context_menu_documentation,
  7. dialog_documentation,
  8. doc,
  9. expansion_documentation,
  10. fullscreen_documentation,
  11. grid_documentation,
  12. list_documentation,
  13. menu_documentation,
  14. notification_documentation,
  15. notify_documentation,
  16. pagination_documentation,
  17. row_documentation,
  18. scroll_area_documentation,
  19. separator_documentation,
  20. skeleton_documentation,
  21. space_documentation,
  22. splitter_documentation,
  23. stepper_documentation,
  24. tabs_documentation,
  25. teleport_documentation,
  26. timeline_documentation,
  27. tooltip_documentation,
  28. )
  29. doc.title('Page *Layout*')
  30. @doc.demo('Auto-context', '''
  31. In order to allow writing intuitive UI descriptions, NiceGUI automatically tracks the context in which elements are created.
  32. This means that there is no explicit `parent` parameter.
  33. Instead the parent context is defined using a `with` statement.
  34. It is also passed to event handlers and timers.
  35. In the demo, the label "Card content" is added to the card.
  36. And because the `ui.button` is also added to the card, the label "Click!" will also be created in this context.
  37. The label "Tick!", which is added once after one second, is also added to the card.
  38. This design decision allows for easily creating modular components that keep working after moving them around in the UI.
  39. For example, you can move label and button somewhere else, maybe wrap them in another container, and the code will still work.
  40. ''')
  41. def auto_context_demo():
  42. with ui.card():
  43. ui.label('Card content')
  44. ui.button('Add label', on_click=lambda: ui.label('Click!'))
  45. ui.timer(1.0, lambda: ui.label('Tick!'), once=True)
  46. doc.intro(card_documentation)
  47. doc.intro(column_documentation)
  48. doc.intro(row_documentation)
  49. doc.intro(grid_documentation)
  50. doc.intro(list_documentation)
  51. doc.intro(fullscreen_documentation)
  52. @doc.demo('Clear Containers', '''
  53. To remove all elements from a row, column or card container, use can call
  54. ```py
  55. container.clear()
  56. ```
  57. Alternatively, you can remove individual elements by calling
  58. - `container.remove(element: Element)`,
  59. - `container.remove(index: int)`, or
  60. - `element.delete()`.
  61. ''')
  62. def clear_containers_demo():
  63. container = ui.row()
  64. def add_face():
  65. with container:
  66. ui.icon('face')
  67. add_face()
  68. ui.button('Add', on_click=add_face)
  69. ui.button('Remove', on_click=lambda: container.remove(0) if list(container) else None)
  70. ui.button('Clear', on_click=container.clear)
  71. doc.intro(teleport_documentation)
  72. doc.intro(expansion_documentation)
  73. doc.intro(scroll_area_documentation)
  74. doc.intro(separator_documentation)
  75. doc.intro(space_documentation)
  76. doc.intro(skeleton_documentation)
  77. doc.intro(splitter_documentation)
  78. doc.intro(tabs_documentation)
  79. doc.intro(stepper_documentation)
  80. doc.intro(timeline_documentation)
  81. doc.intro(carousel_documentation)
  82. doc.intro(pagination_documentation)
  83. doc.intro(menu_documentation)
  84. doc.intro(context_menu_documentation)
  85. doc.intro(tooltip_documentation)
  86. doc.intro(notify_documentation)
  87. doc.intro(notification_documentation)
  88. doc.intro(dialog_documentation)