2023-05-18 17:14:54 +08:00
|
|
|
use super::{use_menu, MenuInjectionKey};
|
|
|
|
use crate::{theme::use_theme, utils::mount_style::mount_style, Theme};
|
|
|
|
use leptos::*;
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn MenuItem(
|
2023-10-15 15:43:02 +08:00
|
|
|
#[prop(into)] key: MaybeSignal<String>,
|
2023-05-18 17:14:54 +08:00
|
|
|
#[prop(into)] label: MaybeSignal<String>,
|
|
|
|
) -> impl IntoView {
|
2023-10-07 21:41:03 +08:00
|
|
|
mount_style("menu-item", include_str!("./menu-item.css"));
|
2023-08-29 09:11:22 +08:00
|
|
|
let theme = use_theme(Theme::light);
|
|
|
|
let menu = use_menu();
|
2023-10-15 15:43:02 +08:00
|
|
|
let click_key = key.clone();
|
|
|
|
let on_click = move |_| {
|
|
|
|
menu.set(MenuInjectionKey::new(click_key.get()));
|
2023-05-18 17:14:54 +08:00
|
|
|
};
|
|
|
|
|
2023-08-29 09:11:22 +08:00
|
|
|
let css_vars = create_memo(move |_| {
|
2023-05-18 17:14:54 +08:00
|
|
|
let mut css_vars = String::new();
|
2023-11-02 22:01:48 +08:00
|
|
|
theme.with(|theme| {
|
|
|
|
let font_color = theme.common.color_primary.clone();
|
2023-11-05 16:03:58 +08:00
|
|
|
css_vars.push_str(&format!("--thaw-font-color-active: {font_color};"));
|
|
|
|
css_vars.push_str(&format!("--thaw-font-color: {};", theme.menu.color));
|
|
|
|
css_vars.push_str(&format!("--thaw-background-color: {font_color}1a;"));
|
2023-11-02 22:01:48 +08:00
|
|
|
css_vars.push_str(&format!(
|
2023-11-05 16:03:58 +08:00
|
|
|
"--thaw-background-color-hover: {};",
|
2023-11-02 22:01:48 +08:00
|
|
|
theme.menu.item_color_hover
|
|
|
|
));
|
|
|
|
});
|
2023-05-18 17:14:54 +08:00
|
|
|
css_vars
|
|
|
|
});
|
2023-10-07 21:41:03 +08:00
|
|
|
view! {
|
2023-11-05 16:03:58 +08:00
|
|
|
<div class="thaw-menu-item">
|
2023-10-08 09:28:13 +08:00
|
|
|
<div
|
2023-11-05 16:03:58 +08:00
|
|
|
class="thaw-menu-item__content"
|
|
|
|
class=("thaw-menu-item__content--selected", move || menu.get().value == key.get())
|
2023-10-15 15:43:02 +08:00
|
|
|
on:click=on_click
|
2023-10-08 09:28:13 +08:00
|
|
|
style=move || css_vars.get()
|
|
|
|
>
|
|
|
|
{move || label.get()}
|
2023-05-18 17:14:54 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|