element_documentation.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.element)
  4. def main_demo() -> None:
  5. with ui.element('div').classes('p-2 bg-blue-100'):
  6. ui.label('inside a colored div')
  7. @doc.demo('Move elements', '''
  8. This demo shows how to move elements between or within containers.
  9. ''')
  10. def move_elements() -> None:
  11. with ui.card() as a:
  12. ui.label('A')
  13. x = ui.label('X')
  14. with ui.card() as b:
  15. ui.label('B')
  16. ui.button('Move X to A', on_click=lambda: x.move(a))
  17. ui.button('Move X to B', on_click=lambda: x.move(b))
  18. ui.button('Move X to top', on_click=lambda: x.move(target_index=0))
  19. @doc.demo('Default props', '''
  20. You can set default props for all elements of a certain class.
  21. This way you can avoid repeating the same props over and over again.
  22. Default props only apply to elements created after the default props were set.
  23. Subclasses inherit the default props of their parent class.
  24. ''')
  25. def default_props() -> None:
  26. ui.button.default_props('rounded outline')
  27. ui.button('Button A')
  28. ui.button('Button B')
  29. # END OF DEMO
  30. ui.button.default_props(remove='rounded outline')
  31. @doc.demo('Default classes', '''
  32. You can set default classes for all elements of a certain class.
  33. This way you can avoid repeating the same classes over and over again.
  34. Default classes only apply to elements created after the default classes were set.
  35. Subclasses inherit the default classes of their parent class.
  36. ''')
  37. def default_classes() -> None:
  38. ui.label.default_classes('bg-blue-100 p-2')
  39. ui.label('Label A')
  40. ui.label('Label B')
  41. # END OF DEMO
  42. ui.label.default_classes(remove='bg-blue-100 p-2')
  43. @doc.demo('Default style', '''
  44. You can set a default style for all elements of a certain class.
  45. This way you can avoid repeating the same style over and over again.
  46. A default style only applies to elements created after the default style was set.
  47. Subclasses inherit the default style of their parent class.
  48. ''')
  49. def default_style() -> None:
  50. ui.label.default_style('color: tomato')
  51. ui.label('Label A')
  52. ui.label('Label B')
  53. # END OF DEMO
  54. ui.label.default_style(remove='color: tomato')
  55. doc.reference(ui.element)