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
use super::{CardBody, CardBodyProperties, CardDivider};
use crate::prelude::{ChildrenProperties, Raw};
use std::rc::Rc;
use yew::virtual_dom::VComp;
use yew::{prelude::*, virtual_dom::VChild};

#[derive(PartialEq, Clone)]
pub struct CardBodyVariant {
    props: CardBodyChild,
}

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

impl From<CardBodyVariant> for Html {
    fn from(value: CardBodyVariant) -> Self {
        match value.props {
            CardBodyChild::Body(props) => VComp::new::<CardBody>(props, None).into(),
            CardBodyChild::Divider(props) => VComp::new::<CardDivider>(props, None).into(),
            CardBodyChild::Raw(props) => VComp::new::<Raw>(props, None).into(),
        }
    }
}

/// Child for an [`AppLauncher`]
#[derive(Clone, PartialEq)]
pub enum CardBodyChild {
    Body(Rc<<CardBody as BaseComponent>::Properties>),
    Divider(Rc<<CardDivider as BaseComponent>::Properties>),
    Raw(Rc<<Raw as BaseComponent>::Properties>),
}

impl From<CardBodyProperties> for CardBodyChild {
    fn from(props: CardBodyProperties) -> Self {
        CardBodyChild::Body(Rc::new(props))
    }
}

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

impl From<ChildrenProperties> for CardBodyChild {
    fn from(props: ChildrenProperties) -> Self {
        CardBodyChild::Raw(Rc::new(props))
    }
}