mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-30 08:00:21 +00:00
44 lines
942 B
Rust
44 lines
942 B
Rust
#![allow(non_snake_case)]
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
fn main() {
|
|
dioxus_desktop::launch(App);
|
|
}
|
|
|
|
struct DarkMode(bool);
|
|
|
|
#[rustfmt::skip]
|
|
pub fn App(cx: Scope) -> Element {
|
|
use_shared_state_provider(cx, || DarkMode(false));
|
|
|
|
render!(
|
|
DarkModeToggle {},
|
|
AppBody {}
|
|
)
|
|
}
|
|
|
|
pub fn DarkModeToggle(cx: Scope) -> Element {
|
|
let dark_mode = use_shared_state::<DarkMode>(cx).unwrap();
|
|
|
|
render!(input {
|
|
r#type: "checkbox",
|
|
oninput: move |event| {
|
|
let is_enabled = event.value == "true";
|
|
dark_mode.write().0 = is_enabled;
|
|
},
|
|
})
|
|
}
|
|
|
|
fn AppBody(cx: Scope) -> Element {
|
|
let dark_mode = use_shared_state::<DarkMode>(cx).unwrap();
|
|
|
|
let is_dark_mode = dark_mode.read().0;
|
|
let answer = if is_dark_mode { "Yes" } else { "No" };
|
|
|
|
render!(
|
|
p {
|
|
"Is Dark mode enabled? {answer}"
|
|
}
|
|
)
|
|
}
|