range_documentation.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.range)
  4. def main_demo() -> None:
  5. min_max_range = ui.range(min=0, max=100, value={'min': 20, 'max': 80})
  6. ui.label().bind_text_from(min_max_range, 'value',
  7. backward=lambda v: f'min: {v["min"]}, max: {v["max"]}')
  8. @doc.demo('Customize labels', '''
  9. You can customize the colors of the range and its labels by setting them individually or for the range in total.
  10. ''')
  11. def customize_labels():
  12. ui.label('Color the entire range')
  13. ui.range(min=0, max=100, value={'min': 20, 'max': 80}) \
  14. .props('label snap color="secondary"')
  15. ui.label('Customize the color of the labels')
  16. ui.range(min=0, max=100, value={'min': 40, 'max': 80}) \
  17. .props('label-always snap label-color="secondary" right-label-text-color="black"')
  18. @doc.demo('Change range limits', '''
  19. This demo shows how to change the limits on the click of a button.
  20. ''')
  21. def range_limits():
  22. def increase_limits():
  23. r.min -= 10
  24. r.max += 10
  25. ui.button('Increase limits', on_click=increase_limits)
  26. r = ui.range(min=0, max=100, value={'min': 30, 'max': 70}).props('label-always')
  27. doc.reference(ui.range)