소스 검색

add a demo about binding `ui.dark_mode`

Falko Schindler 2 달 전
부모
커밋
ee9e87cdac
1개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      website/documentation/content/dark_mode_documentation.py

+ 13 - 0
website/documentation/content/dark_mode_documentation.py

@@ -23,4 +23,17 @@ def main_demo() -> None:
     ))
 
 
+@doc.demo('Binding to a switch', '''
+    The value of the `ui.dark_mode` element can be bound to other elements like a `ui.switch`.
+''')
+def bind_to_switch() -> None:
+    # dark = ui.dark_mode()
+    # ui.switch('Dark mode').bind_value(dark)
+    # END OF DEMO
+    ui.switch('Dark mode', on_change=lambda e: (
+        e.sender.style('color: white' if e.value else 'color: black'),
+        e.sender.parent_slot.parent.style(f'background-color: {WINDOW_BG_COLORS["browser"][1 if e.value else 0]}'),
+    ))
+
+
 doc.reference(ui.dark_mode)