MCPcopy Create free account
hub / github.com/acking-you/static_flow / tooltip

Function tooltip

crates/frontend/src/components/tooltip.rs:33–179  ·  view source on GitHub ↗
(props: &TooltipProps)

Source from the content-addressed store, hash-verified

31
32#[function_component(Tooltip)]
33pub fn tooltip(props: &TooltipProps) -> Html {
34 let TooltipProps {
35 text,
36 position,
37 children,
38 class,
39 } = props;
40
41 let visible = use_state(|| false);
42 let touch_timeout = use_mut_ref(|| None::<Timeout>);
43
44 // 桌面端:hover 显示(300ms 延迟)
45 let on_mouse_enter = {
46 let visible = visible.clone();
47 let touch_timeout = touch_timeout.clone();
48 Callback::from(move |_: MouseEvent| {
49 // 清除可能存在的触摸延迟
50 touch_timeout.borrow_mut().take();
51
52 visible.set(true);
53 })
54 };
55
56 let on_mouse_leave = {
57 let visible = visible.clone();
58 Callback::from(move |_: MouseEvent| {
59 visible.set(false);
60 })
61 };
62
63 // 移动端:长按 300ms 显示
64 let on_touch_start = {
65 let visible = visible.clone();
66 let touch_timeout = touch_timeout.clone();
67 Callback::from(move |_: TouchEvent| {
68 let visible = visible.clone();
69 let timeout = Timeout::new(300, move || {
70 visible.set(true);
71 });
72 *touch_timeout.borrow_mut() = Some(timeout);
73 })
74 };
75
76 let on_touch_end = {
77 let visible = visible.clone();
78 let touch_timeout = touch_timeout.clone();
79 Callback::from(move |_: TouchEvent| {
80 // 清除长按计时器
81 touch_timeout.borrow_mut().take();
82
83 // 隐藏 tooltip
84 visible.set(false);
85 })
86 };
87
88 let on_touch_cancel = {
89 let visible = visible.clone();
90 let touch_timeout = touch_timeout.clone();

Callers

nothing calls this directly

Calls 1

cloneMethod · 0.80

Tested by

no test coverage detected