list_documentation.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.list)
  4. def main_demo() -> None:
  5. with ui.list().props('dense separator'):
  6. with ui.item():
  7. with ui.item_section():
  8. ui.item_label('3 Apples')
  9. with ui.item():
  10. with ui.item_section():
  11. ui.item_label('5 Bananas')
  12. with ui.item():
  13. with ui.item_section():
  14. ui.item_label('8 Strawberries')
  15. with ui.item():
  16. with ui.item_section():
  17. ui.item_label('13 Walnuts')
  18. @doc.demo('Use List Items and List Sections to Structure Content', '''
  19. Items use item sections to structure their content. Item labels take different positions depending on their props.
  20. ''')
  21. def contact_list():
  22. with ui.list().props('bordered separator'):
  23. ui.item_label('Contacts').props('header').classes('text-bold')
  24. ui.separator()
  25. with ui.item(on_click=lambda: contact.set_text('Selected contact 1')):
  26. with ui.item_section().props('avatar'):
  27. ui.icon('person')
  28. with ui.item_section():
  29. ui.item_label('Nice Guy')
  30. ui.item_label('name').props('caption')
  31. with ui.item_section().props('side'):
  32. ui.icon('chat')
  33. with ui.item(on_click=lambda: contact.set_text('Selected contact 2')):
  34. with ui.item_section().props('avatar'):
  35. ui.icon('person')
  36. with ui.item_section():
  37. ui.item_label('Nice Person')
  38. ui.item_label('name').props('caption')
  39. with ui.item_section().props('side'):
  40. ui.icon('chat')
  41. contact = ui.label()
  42. doc.reference(ui.list)