button_group_documentation.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. ui.item('Item 1', on_click=lambda: ui.notify('Item 1'))
  18. ui.item('Item 2', on_click=lambda: ui.notify('Item 2'))
  19. @doc.demo('Button group styling', '''
  20. You can apply the same styling options to a button group as to a button, like "flat", "outline", "push", ...
  21. However, you must always use the same design props for the button group and its containing buttons.
  22. ''')
  23. def styling() -> None:
  24. with ui.button_group().props('rounded'):
  25. ui.button('One')
  26. ui.button('Two')
  27. ui.button('Three')
  28. with ui.button_group().props('push glossy'):
  29. ui.button('One', color='red').props('push')
  30. ui.button('Two', color='orange').props('push text-color=black')
  31. ui.button('Three', color='yellow').props('push text-color=black')
  32. with ui.button_group().props('outline'):
  33. ui.button('One').props('outline')
  34. ui.button('Two').props('outline')
  35. ui.button('Three').props('outline')
  36. doc.reference(ui.button_group)