mirror of
https://github.com/Nutomic/ibis.git
synced 2024-12-23 23:11:24 +00:00
Persistent storage for dark mode
This commit is contained in:
parent
684f4d07a7
commit
2fd3999341
4 changed files with 28 additions and 3 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -1796,6 +1796,7 @@ dependencies = [
|
|||
"leptos",
|
||||
"leptos-use",
|
||||
"leptos_axum",
|
||||
"leptos_darkmode",
|
||||
"leptos_meta",
|
||||
"leptos_router",
|
||||
"log",
|
||||
|
@ -2069,6 +2070,16 @@ dependencies = [
|
|||
"typed-builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "leptos_darkmode"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35ec7c7c56b312da0a739680cc2cb70d641eb82adbc1f83a565c2e9562a96253"
|
||||
dependencies = [
|
||||
"leptos",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "leptos_dom"
|
||||
version = "0.6.15"
|
||||
|
|
|
@ -108,6 +108,7 @@ markdown-it-footnote = "0.2.0"
|
|||
markdown-it-sub = "1.0.0"
|
||||
markdown-it-sup = "1.0.0"
|
||||
leptos-use = "0.13.6"
|
||||
leptos_darkmode = "0.2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1.4.1"
|
||||
|
|
|
@ -37,6 +37,7 @@ use leptos::{
|
|||
SignalGetUntracked,
|
||||
SignalUpdate,
|
||||
};
|
||||
use leptos_darkmode::Darkmode;
|
||||
use leptos_meta::{provide_meta_context, *};
|
||||
use leptos_router::{Route, Router, Routes};
|
||||
use reqwest::Client;
|
||||
|
@ -90,8 +91,18 @@ pub fn App() -> impl IntoView {
|
|||
GlobalState::update_my_profile();
|
||||
provide_context(create_rw_signal(global_state));
|
||||
|
||||
let darkmode = Darkmode::init();
|
||||
provide_context(darkmode.clone());
|
||||
let theme = move || {
|
||||
if darkmode.is_light() {
|
||||
"emerald"
|
||||
} else {
|
||||
"dim"
|
||||
}
|
||||
};
|
||||
|
||||
view! {
|
||||
<Html attr:data-theme="emerald" class="h-full" />
|
||||
<Html attr:data-theme=theme class="h-full" />
|
||||
<Body class="min-h-full flex max-sm:flex-col md:divide-x divide-slate-400 divide-solid" />
|
||||
<>
|
||||
<Stylesheet id="ibis" href="/pkg/ibis.css" />
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::frontend::app::GlobalState;
|
||||
use leptos::{component, use_context, view, IntoView, RwSignal, SignalWith, *};
|
||||
use leptos_darkmode::Darkmode;
|
||||
use leptos_router::*;
|
||||
|
||||
#[component]
|
||||
|
@ -124,8 +125,9 @@ pub fn Nav() -> impl IntoView {
|
|||
<span class="label-text">Light</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
value="dim"
|
||||
class="toggle theme-controller select-none"
|
||||
class="toggle"
|
||||
checked=move || { expect_context::<Darkmode>().is_dark() }
|
||||
on:click=move |_| { expect_context::<Darkmode>().toggle() }
|
||||
/>
|
||||
<span class="label-text">Dark</span>
|
||||
</label>
|
||||
|
|
Loading…
Reference in a new issue