dioxus_element_plug/components/
backtop.rs1use dioxus::prelude::*;
2
3#[derive(Props, Clone, PartialEq)]
5pub struct BacktopProps {
6 #[props(default)]
7 pub children: Option<Element>,
8
9 #[props(default)]
11 pub target: Option<String>,
12
13 #[props(default = 200)]
15 pub visibility_height: u32,
16
17 #[props(default = 40)]
19 pub right: u32,
20
21 #[props(default = 40)]
23 pub bottom: u32,
24
25 #[props(default)]
26 pub on_click: Option<EventHandler<()>>,
27
28 #[props(default)]
29 pub class: Option<String>,
30}
31
32#[component]
34pub fn Backtop(props: BacktopProps) -> Element {
35 let mut class_names = vec!["el-backtop".to_string()];
36 if let Some(ref c) = props.class { class_names.push(c.clone()); }
37
38 rsx! {
39 div {
40 class: "{class_names.join(\" \")}",
41 style: "position: fixed; right: {props.right}px; bottom: {props.bottom}px; z-index: 1000; cursor: pointer;",
42 onclick: move |_| {
43 if let Some(handler) = props.on_click {
44 handler.call(());
45 }
46 },
47 if props.children.is_some() {
48 {props.children}
49 } else {
50 i { class: "el-icon-caret-top" }
51 }
52 }
53 }
54}