From a11538ee5baaa42bff8c5773f8548c700244d3cc Mon Sep 17 00:00:00 2001 From: luoxiao Date: Thu, 1 Aug 2024 00:18:31 +0800 Subject: [PATCH] feat: NavItem adds icon prop --- demo/src/app.rs | 1 + demo/src/pages/components.rs | 4 +++ demo_markdown/docs/nav/mod.md | 20 ++++++++++++++ demo_markdown/src/lib.rs | 1 + thaw/src/nav/nav-drawer.css | 3 ++- thaw/src/nav/nav_item.rs | 49 ++++++++++++++++++++++++++++------- 6 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 demo_markdown/docs/nav/mod.md diff --git a/demo/src/app.rs b/demo/src/app.rs index 94783a2..e3d4c8f 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -84,6 +84,7 @@ fn TheRouter(is_routing: RwSignal) -> impl IntoView { + diff --git a/demo/src/pages/components.rs b/demo/src/pages/components.rs index e7e75f9..11e51d5 100644 --- a/demo/src/pages/components.rs +++ b/demo/src/pages/components.rs @@ -226,6 +226,10 @@ pub(crate) fn gen_menu_data() -> Vec { value: "/components/message-bar".into(), label: "Message Bar".into(), }, + MenuItemOption { + value: "/components/nav".into(), + label: "Nav".into(), + }, MenuItemOption { value: "/components/popover".into(), label: "Popover".into(), diff --git a/demo_markdown/docs/nav/mod.md b/demo_markdown/docs/nav/mod.md new file mode 100644 index 0000000..08a4fa5 --- /dev/null +++ b/demo_markdown/docs/nav/mod.md @@ -0,0 +1,20 @@ +# Nav + +```rust demo + +view! { + + + "Github" + + + "Chrome" + + +} +``` \ No newline at end of file diff --git a/demo_markdown/src/lib.rs b/demo_markdown/src/lib.rs index edebaf9..dd8a5e1 100644 --- a/demo_markdown/src/lib.rs +++ b/demo_markdown/src/lib.rs @@ -53,6 +53,7 @@ pub fn include_md(_token_stream: proc_macro::TokenStream) -> proc_macro::TokenSt "LoadingBarMdPage" => "../docs/loading_bar/mod.md", "MenuMdPage" => "../docs/menu/mod.md", "MessageBarMdPage" => "../docs/message_bar/mod.md", + "NavMdPage" => "../docs/nav/mod.md", "PopoverMdPage" => "../docs/popover/mod.md", "ProgressBarMdPage" => "../docs/progress_bar/mod.md", "RadioMdPage" => "../docs/radio/mod.md", diff --git a/thaw/src/nav/nav-drawer.css b/thaw/src/nav/nav-drawer.css index fe931b8..f9ed9c5 100644 --- a/thaw/src/nav/nav-drawer.css +++ b/thaw/src/nav/nav-drawer.css @@ -44,8 +44,9 @@ position: relative; justify-content: start; gap: var(--spacingVerticalL); + width: 100%; padding: var(--spacingVerticalMNudge); - /* background-color: var(--colorNeutralBackground4); */ + background-color: inherit; border-radius: var(--borderRadiusMedium); color: var(--colorNeutralForeground2); text-decoration-line: none; diff --git a/thaw/src/nav/nav_item.rs b/thaw/src/nav/nav_item.rs index 88b1932..9319afc 100644 --- a/thaw/src/nav/nav_item.rs +++ b/thaw/src/nav/nav_item.rs @@ -1,11 +1,13 @@ -use crate::use_nav_drawer; -use leptos::prelude::*; +use crate::{use_nav_drawer, Icon}; +use leptos::{either::Either, prelude::*}; use thaw_utils::{class_list, StoredMaybeSignal}; #[component] pub fn NavItem( #[prop(optional, into)] class: MaybeProp, + #[prop(optional, into)] icon: MaybeProp, #[prop(into)] value: MaybeSignal, + #[prop(optional, into)] href: Option>, children: Children, ) -> impl IntoView { let nav_drawer = use_nav_drawer(); @@ -16,13 +18,42 @@ pub fn NavItem( nav_drawer.0.set(value); } }; - view! { - + + let children = || { + view! { + { + move || { + if let Some(icon) = icon.get() { + Either::Left(view! { + + }) + } else { + Either::Right(()) + } + } + } {children()} - + } + }; + + if let Some(href) = href { + Either::Left(view! { + + {children()} + + }) + } else { + Either::Right(view! { + + }) } }