Skip to content

Commit

Permalink
Add support for Leptos stable (#17)
Browse files Browse the repository at this point in the history
* Leptos nightly --> stable

* cargo fmt
  • Loading branch information
zakstucke authored Jun 5, 2024
1 parent 538dd2b commit 3262d57
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/leptos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 7 additions & 5 deletions packages/leptos/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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`.
Expand All @@ -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
}
Expand Down
30 changes: 15 additions & 15 deletions packages/leptos/src/use_floating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -146,16 +146,16 @@ 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,
will_change: None,
};

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 {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn use_floating<

let reset = move || {
if !open_option() {
set_is_positioned(false);
set_is_positioned.set(false);
}
};

Expand Down Expand Up @@ -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();
},
Expand Down

0 comments on commit 3262d57

Please sign in to comment.