scroll_area_documentation.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from nicegui import ui
  2. from ...model import UiElementDocumentation
  3. class ScrollAreaDocumentation(UiElementDocumentation, element=ui.scroll_area):
  4. def main_demo(self) -> None:
  5. with ui.row():
  6. with ui.scroll_area().classes('w-32 h-32 border'):
  7. ui.label('I scroll. ' * 20)
  8. with ui.column().classes('p-4 w-32 h-32 border'):
  9. ui.label('I will not scroll. ' * 10)
  10. def more(self) -> None:
  11. @self.demo('Handling Scroll Events', '''
  12. You can use the `on_scroll` argument in `ui.scroll_area` to handle scroll events.
  13. The callback receives a `ScrollEventArguments` object with the following attributes:
  14. - `sender`: the scroll area that generated the event
  15. - `client`: the matching client
  16. - additional arguments as described in [Quasar's documentation for the ScrollArea API](https://quasar.dev/vue-components/scroll-area/#qscrollarea-api)
  17. ''')
  18. def scroll_events():
  19. position = ui.number('scroll position:').props('readonly')
  20. with ui.card().classes('w-32 h-32'):
  21. with ui.scroll_area(on_scroll=lambda e: position.set_value(e.vertical_percentage)):
  22. ui.label('I scroll. ' * 20)
  23. @self.demo('Setting the scroll position', '''
  24. You can use `scroll_to` to programmatically set the scroll position.
  25. This can be useful for navigation or synchronization of multiple scroll areas.
  26. ''')
  27. def scroll_position():
  28. ui.number('position', value=0, min=0, max=1, step=0.1,
  29. on_change=lambda e: area1.scroll_to(percent=e.value)).classes('w-32')
  30. with ui.row():
  31. with ui.card().classes('w-32 h-48'):
  32. with ui.scroll_area(on_scroll=lambda e: area2.scroll_to(percent=e.vertical_percentage)) as area1:
  33. ui.label('I scroll. ' * 20)
  34. with ui.card().classes('w-32 h-48'):
  35. with ui.scroll_area() as area2:
  36. ui.label('I scroll. ' * 20)