rating_documentation.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.rating)
  4. def main_demo() -> None:
  5. ui.rating(value=4)
  6. @doc.demo('Customize icons', '''
  7. You can customize name and size of the icons.
  8. Optionally, unselected, selected or half-selected values can have different icons.
  9. ''')
  10. def customize_icons():
  11. ui.rating(
  12. value=3.5,
  13. size='lg',
  14. icon='sentiment_dissatisfied',
  15. icon_selected='sentiment_satisfied',
  16. icon_half='sentiment_neutral',
  17. )
  18. ui.rating(
  19. value=3.5,
  20. size='lg',
  21. icon='star',
  22. icon_selected='star',
  23. icon_half='star_half',
  24. )
  25. @doc.demo('Customize color', '''
  26. You can customize the color of the rating either by providing a single color or a range of different colors.
  27. ''')
  28. def rating_color():
  29. ui.rating(value=3, color='red-10')
  30. ui.rating(value=5, color=['green-2', 'green-4', 'green-6', 'green-8', 'green-10'])
  31. @doc.demo('Maximum rating', '''
  32. This demo shows how to change the maximum possible rating
  33. as well as binding the value to a slider.
  34. ''')
  35. def rating_scale():
  36. slider = ui.slider(value=5, min=0, max=10)
  37. ui.rating(max=10, icon='circle').bind_value(slider)
  38. doc.reference(ui.range)