patternfly_yew/components/breadcrumb/
router.rs

1use super::variant::BreadcrumbChild;
2use std::rc::Rc;
3use yew::{prelude::*, virtual_dom::VComp};
4use yew_nested_router::{components::Link, prelude::*};
5
6/// Properties for [`BreadcrumbRouterItem`]
7#[derive(Clone, Debug, PartialEq, Properties)]
8pub struct BreadcrumbRouterItemProperties<T: Target> {
9    pub to: T,
10    #[prop_or_default]
11    pub children: Html,
12    #[prop_or_default]
13    current: bool,
14}
15
16impl<T: Target> From<BreadcrumbRouterItemProperties<T>> for BreadcrumbChild {
17    fn from(props: BreadcrumbRouterItemProperties<T>) -> Self {
18        Self {
19            creator: Rc::new(props),
20        }
21    }
22}
23
24impl<T: Target> super::variant::BreadcrumbItemCreator for BreadcrumbRouterItemProperties<T> {
25    fn create(mut self: Rc<Self>, current: bool) -> Html {
26        let props = Rc::make_mut(&mut self);
27        props.current = current;
28        VComp::new::<BreadcrumbRouterItem<T>>(self, None).into()
29    }
30}
31
32/// A breadcrumb item component based on [`yew_nested_router`].
33#[function_component(BreadcrumbRouterItem)]
34pub fn breadcrumb_router_item<T: Target>(props: &BreadcrumbRouterItemProperties<T>) -> Html {
35    let mut class = Classes::from("pf-v5-c-breadcrumb__link");
36
37    if props.current {
38        class.push("pf-m-current");
39    }
40
41    html!(
42        <Link<T>
43            {class}
44            to={props.to.clone()}
45        >
46            { props.children.clone() }
47        </Link<T>>
48    )
49}