diff --git a/crates/components/src/animated_router.rs b/crates/components/src/animated_router.rs index 553838fbe..8f4dd5c0b 100644 --- a/crates/components/src/animated_router.rs +++ b/crates/components/src/animated_router.rs @@ -6,11 +6,14 @@ use dioxus_router::prelude::{ #[derive(Clone)] pub enum AnimatedRouterContext { + /// Transition from one route to another. FromTo(R, R), + /// Settled in a route. In(R), } impl AnimatedRouterContext { + /// Get the current destination route. pub fn target_route(&self) -> &R { match self { Self::FromTo(_, to) => to, @@ -18,6 +21,7 @@ impl AnimatedRouterContext { } } + /// Update the destination route. pub fn set_target_route(&mut self, to: R) { match self { Self::FromTo(old_from, old_to) => { @@ -28,6 +32,7 @@ impl AnimatedRouterContext { } } + /// After the transition animation has finished, make the outlet only render the destination route. pub fn settle(&mut self) { if let Self::FromTo(_, to) = self { *self = Self::In(to.clone()) @@ -40,6 +45,9 @@ pub struct AnimatedRouterProps { children: Element, } +/// Provide a mechanism for outlets to animate between route transitions. +/// +/// See the `animated_sidebar.rs` or `animated_tabs.rs` for an example on how to use it. #[allow(non_snake_case)] pub fn AnimatedRouter( AnimatedRouterProps { children }: AnimatedRouterProps, @@ -55,6 +63,7 @@ pub fn AnimatedRouter( rsx!({ children }) } +/// Shortcut to get access to the [AnimatedRouterContext]. pub fn use_animated_router() -> Signal> { use_context() }