slide_item_documentation.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.slide_item)
  4. def main_demo() -> None:
  5. with ui.list().props('bordered separator'):
  6. with ui.slide_item('Slide me left or right') as slide_item_1:
  7. slide_item_1.left('Left', color='green')
  8. slide_item_1.right('Right', color='red')
  9. with ui.slide_item('Slide me up or down') as slide_item_2:
  10. slide_item_2.top('Top', color='blue')
  11. slide_item_2.bottom('Bottom', color='purple')
  12. @doc.demo('More complex layout', '''
  13. You can fill the slide item and its action slots with custom UI elements.
  14. ''')
  15. def complex_demo():
  16. with ui.list().props('bordered'):
  17. with ui.slide_item() as slide_item:
  18. with ui.item():
  19. with ui.item_section().props('avatar'):
  20. ui.icon('person')
  21. with ui.item_section():
  22. ui.item_label('Alice A. Anderson')
  23. ui.item_label('CEO').props('caption')
  24. with slide_item.left(on_slide=lambda: ui.notify('Calling...')):
  25. with ui.item(on_click=slide_item.reset):
  26. with ui.item_section().props('avatar'):
  27. ui.icon('phone')
  28. ui.item_section('Call')
  29. with slide_item.right(on_slide=lambda: ui.notify('Texting...')):
  30. with ui.item(on_click=slide_item.reset):
  31. ui.item_section('Text')
  32. with ui.item_section().props('avatar'):
  33. ui.icon('message')
  34. @doc.demo('Slide handlers', '''
  35. An event handler can be triggered when a specific side is selected.
  36. ''')
  37. def slide_callbacks():
  38. with ui.list().props('bordered'):
  39. with ui.slide_item('Slide me', on_slide=lambda e: ui.notify(f'Slide: {e.side}')) as slide_item:
  40. slide_item.left('A', on_slide=lambda e: ui.notify(f'A ({e.side})'))
  41. slide_item.right('B', on_slide=lambda e: ui.notify(f'B ({e.side})'))
  42. @doc.demo('Resetting the slide item', '''
  43. After a slide action has occurred, the slide item can be reset back to its initial state using the ``reset`` method.
  44. ''')
  45. def slide_reset():
  46. with ui.list().props('bordered'):
  47. with ui.slide_item() as slide_item:
  48. ui.item('Slide me')
  49. with slide_item.left(color='blue'):
  50. ui.item('Left')
  51. with slide_item.right(color='purple'):
  52. ui.item('Right')
  53. ui.button('Reset', on_click=slide_item.reset)