dark_mode_documentation.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from nicegui import ui
  2. from ..windows import WINDOW_BG_COLORS
  3. from . import doc
  4. @doc.demo(ui.dark_mode)
  5. def main_demo() -> None:
  6. # dark = ui.dark_mode()
  7. # ui.label('Switch mode:')
  8. # ui.button('Dark', on_click=dark.enable)
  9. # ui.button('Light', on_click=dark.disable)
  10. # END OF DEMO
  11. label = ui.label('Switch mode:')
  12. container = label.parent_slot.parent
  13. ui.button('Dark', on_click=lambda: (
  14. label.style('color: white'),
  15. container.style(f'background-color: {WINDOW_BG_COLORS["browser"][1]}'),
  16. ))
  17. ui.button('Light', on_click=lambda: (
  18. label.style('color: black'),
  19. container.style(f'background-color: {WINDOW_BG_COLORS["browser"][0]}'),
  20. ))
  21. @doc.demo('Binding to a switch', '''
  22. The value of the `ui.dark_mode` element can be bound to other elements like a `ui.switch`.
  23. ''')
  24. def bind_to_switch() -> None:
  25. # dark = ui.dark_mode()
  26. # ui.switch('Dark mode').bind_value(dark)
  27. # END OF DEMO
  28. ui.switch('Dark mode', on_change=lambda e: (
  29. e.sender.style('color: white' if e.value else 'color: black'),
  30. e.sender.parent_slot.parent.style(f'background-color: {WINDOW_BG_COLORS["browser"][1 if e.value else 0]}'),
  31. ))
  32. doc.reference(ui.dark_mode)