Skip to main content

yew_nav_link/active_link/
props.rs

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