1
0

button_group_documentation.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.button_group)
  4. def main_demo() -> None:
  5. with ui.button_group():
  6. ui.button('One', on_click=lambda: ui.notify('You clicked Button 1!'))
  7. ui.button('Two', on_click=lambda: ui.notify('You clicked Button 2!'))
  8. ui.button('Three', on_click=lambda: ui.notify('You clicked Button 3!'))
  9. @doc.demo('Button group with dropdown button', '''
  10. You can also add a dropdown button to a button group.
  11. ''')
  12. def with_dropdown() -> None:
  13. with ui.button_group():
  14. ui.button('One')
  15. ui.button('Two')
  16. with ui.dropdown_button('Dropdown'):
  17. with ui.list():
  18. with ui.item(on_click=lambda: ui.notify('Item 1')):
  19. with ui.item_section():
  20. ui.item_label('Item 1')
  21. with ui.item(on_click=lambda: ui.notify('Item 2')):
  22. with ui.item_section():
  23. ui.item_label('Item 2')
  24. @doc.demo('Button group styling', '''
  25. You can apply the same styling options to a button group as to a button, like "flat", "outline", "push", ...
  26. However, you must always use the same design props for the button group and its containing buttons.
  27. ''')
  28. def styling() -> None:
  29. with ui.button_group().props('rounded'):
  30. ui.button('One')
  31. ui.button('Two')
  32. ui.button('Three')
  33. with ui.button_group().props('push glossy'):
  34. ui.button('One', color='red').props('push')
  35. ui.button('Two', color='orange').props('push text-color=black')
  36. ui.button('Three', color='yellow').props('push text-color=black')
  37. with ui.button_group().props('outline'):
  38. ui.button('One').props('outline')
  39. ui.button('Two').props('outline')
  40. ui.button('Three').props('outline')
  41. doc.reference(ui.button_group)