feat: properly animate tab groups

This commit is contained in:
alphafetus committed 2026-01-30 10:10:41 -05:00
1 parent 3f1745a589
commit dfd1594395
1 file changed
+17 -22
+17 -22
View File
@@ -1,6 +1,4 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos_animate::animate;
use leptos_animate::animations::classes::{In, Out};
use leptos_router::components::{Outlet, A}; use leptos_router::components::{Outlet, A};
use leptos_router::hooks::use_location; use leptos_router::hooks::use_location;
use crate::common::{SubTabInfo, TabInfo}; use crate::common::{SubTabInfo, TabInfo};
@@ -89,33 +87,33 @@ fn SidebarTab(
}); });
view! { view! {
<A href=move || path.get()>
<div <div
class="p-3 transition-all font-bold" class="transition-all duration-300"
class=(["bg-transparent", "text-white"], move || !selected.get()) class=(["bg-transparent", "text-white"], move || !selected.get())
class=(["bg-white", "text-black"], move || selected.get()) class=(["bg-white", "text-black"], move || selected.get())
>
<A href=move || path.get()>
<div
class="p-3 transition-bg font-bold"
> >
{text} {text}
</div> </div>
</A> </A>
<div
class="grid transition-all ease-in-out"
style:grid-template-rows=move || if selected.get() { "1fr" } else { "0fr" }
>
<div class="overflow-hidden min-h-0">
<For <For
each=move || sub_paths.get() each=move || sub_paths.get()
key=|info| info.text.clone() key=|info| info.text.clone()
let(SubTabInfo { text, path }) let(SubTabInfo { text, path })
> >
<SidebarSubTab <SidebarSubTab text=text path=path visible=selected />
use:animate=(
In::default()
.source("h-0")
.target("h-auto")
.active("transition-all"),
Out::default()
.source("h-auto")
.target("h-0")
.active("transition-all")
)
text=text path=path visible=selected />
</For> </For>
</div>
</div>
</div>
} }
} }
@@ -130,16 +128,13 @@ fn SidebarSubTab(
}); });
view! { view! {
<div class="grid transition-all ease-in-out" <A href=move || path.get()>
style:grid-template-rows=move || if visible.get() { "1fr" } else { "0fr" }
style:opacity=move || if visible.get() { "1" } else { "0" }
>
<div <div
class="overflow-hidden p-3 pl-10 transition-all bg-white" class="p-3 pl-10 transition-all"
class=(["font-bold"], move || selected.get()) class=(["font-bold"], move || selected.get())
> >
{text} {text}
</div> </div>
</div> </A>
} }
} }