use crate::core::EventTargetMaybeSignal; use crate::use_event_listener; use leptos::*; // pub fn use_scroll( // cx: Scope, // element: El, // options: UseScrollOptions, // ) -> UseScrollReturn // where // (Scope, El): Into>, // T: Into + Clone + 'static, // { // } /// Options for [`use_scroll`]. #[derive(Default)] pub struct UseScrollOptions { /// Throttle time in milliseconds for the scroll events. Defaults to 0 (disabled). pub throttle: u32, /// After scrolling ends we wait idle + throttle milliseconds before we consider scrolling to have stopped. /// Defaults to 200. pub idle: u32, /// Threshold in pixels when we consider a side to have arrived (`UseScrollReturn::arrived_state`). pub offset: ScrollOffset, /// Callback when scrolling is happening. pub on_scroll: Option>, /// Callback when scrolling stops (after `idle` + `throttle` milliseconds have passed). pub on_stop: Option>, /// Options passed to the `addEventListener("scroll", ...)` call pub event_listener_options: Option, /// When changing the `x` or `y` signals this specifies the scroll behaviour. /// Can be `Auto` (= not smooth) or `Smooth`. Defaults to `Auto`. pub behavior: ScrollBehavior, } #[derive(Default)] pub enum ScrollBehavior { #[default] Auto, Smooth, } pub struct UseScrollReturn where Fx: FnMut(f64), Fy: FnMut(f64), { pub x: Signal, pub set_x: Fx, pub y: Signal, pub set_y: Fy, pub is_scrolling: Signal, pub arrived_state: Signal, pub directions: Signal, } #[derive(Copy, Clone)] pub struct Directions { pub left: bool, pub right: bool, pub top: bool, pub bottom: bool, } #[derive(Default)] pub struct ScrollOffset { pub left: f64, pub top: f64, pub right: f64, pub bottom: f64, }