Skip to content

Commit

Permalink
doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jun 29, 2024
1 parent e5c6792 commit 89d9d27
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/components/src/animated_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ use dioxus_router::prelude::{

#[derive(Clone)]
pub enum AnimatedRouterContext<R: Routable + PartialEq> {
/// Transition from one route to another.
FromTo(R, R),
/// Settled in a route.
In(R),
}

impl<R: Routable + PartialEq> AnimatedRouterContext<R> {
/// Get the current destination route.
pub fn target_route(&self) -> &R {
match self {
Self::FromTo(_, to) => to,
Self::In(to) => to,
}
}

/// Update the destination route.
pub fn set_target_route(&mut self, to: R) {
match self {
Self::FromTo(old_from, old_to) => {
Expand All @@ -28,6 +32,7 @@ impl<R: Routable + PartialEq> AnimatedRouterContext<R> {
}
}

/// 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())
Expand All @@ -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<R: Routable + PartialEq + Clone>(
AnimatedRouterProps { children }: AnimatedRouterProps,
Expand All @@ -55,6 +63,7 @@ pub fn AnimatedRouter<R: Routable + PartialEq + Clone>(
rsx!({ children })
}

/// Shortcut to get access to the [AnimatedRouterContext].
pub fn use_animated_router<Route: Routable + PartialEq>() -> Signal<AnimatedRouterContext<Route>> {
use_context()
}

0 comments on commit 89d9d27

Please sign in to comment.