query_documentation.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from nicegui import context, ui
  2. from ...model import UiElementDocumentation
  3. class QueryDocumentation(UiElementDocumentation, element=ui.query):
  4. def main_demo(self) -> None:
  5. def set_background(color: str) -> None:
  6. ui.query('body').style(f'background-color: {color}')
  7. # ui.button('Blue', on_click=lambda: set_background('#ddeeff'))
  8. # ui.button('Orange', on_click=lambda: set_background('#ffeedd'))
  9. # END OF DEMO
  10. ui.button('Blue', on_click=lambda e: e.sender.parent_slot.parent.style('background-color: #ddeeff'))
  11. ui.button('Orange', on_click=lambda e: e.sender.parent_slot.parent.style('background-color: #ffeedd'))
  12. def more(self) -> None:
  13. @self.demo('Set background gradient', '''
  14. It's easy to set a background gradient, image or similar.
  15. See [w3schools.com](https://www.w3schools.com/cssref/pr_background-image.php) for more information about setting background with CSS.
  16. ''')
  17. def background_image():
  18. # ui.query('body').classes('bg-gradient-to-t from-blue-400 to-blue-100')
  19. # END OF DEMO
  20. context.get_slot_stack()[-1].parent.classes('bg-gradient-to-t from-blue-400 to-blue-100')
  21. @self.demo('Modify default page padding', '''
  22. By default, NiceGUI provides a built-in padding around the content of the page.
  23. You can modify it using the class selector `.nicegui-content`.
  24. ''')
  25. def remove_padding():
  26. # ui.query('.nicegui-content').classes('p-0')
  27. context.get_slot_stack()[-1].parent.classes(remove='p-4') # HIDE
  28. # with ui.column().classes('h-screen w-full bg-gray-400 justify-between'):
  29. with ui.column().classes('h-full w-full bg-gray-400 justify-between'): # HIDE
  30. ui.label('top left')
  31. ui.label('bottom right').classes('self-end')