use crate::core::{Direction, Directions, ElementMaybeSignal};
use crate::{
use_element_visibility, use_scroll_with_options, ScrollOffset, UseEventListenerOptions,
UseScrollOptions, UseScrollReturn,
};
use default_struct_builder::DefaultBuilder;
use futures_util::join;
use gloo_timers::future::sleep;
use leptos::*;
use std::future::Future;
use std::rc::Rc;
use std::time::Duration;
use wasm_bindgen::JsCast;
/// Infinite scrolling of the element.
///
/// ## Demo
///
/// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/main/examples/use_infinite_scroll)
///
/// ## Usage
///
/// ```
/// # use leptos::*;
/// use leptos::html::Div;
/// # use leptos_use::{use_infinite_scroll_with_options, UseInfiniteScrollOptions};
/// #
/// # #[component]
/// # fn Demo() -> impl IntoView {
/// let el = create_node_ref::
();
///
/// let (data, set_data) = create_signal(vec![1, 2, 3, 4, 5, 6]);
///
/// let _ = use_infinite_scroll_with_options(
/// el,
/// move |_| async move {
/// let len = data.with(|d| d.len());
/// set_data.update(|data| *data = (1..len+6).collect());
/// },
/// UseInfiniteScrollOptions::default().distance(10.0),
/// );
///
/// view! {
///
/// { item }
///
/// }
/// # }
/// ```
///
/// The returned signal is `true` while new data is being loaded.
pub fn use_infinite_scroll
(el: El, on_load_more: LFn) -> Signal
where
El: Into> + Clone + 'static,
T: Into + Clone + 'static,
LFn: Fn(ScrollState) -> LFut + 'static,
LFut: Future