From 3262d570d6df8b673674125a1748b12ceea2a620 Mon Sep 17 00:00:00 2001 From: zakstucke <44890343+zakstucke@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:05:57 +0200 Subject: [PATCH] Add support for Leptos stable (#17) * Leptos nightly --> stable * cargo fmt --- packages/leptos/Cargo.toml | 2 +- packages/leptos/src/types.rs | 12 +++++++----- packages/leptos/src/use_floating.rs | 30 ++++++++++++++--------------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/leptos/Cargo.toml b/packages/leptos/Cargo.toml index dcdcc09..dd353e3 100644 --- a/packages/leptos/Cargo.toml +++ b/packages/leptos/Cargo.toml @@ -11,7 +11,7 @@ version.workspace = true [dependencies] cfg-if = "1.0.0" floating-ui-dom = { path = "../dom", version = "0.0.8" } -leptos = { version = "0.6.9", features = ["nightly"] } +leptos = { version = "0.6.9", features = [] } paste = "1.0.0" web-sys.workspace = true diff --git a/packages/leptos/src/types.rs b/packages/leptos/src/types.rs index c489f2d..5bd5230 100644 --- a/packages/leptos/src/types.rs +++ b/packages/leptos/src/types.rs @@ -4,7 +4,7 @@ use floating_ui_dom::{ auto_update, AutoUpdateOptions, ElementOrVirtual, Middleware, MiddlewareData, Placement, Strategy, }; -use leptos::{Attribute, IntoAttribute, MaybeProp, MaybeSignal, Signal}; +use leptos::{Attribute, IntoAttribute, MaybeProp, MaybeSignal, Signal, SignalGet}; use web_sys::{Element, Window}; pub type WhileElementsMountedFn = @@ -103,7 +103,7 @@ impl UseFloatingOptions { auto_update(reference, floating, update, AutoUpdateOptions::default()) }); self.while_elements_mounted(MaybeProp::derive(move || { - if enabled() { + if enabled.get() { Some(auto_update_rc.clone()) } else { None @@ -122,7 +122,9 @@ impl UseFloatingOptions { }) }; - self.while_elements_mounted(MaybeProp::derive(move || Some(auto_update_rc(options())))) + self.while_elements_mounted(MaybeProp::derive(move || { + Some(auto_update_rc(options.get())) + })) } /// Set `while_elements_mounted` option to [`auto_update`] with `options` when `enabled` is `true`. @@ -138,8 +140,8 @@ impl UseFloatingOptions { }; self.while_elements_mounted(MaybeProp::derive(move || { - if enabled() { - Some(auto_update_rc(options())) + if enabled.get() { + Some(auto_update_rc(options.get())) } else { None } diff --git a/packages/leptos/src/use_floating.rs b/packages/leptos/src/use_floating.rs index dd0addf..04a9cd6 100644 --- a/packages/leptos/src/use_floating.rs +++ b/packages/leptos/src/use_floating.rs @@ -7,7 +7,7 @@ use floating_ui_dom::{ use leptos::{ create_effect, create_memo, create_signal, html::{AnyElement, ElementDescriptor}, - on_cleanup, watch, MaybeProp, NodeRef, SignalGet, SignalGetUntracked, + on_cleanup, watch, MaybeProp, NodeRef, SignalGet, SignalGetUntracked, SignalSet, }; use crate::{ @@ -146,7 +146,7 @@ pub fn use_floating< let (is_positioned, set_is_positioned) = create_signal(false); let floating_styles = create_memo(move |_| { let initial_styles = FloatingStyles { - position: strategy(), + position: strategy.get(), top: "0".into(), left: "0".into(), transform: None, @@ -154,8 +154,8 @@ pub fn use_floating< }; if let Some(floating_element) = floating.get_as_element() { - let x_val = round_by_dpr(&floating_element, x()); - let y_val = round_by_dpr(&floating_element, y()); + let x_val = round_by_dpr(&floating_element, x.get()); + let y_val = round_by_dpr(&floating_element, y.get()); if transform_option() { FloatingStyles { @@ -194,12 +194,12 @@ pub fn use_floating< &floating_element, Some(config), ); - set_x(position.x); - set_y(position.y); - set_strategy(position.strategy); - set_placement(position.placement); - set_middleware_data(position.middleware_data); - set_is_positioned(true); + set_x.set(position.x); + set_y.set(position.y); + set_strategy.set(position.strategy); + set_placement.set(position.placement); + set_middleware_data.set(position.middleware_data); + set_is_positioned.set(true); } } } @@ -247,7 +247,7 @@ pub fn use_floating< let reset = move || { if !open_option() { - set_is_positioned(false); + set_is_positioned.set(false); } }; @@ -288,28 +288,28 @@ pub fn use_floating< let strategy_update_rc = update_rc.clone(); let middleware_update_rc = update_rc.clone(); _ = watch( - options.placement, + move || options.placement.get(), move |_, _, _| { placement_update_rc(); }, false, ); _ = watch( - options.strategy, + move || options.strategy.get(), move |_, _, _| { strategy_update_rc(); }, false, ); _ = watch( - options.middleware, + move || options.middleware.get(), move |_, _, _| { middleware_update_rc(); }, false, ); _ = watch( - options.while_elements_mounted, + move || options.while_elements_mounted.get(), move |_, _, _| { attach_rc(); },