feat: nav slot

This commit is contained in:
luoxiao 2024-05-11 17:47:33 +08:00
parent 6d42248e76
commit d45f7b908e
3 changed files with 44 additions and 4 deletions

View file

@ -58,13 +58,22 @@ pub fn ComponentsPage() -> impl IntoView {
<Layout position=LayoutPosition::Absolute> <Layout position=LayoutPosition::Absolute>
<SiteHeader/> <SiteHeader/>
<Layout has_sider=true position=LayoutPosition::Absolute style="top: 64px;"> <Layout has_sider=true position=LayoutPosition::Absolute style="top: 64px;">
<LayoutSider class="demo-components__sider"> <div class="demo-components__sider">
<NavDrawer selected_value=select_name> <NavDrawer selected_value=select_name>
{gen_menu_data().into_view()} {gen_menu_data().into_view()}
<NavDrawerFooter slot>
<Button
appearance=ButtonAppearance::Subtle
icon=icondata::AiGithubOutlined
style="font-size: 22px; padding: 0px 6px;"
on_click=move |_| {
_ = window().open_with_url("http://github.com/thaw-ui/thaw");
}
/>
</NavDrawerFooter>
</NavDrawer> </NavDrawer>
</LayoutSider> </div>
<Layout content_style="padding: 8px 12px 28px; display: flex;" class="doc-content"> <Layout content_style="padding: 8px 12px 28px; display: flex;" class="doc-content">
<Outlet/> <Outlet/>
</Layout> </Layout>

View file

@ -23,6 +23,15 @@
/* overflow: auto; */ /* overflow: auto; */
} }
.thaw-nav-drawer__footer {
width: 100%;
max-width: 100%;
padding: 0 var(--spacingVerticalMNudge);
box-sizing: border-box;
position: relative;
z-index: 2;
}
.thaw-nav-item { .thaw-nav-item {
display: flex; display: flex;
text-transform: none; text-transform: none;

View file

@ -1,24 +1,46 @@
use leptos::*; use leptos::*;
use thaw_components::OptionComp;
use thaw_utils::{mount_style, Model}; use thaw_utils::{mount_style, Model};
use crate::Scrollbar;
#[component] #[component]
pub fn NavDrawer( pub fn NavDrawer(
#[prop(optional, into)] selected_value: Model<String>, #[prop(optional, into)] selected_value: Model<String>,
children: Children, children: Children,
#[prop(optional)] nav_drawer_header: Option<NavDrawerHeader>,
#[prop(optional)] nav_drawer_footer: Option<NavDrawerFooter>,
) -> impl IntoView { ) -> impl IntoView {
mount_style("nav-drawer", include_str!("./nav-drawer.css")); mount_style("nav-drawer", include_str!("./nav-drawer.css"));
view! { view! {
<Provider value=NavDrawerInjection(selected_value)> <Provider value=NavDrawerInjection(selected_value)>
<div class="thaw-nav-drawer"> <div class="thaw-nav-drawer">
<OptionComp value=nav_drawer_header let:header>
<header class="thaw-nav-drawer__header">{(header.children)()}</header>
</OptionComp>
<div class="thaw-nav-drawer__body"> <div class="thaw-nav-drawer__body">
<Scrollbar>
{children()} {children()}
</Scrollbar>
</div> </div>
<OptionComp value=nav_drawer_footer let:footer>
<footer class="thaw-nav-drawer__footer">{(footer.children)()}</footer>
</OptionComp>
</div> </div>
</Provider> </Provider>
} }
} }
#[slot]
pub struct NavDrawerHeader {
children: Children,
}
#[slot]
pub struct NavDrawerFooter {
children: Children,
}
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct NavDrawerInjection(pub Model<String>); pub(crate) struct NavDrawerInjection(pub Model<String>);