parent
5b4367d050
commit
db9c2cc042
@ -0,0 +1,36 @@
|
|||||||
|
use lazy_static::lazy_static;
|
||||||
|
use perseus::prelude::*;
|
||||||
|
use sycamore::prelude::*;
|
||||||
|
|
||||||
|
use crate::global_state::AppStateRx;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref DARK_MODE_BTN: Capsule<PerseusNodeType, ()> = get_capsule();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dark_mode_btn<G: Html>(cx: Scope, _props: ()) -> View<G> {
|
||||||
|
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||||
|
|
||||||
|
let toggle_dark_mode = move |_| {
|
||||||
|
global_state.dark_mode.set(!*global_state.dark_mode.get());
|
||||||
|
};
|
||||||
|
|
||||||
|
view! { cx,
|
||||||
|
button (on:click=toggle_dark_mode, class="py-1 px-2 mx-1 rounded-full bg-slate-200 dark:bg-slate-800")
|
||||||
|
{ "Toggle dark mode" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fallback<G: Html>(cx: Scope, _props: ()) -> View<G> {
|
||||||
|
view! { cx,
|
||||||
|
button (class="py-1 px-2 mx-1 rounded-full bg-slate-200 dark:bg-slate-800")
|
||||||
|
{ "Toggle dark mode" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_capsule<G: Html>() -> Capsule<G, ()> {
|
||||||
|
Capsule::build(Template::build("dark_mode_btn"))
|
||||||
|
.fallback(fallback)
|
||||||
|
.view(dark_mode_btn)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
pub mod dark_mode_btn;
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue