dioxus_element_plug/components/
tooltip.rs1use dioxus::prelude::*;
2
3#[derive(Clone, PartialEq)]
5pub enum TooltipPlacement {
6 Top, TopStart, TopEnd,
7 Bottom, BottomStart, BottomEnd,
8 Left, LeftStart, LeftEnd,
9 Right, RightStart, RightEnd,
10}
11
12impl TooltipPlacement {
13 pub fn as_str(&self) -> &'static str {
14 match self {
15 TooltipPlacement::Top => "top",
16 TooltipPlacement::TopStart => "top-start",
17 TooltipPlacement::TopEnd => "top-end",
18 TooltipPlacement::Bottom => "bottom",
19 TooltipPlacement::BottomStart => "bottom-start",
20 TooltipPlacement::BottomEnd => "bottom-end",
21 TooltipPlacement::Left => "left",
22 TooltipPlacement::LeftStart => "left-start",
23 TooltipPlacement::LeftEnd => "left-end",
24 TooltipPlacement::Right => "right",
25 TooltipPlacement::RightStart => "right-start",
26 TooltipPlacement::RightEnd => "right-end",
27 }
28 }
29}
30
31#[derive(Props, Clone, PartialEq)]
33pub struct TooltipProps {
34 #[props(default)]
35 pub children: Element,
36
37 pub content: String,
39
40 #[props(default = TooltipPlacement::Top)]
42 pub placement: TooltipPlacement,
43
44 #[props(default = "dark".to_string())]
46 pub effect: String,
47
48 #[props(default = false)]
50 pub disabled: bool,
51
52 #[props(default = false)]
54 pub visible: bool,
55
56 #[props(default = 0)]
58 pub show_delay: u32,
59
60 #[props(default = 0)]
62 pub hide_delay: u32,
63
64 #[props(default)]
65 pub class: Option<String>,
66
67 #[props(default)]
68 pub style: Option<String>,
69}
70
71#[component]
73pub fn Tooltip(props: TooltipProps) -> Element {
74 if props.disabled {
75 return rsx! { {props.children} };
76 }
77
78 rsx! {
79 span {
80 class: "el-tooltip__trigger",
81 style: "display: inline-block; position: relative;",
82 {props.children}
83 if props.visible {
84 span {
85 class: "el-tooltip__popper is-{props.effect}",
86 style: "position: absolute; z-index: 3000; transform: translateX(-50%); top: -100%; left: 50%;",
87 span { class: "el-tooltip__content", "{props.content}" }
88 }
89 }
90 }
91 }
92}