material_yew/icon_button_toggle/
off_icon.rs

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