chip_documentation.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.chip)
  4. def main_demo() -> None:
  5. with ui.row().classes('gap-1'):
  6. ui.chip('Click me', icon='ads_click', on_click=lambda: ui.notify('Clicked'))
  7. ui.chip('Selectable', selectable=True, icon='bookmark', color='orange')
  8. ui.chip('Removable', removable=True, icon='label', color='indigo-3')
  9. ui.chip('Styled', icon='star', color='green').props('outline square')
  10. ui.chip('Disabled', icon='block', color='red').set_enabled(False)
  11. @doc.demo('Dynamic chip elements as labels/tags', '''
  12. This demo shows how to implement a dynamic list of chips as labels or tags.
  13. You can add new chips by typing a label and pressing Enter or pressing the plus button.
  14. Removed chips still exist, but their value is set to `False`.
  15. ''')
  16. def labels():
  17. def add_chip():
  18. with chips:
  19. ui.chip(label_input.value, icon='label', color='silver', removable=True)
  20. label_input.value = ''
  21. label_input = ui.input('Add label').on('keydown.enter', add_chip)
  22. with label_input.add_slot('append'):
  23. ui.button(icon='add', on_click=add_chip).props('round dense flat')
  24. with ui.row().classes('gap-0') as chips:
  25. ui.chip('Label 1', icon='label', color='silver', removable=True)
  26. ui.button('Restore removed chips', icon='unarchive',
  27. on_click=lambda: [chip.set_value(True) for chip in chips]) \
  28. .props('flat')
  29. doc.reference(ui.chip)