stepper_documentation.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.stepper)
  4. def main_demo() -> None:
  5. with ui.stepper().props('vertical').classes('w-full') as stepper:
  6. with ui.step('Preheat'):
  7. ui.label('Preheat the oven to 350 degrees')
  8. with ui.stepper_navigation():
  9. ui.button('Next', on_click=stepper.next)
  10. with ui.step('Ingredients'):
  11. ui.label('Mix the ingredients')
  12. with ui.stepper_navigation():
  13. ui.button('Next', on_click=stepper.next)
  14. ui.button('Back', on_click=stepper.previous).props('flat')
  15. with ui.step('Bake'):
  16. ui.label('Bake for 20 minutes')
  17. with ui.stepper_navigation():
  18. ui.button('Done', on_click=lambda: ui.notify('Yay!', type='positive'))
  19. ui.button('Back', on_click=stepper.previous).props('flat')
  20. @doc.demo('Dynamic Stepper', '''
  21. Steps can be added dynamically and positioned via `ui.move()`.
  22. ''')
  23. def dynamic_stepper() -> None:
  24. def next_step() -> None:
  25. if extra_step.value and len(stepper.default_slot.children) == 2:
  26. with stepper:
  27. with ui.step('extra') as extra:
  28. ui.label('Extra')
  29. with ui.stepper_navigation():
  30. ui.button('Back', on_click=stepper.previous).props('flat')
  31. ui.button('Next', on_click=stepper.next)
  32. extra.move(target_index=1)
  33. stepper.next()
  34. with ui.stepper().props('vertical').classes('w-full') as stepper:
  35. with ui.step('start'):
  36. ui.label('Start')
  37. extra_step = ui.checkbox('do extra step')
  38. with ui.stepper_navigation():
  39. ui.button('Next', on_click=next_step)
  40. with ui.step('finish'):
  41. ui.label('Finish')
  42. with ui.stepper_navigation():
  43. ui.button('Back', on_click=stepper.previous).props('flat')
  44. doc.reference(ui.stepper)