25 lines
744 B
Rust
25 lines
744 B
Rust
use yew::prelude::*;
|
|
|
|
#[function_component]
|
|
pub fn ThemeToggle() -> Html {
|
|
let onclick = {
|
|
Callback::from(|_| {
|
|
if let Some(window) = web_sys::window() {
|
|
if let Some(document) = window.document() {
|
|
if let Some(html) = document.document_element() {
|
|
let current = html.get_attribute("data-theme").unwrap_or_default();
|
|
let new_theme = if current == "dark" { "" } else { "dark" };
|
|
let _ = html.set_attribute("data-theme", new_theme);
|
|
}
|
|
}
|
|
}
|
|
})
|
|
};
|
|
|
|
html! {
|
|
<button {onclick} class="sidebar-button">
|
|
{"🌙"}
|
|
</button>
|
|
}
|
|
}
|