dioxus_tw_components/components/molecules/callout/
props.rs

1use super::CalloutVariant;
2use crate::attributes::*;
3use crate::prelude::*;
4use dioxus::prelude::*;
5use dioxus_tw_components_macro::UiComp;
6
7#[derive(Clone, PartialEq, Props, UiComp)]
8pub struct CalloutProps {
9    #[props(extends = div, extends = GlobalAttributes)]
10    attributes: Vec<Attribute>,
11
12    title: std::string::String,
13
14    #[props(optional, default)]
15    pub variant: ReadOnlySignal<CalloutVariant>,
16    #[props(optional, default)]
17    pub icon: Option<Icons>,
18
19    children: Element,
20}
21
22impl std::default::Default for CalloutProps {
23    fn default() -> Self {
24        Self {
25            attributes: Vec::<Attribute>::default(),
26            title: std::string::String::default(),
27            variant: ReadOnlySignal::<CalloutVariant>::default(),
28            icon: None,
29            children: rsx! {},
30        }
31    }
32}
33
34#[component]
35pub fn Callout(mut props: CalloutProps) -> Element {
36    props.update_class_attribute();
37
38    let icon = match *props.variant.read() {
39        CalloutVariant::Note => Icons::Info,
40        CalloutVariant::Tip => Icons::Lightbulb,
41        CalloutVariant::Warning => Icons::Warning,
42        CalloutVariant::Caution => Icons::Report,
43    };
44
45    rsx! {
46        div {..props.attributes,
47            div { class: "text-md flex flex-row align-middle",
48                Icon {
49                    class: "mr-2",
50                    size: Size::Sm,
51                    icon: if props.icon.is_some() { props.icon.unwrap() } else { icon },
52                }
53                "{props.title}"
54            }
55            div { class: "text-sm text-foreground/70", {props.children} }
56        }
57    }
58}