1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use super::*;
use std::rc::Rc;
use yew::{
    prelude::*,
    virtual_dom::{VChild, VComp},
};

/// Child of a toolbar component
#[derive(Clone, PartialEq)]
pub enum ToolbarChild {
    Item(Rc<<ToolbarItem as BaseComponent>::Properties>),
    Divider(Rc<<ToolbarDivider as BaseComponent>::Properties>),
    Group(Rc<<ToolbarGroup as BaseComponent>::Properties>),
}

impl From<ToolbarItemProperties> for ToolbarChild {
    fn from(props: ToolbarItemProperties) -> Self {
        ToolbarChild::Item(Rc::new(props))
    }
}

impl From<ToolbarGroupProperties> for ToolbarChild {
    fn from(props: ToolbarGroupProperties) -> Self {
        ToolbarChild::Group(Rc::new(props))
    }
}

impl From<()> for ToolbarChild {
    fn from(_: ()) -> Self {
        ToolbarChild::Divider(Rc::new(()))
    }
}

#[derive(PartialEq, Clone)]
pub struct ToolbarChildVariant {
    props: ToolbarChild,
}

impl<CHILD> From<VChild<CHILD>> for ToolbarChildVariant
where
    CHILD: BaseComponent,
    CHILD::Properties: Into<ToolbarChild> + Clone,
{
    fn from(vchild: VChild<CHILD>) -> Self {
        Self {
            props: (*vchild.props).clone().into(),
        }
    }
}

impl From<ToolbarChildVariant> for Html {
    fn from(value: ToolbarChildVariant) -> Self {
        match value.props {
            ToolbarChild::Item(props) => VComp::new::<ToolbarItem>(props, None).into(),
            ToolbarChild::Group(props) => VComp::new::<ToolbarGroup>(props, None).into(),
            ToolbarChild::Divider(props) => VComp::new::<ToolbarDivider>(props, None).into(),
        }
    }
}