material_yew/top_app_bar/
navigation_icon.rs

1use yew::prelude::*;
2
3const SLOT: &str = "navigationIcon";
4
5/// Props for [`MatTopAppBarNavigationIcon`]
6#[derive(Properties, PartialEq, Clone)]
7pub struct TopAppBarNavigationIconProps {
8    pub children: Children,
9}
10
11/// Defines header for [`MatTopAppBar`][crate::MatTopAppBar] or
12/// [`MatTopAppBarFixed`][crate::MatTopAppBarFixed].
13///
14/// If the child passed is an element (a `VTag`), then it is modified to include
15/// the appropriate attributes. Otherwise, the child is wrapped in a `span`
16/// containing said attributes.
17pub struct MatTopAppBarNavigationIcon {}
18
19impl Component for MatTopAppBarNavigationIcon {
20    type Message = ();
21    type Properties = TopAppBarNavigationIconProps;
22
23    fn create(_: &Context<Self>) -> Self {
24        Self {}
25    }
26
27    fn view(&self, ctx: &Context<Self>) -> Html {
28        let props = ctx.props();
29        let children = props
30            .children
31            .iter()
32            .map(|child| {
33                match child {
34                    Html::VTag(mut vtag) => {
35                        vtag.add_attribute("slot", SLOT);
36                        Html::VTag(vtag)
37                    }
38                    _ => {
39                        html! {
40                             <span slot={SLOT}>
41                                 {child}
42                             </span>
43                        }
44                    }
45                }
46            })
47            .collect::<Html>();
48
49        html! {
50             {children}
51        }
52    }
53}