Skip to main content

dioxus_element_plug/components/
affix.rs

1use dioxus::prelude::*;
2
3/// Affix props
4#[derive(Props, Clone, PartialEq)]
5pub struct AffixProps {
6    #[props(default)]
7    pub children: Element,
8
9    /// Target container offset top
10    #[props(default = 0)]
11    pub offset: u32,
12
13    /// Affix position
14    #[props(default = "top".to_string())]
15    pub position: String,
16
17    /// Target element selector
18    #[props(default)]
19    pub target: Option<String>,
20
21    #[props(default)]
22    pub on_change: Option<EventHandler<bool>>,
23
24    #[props(default)]
25    pub class: Option<String>,
26
27    #[props(default)]
28    pub style: Option<String>,
29}
30
31/// Affix component for fixing elements on scroll
32#[component]
33pub fn Affix(props: AffixProps) -> Element {
34    let mut class_names = vec!["el-affix".to_string()];
35    if let Some(ref c) = props.class { class_names.push(c.clone()); }
36
37    rsx! {
38        div {
39            class: "{class_names.join(\" \")}",
40            style: props.style.clone().unwrap_or_default(),
41            {props.children}
42        }
43    }
44}