diff --git a/Cargo.toml b/Cargo.toml index b8d2d67..21b947b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,7 @@ leptos = "0.3" web-sys = { version = "0.3", features = ["ScrollToOptions", "ScrollBehavior", "CssStyleDeclaration"] } wasm-bindgen = "0.2" js-sys = "0.3" -default-struct-builder = "0.1" \ No newline at end of file +default-struct-builder = "0.1" + +[features] +docs = [] \ No newline at end of file diff --git a/docs/book/post_build.py b/docs/book/post_build.py index ce8afab..d6cc821 100644 --- a/docs/book/post_build.py +++ b/docs/book/post_build.py @@ -30,9 +30,9 @@ def build_and_copy_demo(category, md_name): dirs_exist_ok=True) with open(os.path.join(target_path, "index.html"), "r") as f: - html = f.read().replace("./demo", f"./{name}/demo") - head = html.split("
")[1].split("")[0] - body = html.split("")[1].split("")[0] + html = f.read().replace("/demo", f"./{name}/demo") + demo_head = html.split("")[1].split("")[0] + demo_body = html.split("")[1].split("")[0] book_html_path = os.path.join("book", category, f"{name}.html") with open(book_html_path, "r") as f: @@ -46,11 +46,11 @@ def build_and_copy_demo(category, md_name): f.write( f"""{head_split[0]} - {head} + {demo_head} {target_head} - {body} + {demo_body} {target_body} {body_split[1]}""") diff --git a/docs/book/src/custom.css b/docs/book/src/custom.css index a400dc7..78faaf9 100644 --- a/docs/book/src/custom.css +++ b/docs/book/src/custom.css @@ -1,5 +1,20 @@ +:root { + --brand-color: #EF3939; + --brand-color-dark: #9c2525; + --background-color: #ffffff; + --text-color: #856464; + --devider-light-color: #bbb; +} + .light { --fg: #333; + --links: #c42f2f; + --sidebar-active: var(--links); +} + +.coal { + --links: #ee6f6f; + --sidebar-active: var(--links); } pre > code { diff --git a/docs/book/src/demo.css b/docs/book/src/demo.css index a0d77f5..7adf66a 100644 --- a/docs/book/src/demo.css +++ b/docs/book/src/demo.css @@ -1,8 +1,3 @@ -:root { - --brand-color: #EF3939; - --brand-color-dark: #9c2525; -} - .demo-container { position: relative; } @@ -29,6 +24,8 @@ .ayu .demo-container, .navy .demo-container, .coal .demo-container { background-color: #1d1f21; + --background-color: #1d1f21; + --text-color: #aaaaaa; } .demo-container button { @@ -63,4 +60,17 @@ .demo-container .note { opacity: 0.7; font-size: 1.4rem; +} + +.demo-container input[type="text"], .demo-container input[type="search"], .demo-container input[type="number"] { + display: block; + font-size: 90%; + padding: .5em 1em .4em; + border: 1px solid var(--divider-light-color); + border-radius: 4px; + outline: none; + background: var(--background-color); + color: var(--text-color); + min-width: 20rem; + margin: .5rem 0; } \ No newline at end of file diff --git a/examples/use_debounce_fn/Cargo.toml b/examples/use_debounce_fn/Cargo.toml index df49a7a..21f7aa5 100644 --- a/examples/use_debounce_fn/Cargo.toml +++ b/examples/use_debounce_fn/Cargo.toml @@ -8,7 +8,7 @@ leptos = "0.3" console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../.." } +leptos-use = { path = "../..", features = ["docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_debounce_fn/Trunk.toml b/examples/use_debounce_fn/Trunk.toml index f521021..3e4be08 100644 --- a/examples/use_debounce_fn/Trunk.toml +++ b/examples/use_debounce_fn/Trunk.toml @@ -1,2 +1,2 @@ [build] -public_url = "./demo/" \ No newline at end of file +public_url = "/demo/" \ No newline at end of file diff --git a/examples/use_debounce_fn/src/main.rs b/examples/use_debounce_fn/src/main.rs index 6801092..9416a02 100644 --- a/examples/use_debounce_fn/src/main.rs +++ b/examples/use_debounce_fn/src/main.rs @@ -1,6 +1,6 @@ use leptos::*; -use leptos_use::use_debounce_fn_with_options; -use leptos_use::utils::{demo_or_body, DebounceOptions}; +use leptos_use::docs::demo_or_body; +use leptos_use::{use_debounce_fn_with_options, DebounceOptions}; #[component] fn Demo(cx: Scope) -> impl IntoView { @@ -10,9 +10,7 @@ fn Demo(cx: Scope) -> impl IntoView { let debounced_fn = use_debounce_fn_with_options( move || set_debounced_count(debounced_count() + 1), 1000.0, - DebounceOptions { - max_wait: Some(5000.0), - }, + DebounceOptions::default().max_wait(Some(5000.0)), ); view! { cx, diff --git a/examples/use_scroll/Cargo.toml b/examples/use_scroll/Cargo.toml index 4defd6f..07cf122 100644 --- a/examples/use_scroll/Cargo.toml +++ b/examples/use_scroll/Cargo.toml @@ -8,7 +8,7 @@ leptos = "0.3" console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../.." } +leptos-use = { path = "../..", features = ["docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_scroll/README.md b/examples/use_scroll/README.md index c2cc20d..4fb813a 100644 --- a/examples/use_scroll/README.md +++ b/examples/use_scroll/README.md @@ -5,7 +5,7 @@ as well as the nightly toolchain for Rust and the wasm32-unknown-unknown target: ```bash cargo install trunk -npm install -D tailwindcss +npm install -D tailwindcss @tailwindcss/forms rustup toolchain install nightly rustup target add wasm32-unknown-unknown ``` diff --git a/examples/use_scroll/Trunk.toml b/examples/use_scroll/Trunk.toml index f521021..3e4be08 100644 --- a/examples/use_scroll/Trunk.toml +++ b/examples/use_scroll/Trunk.toml @@ -1,2 +1,2 @@ [build] -public_url = "./demo/" \ No newline at end of file +public_url = "/demo/" \ No newline at end of file diff --git a/examples/use_scroll/src/main.rs b/examples/use_scroll/src/main.rs index ab63782..60d4131 100644 --- a/examples/use_scroll/src/main.rs +++ b/examples/use_scroll/src/main.rs @@ -1,10 +1,143 @@ use leptos::*; -use leptos_use::utils::demo_or_body; +use leptos_use::docs::{demo_or_body, BooleanDisplay}; +use leptos_use::{use_scroll_with_options, ScrollBehavior, UseScrollOptions, UseScrollReturn}; #[component] fn Demo(cx: Scope) -> impl IntoView { - view! { cx, + let el = create_node_ref(cx); + let (smooth, set_smooth) = create_signal(cx, false); + let behavior = Signal::derive(cx, move || { + if smooth() { + ScrollBehavior::Smooth + } else { + ScrollBehavior::Auto + } + }); + let UseScrollReturn { + x, + y, + set_x, + set_y, + is_scrolling, + arrived_state, + directions, + .. + } = use_scroll_with_options(cx, el, UseScrollOptions::default().behavior(behavior)); + + view! { cx, +