feat: update leptos

This commit is contained in:
luoxiao 2024-08-07 23:40:50 +08:00
parent 1c243922bd
commit 42bf8058dc
6 changed files with 15 additions and 21 deletions

View file

@ -16,6 +16,6 @@ thaw_components = { version = "0.2.0-alpha", path = "./thaw_components" }
thaw_macro = { version = "0.1.0-alpha", path = "./thaw_macro" } thaw_macro = { version = "0.1.0-alpha", path = "./thaw_macro" }
thaw_utils = { version = "0.1.0-alpha", path = "./thaw_utils" } thaw_utils = { version = "0.1.0-alpha", path = "./thaw_utils" }
leptos = { git = "https://github.com/leptos-rs/leptos", rev = "3dbedfc8710add4bc9a94fe27fa000fb180f393b" } leptos = { git = "https://github.com/leptos-rs/leptos", rev = "867036559489e86c1f25cdf7133d803d88b0579b" }
leptos_meta = { git = "https://github.com/leptos-rs/leptos", rev = "3dbedfc8710add4bc9a94fe27fa000fb180f393b" } leptos_meta = { git = "https://github.com/leptos-rs/leptos", rev = "867036559489e86c1f25cdf7133d803d88b0579b" }
leptos_router = { git = "https://github.com/leptos-rs/leptos", rev = "3dbedfc8710add4bc9a94fe27fa000fb180f393b" } leptos_router = { git = "https://github.com/leptos-rs/leptos", rev = "867036559489e86c1f25cdf7133d803d88b0579b" }

View file

@ -10,11 +10,14 @@ use thaw_utils::{
pub fn BackTop( pub fn BackTop(
#[prop(optional, into)] class: MaybeProp<String>, #[prop(optional, into)] class: MaybeProp<String>,
/// The width of BackTop from the right side of the page. /// The width of BackTop from the right side of the page.
#[prop(default=40.into(), into)] right: MaybeSignal<i32>, #[prop(default=40.into(), into)]
right: MaybeSignal<i32>,
/// The height of BackTop from the bottom of the page. /// The height of BackTop from the bottom of the page.
#[prop(default=40.into(), into)] bottom: MaybeSignal<i32>, #[prop(default=40.into(), into)]
bottom: MaybeSignal<i32>,
/// BackTop's trigger scroll top. /// BackTop's trigger scroll top.
#[prop(default=180.into(), into)] visibility_height: MaybeSignal<i32>, #[prop(default=180.into(), into)]
visibility_height: MaybeSignal<i32>,
#[prop(optional)] children: Option<Children>, #[prop(optional)] children: Option<Children>,
) -> impl IntoView { ) -> impl IntoView {
mount_style("back-top", include_str!("./back-top.css")); mount_style("back-top", include_str!("./back-top.css"));
@ -24,7 +27,7 @@ pub fn BackTop(
let is_show_back_top = RwSignal::new(false); let is_show_back_top = RwSignal::new(false);
let scroll_top = RwSignal::new(0); let scroll_top = RwSignal::new(0);
Effect::new(move |prev| { Effect::new(move |prev: Option<()>| {
scroll_top.track(); scroll_top.track();
if prev.is_some() { if prev.is_some() {
is_show_back_top.set(scroll_top.get() > visibility_height.get_untracked()); is_show_back_top.set(scroll_top.get() > visibility_height.get_untracked());

View file

@ -66,7 +66,7 @@ pub fn ColorPicker(
style style
}); });
Effect::new(move |prev| { Effect::new(move |prev: Option<()>| {
let (s, v) = sv.get(); let (s, v) = sv.get();
let hue_value = hue.get(); let hue_value = hue.get();
if prev.is_none() { if prev.is_none() {

View file

@ -30,7 +30,7 @@ pub fn FocusTrap(
STACK.with_borrow_mut(|stack| stack.retain(|value| id.with_value(|id| id != value))); STACK.with_borrow_mut(|stack| stack.retain(|value| id.with_value(|id| id != value)));
}; };
Effect::new(move |prev| { Effect::new(move |prev: Option<bool>| {
let is_active = active.get(); let is_active = active.get();
if is_active && !prev.unwrap_or(false) { if is_active && !prev.unwrap_or(false) {
let on_esc = on_esc.clone(); let on_esc = on_esc.clone();

View file

@ -1,15 +1,12 @@
use std::cell::Cell;
// use cfg_if::cfg_if;
use leptos::prelude::*; use leptos::prelude::*;
use std::cell::Cell;
/// https://github.com/solidjs/solid/blob/main/packages/solid/web/src/index.ts#L56
#[component] #[component]
pub fn Teleport( pub fn Teleport(
#[prop(default = true.into(), into)] immediate: MaybeSignal<bool>, #[prop(default = true.into(), into)] immediate: MaybeSignal<bool>,
#[prop(into, optional)] mount: Option<web_sys::Element>, #[prop(into, optional)] mount: Option<web_sys::Element>,
children: Children, children: Children,
) -> impl IntoView { ) -> impl IntoView {
// cfg_if! { if #[cfg(all(target_arch = "wasm32", any(feature = "csr", feature = "hydrate")))] {
let mount_fn: Cell<Option<Box<dyn FnOnce() -> ()>>> = Cell::new(Some(Box::new(move || { let mount_fn: Cell<Option<Box<dyn FnOnce() -> ()>>> = Cell::new(Some(Box::new(move || {
let mount = if let Some(el) = mount.as_ref() { let mount = if let Some(el) = mount.as_ref() {
el el
@ -36,7 +33,7 @@ pub fn Teleport(
}); });
}))); })));
let owner = Owner::current().unwrap(); let owner = Owner::new();
Effect::new(move |_| { Effect::new(move |_| {
if immediate.get() { if immediate.get() {
let Some(f) = mount_fn.take() else { let Some(f) = mount_fn.take() else {
@ -48,10 +45,4 @@ pub fn Teleport(
}); });
} }
}); });
// } else {
// let _ = mount;
// let _ = immediate;
// let _ = element;
// let _ = children;
// }}
} }

View file

@ -39,7 +39,7 @@ where
fn watch(&self, f: impl Fn(&Self::Value) + 'static) -> Box<dyn FnOnce()> { fn watch(&self, f: impl Fn(&Self::Value) + 'static) -> Box<dyn FnOnce()> {
let signal = *self; let signal = *self;
let effect = Effect::new(move |prev| { let effect = Effect::new(move |prev: Option<()>| {
signal.with(|value| { signal.with(|value| {
if prev.is_some() { if prev.is_some() {
untrack(|| f(value)); untrack(|| f(value));