daisy_rsx/
tooltip.rs

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
#![allow(non_snake_case)]
use dioxus::prelude::*;

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum ToolTipColor {
    #[default]
    Default,
    Warn,
    Info,
    Error,
    Success,
}

impl ToolTipColor {
    pub fn to_string(&self) -> &'static str {
        match self {
            ToolTipColor::Default => "tooltip tooltip-info",
            ToolTipColor::Info => "tooltip tooltip-info",
            ToolTipColor::Warn => "tooltip tooltip-warning",
            ToolTipColor::Error => "tooltip tooltip-error",
            ToolTipColor::Success => "tooltip tooltip-success",
        }
    }
}

#[derive(Props, Clone, PartialEq)]
pub struct ToolTipProps {
    text: String,
    children: Element,
    class: Option<String>,
    alert_color: Option<ToolTipColor>,
}

#[component]
pub fn ToolTip(props: ToolTipProps) -> Element {
    let alert_color = if props.alert_color.is_some() {
        props.alert_color.unwrap()
    } else {
        Default::default()
    };

    let class = if let Some(class) = props.class {
        class
    } else {
        "".to_string()
    };

    let class = format!("{} {}", alert_color.to_string(), class);

    rsx!(
        div {
            class: "{class}",
            "data-tip": props.text,
            {props.children}
        }
    )
}