Skip to main content

yew_nav_link/active_link/
props.rs

1use std::marker::PhantomData;
2
3use yew::prelude::*;
4use yew_router::prelude::*;
5
6/// Properties for the [`crate::NavLink`] component.
7#[derive(Properties, Clone, PartialEq, Debug)]
8pub struct NavLinkProps<R: Routable + PartialEq + Clone + 'static> {
9    /// Target route for navigation.
10    pub to: R,
11
12    /// Content rendered inside the link element.
13    pub children: Children,
14
15    /// Enable partial (prefix) path matching.
16    #[prop_or(false)]
17    pub partial: bool,
18
19    /// Base CSS class applied to the link.
20    #[prop_or("nav-link")]
21    pub class: &'static str,
22
23    /// CSS class applied when the link is active.
24    #[prop_or("active")]
25    pub active_class: &'static str,
26
27    #[prop_or_default]
28    pub(crate) _marker: PhantomData<R>
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[derive(Clone, PartialEq, Debug, Routable)]
36    enum TestRoute {
37        #[at("/")]
38        Home
39    }
40
41    #[test]
42    fn props_equality() {
43        let props1: NavLinkProps<TestRoute> = NavLinkProps {
44            to:           TestRoute::Home,
45            children:     Children::default(),
46            partial:      false,
47            class:        "nav-link",
48            active_class: "active",
49            _marker:      PhantomData
50        };
51        let props2 = props1.clone();
52        assert_eq!(props1, props2);
53    }
54}