From d90ee993675ffe0b7aecbbb3c0b840ff745133a8 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Fri, 5 Jul 2024 16:48:41 +0800 Subject: [PATCH] feat: leptos-v0.7 --- thaw/Cargo.toml | 1 + thaw/src/accordion/accordion_item.rs | 2 +- thaw/src/anchor/anchor_link.rs | 21 ++++++++------------- thaw/src/anchor/mod.rs | 8 ++++---- thaw/src/back_top/mod.rs | 15 +++++++-------- thaw/src/button/mod.rs | 7 +++---- thaw/src/combobox/combobox_option.rs | 2 +- thaw/src/date_picker/panel/mod.rs | 6 +++--- thaw/src/dialog/dialog_surface.rs | 2 +- thaw/src/divider/mod.rs | 2 +- thaw/src/drawer/overlay_drawer.rs | 2 +- thaw/src/layout/mod.rs | 2 -- thaw/src/progress_bar/progress_bar.rs | 6 +++--- thaw/src/progress_bar/progress_circle.rs | 6 +++--- thaw/src/spin_button/mod.rs | 4 ++-- 15 files changed, 39 insertions(+), 47 deletions(-) diff --git a/thaw/Cargo.toml b/thaw/Cargo.toml index 03a522c..75b0561 100644 --- a/thaw/Cargo.toml +++ b/thaw/Cargo.toml @@ -33,6 +33,7 @@ cfg-if = "1.0.0" chrono = "0.4.35" palette = "0.7.5" num-traits = "0.2.18" +send_wrapper = "0.6" [features] csr = ["leptos/csr", "thaw_components/csr", "thaw_utils/csr"] diff --git a/thaw/src/accordion/accordion_item.rs b/thaw/src/accordion/accordion_item.rs index 4698ab5..1a74f83 100644 --- a/thaw/src/accordion/accordion_item.rs +++ b/thaw/src/accordion/accordion_item.rs @@ -59,7 +59,7 @@ pub fn AccordionItem(
{children()}
diff --git a/thaw/src/anchor/anchor_link.rs b/thaw/src/anchor/anchor_link.rs index a810624..58aee8b 100644 --- a/thaw/src/anchor/anchor_link.rs +++ b/thaw/src/anchor/anchor_link.rs @@ -1,4 +1,4 @@ -use crate::use_anchor; +use super::AnchorInjection; use leptos::{html, prelude::*}; use thaw_components::OptionComp; use thaw_utils::{class_list, OptionalProp, StoredMaybeSignal}; @@ -10,7 +10,7 @@ pub fn AnchorLink( #[prop(into)] href: String, #[prop(optional)] children: Option, ) -> impl IntoView { - let anchor = use_anchor(); + let anchor = AnchorInjection::use_(); let title: StoredMaybeSignal<_> = title.into(); let title_ref = NodeRef::::new(); @@ -39,20 +39,15 @@ pub fn AnchorLink( }); }); - Effect::new(|_| { + Effect::new(move |_| { let Some(title_el) = title_ref.get() else { return; }; - let _ = watch( - move || is_active.get(), - move |is_active, _, _| { - if *is_active { - let title_rect = title_el.get_bounding_client_rect(); - anchor.update_background_position(title_rect); - } - }, - true, - ); + + if is_active.get() { + let title_rect = title_el.get_bounding_client_rect(); + anchor.update_background_position(title_rect); + } }); } } diff --git a/thaw/src/anchor/mod.rs b/thaw/src/anchor/mod.rs index 6b183b0..b072839 100644 --- a/thaw/src/anchor/mod.rs +++ b/thaw/src/anchor/mod.rs @@ -121,6 +121,10 @@ pub(crate) struct AnchorInjection { impl Copy for AnchorInjection {} impl AnchorInjection { + pub fn use_() -> Self { + expect_context() + } + fn new( anchor_ref: NodeRef, bar_ref: NodeRef, @@ -170,10 +174,6 @@ impl AnchorInjection { } } -pub(crate) fn use_anchor() -> AnchorInjection { - expect_context() -} - struct LinkInfo { top: f64, id: String, diff --git a/thaw/src/back_top/mod.rs b/thaw/src/back_top/mod.rs index 7ea89eb..f9c3392 100644 --- a/thaw/src/back_top/mod.rs +++ b/thaw/src/back_top/mod.rs @@ -21,13 +21,12 @@ pub fn BackTop( let is_show_back_top = RwSignal::new(false); let scroll_top = RwSignal::new(0); - let _ = watch( - move || scroll_top.get(), - move |scroll_top, _, _| { - is_show_back_top.set(scroll_top > &visibility_height.get()); - }, - false, - ); + Effect::new(move |prev| { + scroll_top.track(); + if prev.is_some() { + is_show_back_top.set(scroll_top.get() > visibility_height.get_untracked()); + } + }); let scroll_to_top = StoredValue::new(None::>); let scroll_handle = StoredValue::new(None::); @@ -42,7 +41,7 @@ pub fn BackTop( .unwrap_or_else(|| document().document_element().unwrap()); { - let scroll_el = scroll_el.clone(); + let scroll_el = send_wrapper::SendWrapper::new(scroll_el.clone()); scroll_to_top.set_value(Some(Callback::new(move |_| { scroll_el.scroll_to_with_scroll_to_options( web_sys::ScrollToOptions::new() diff --git a/thaw/src/button/mod.rs b/thaw/src/button/mod.rs index 0cde01f..a50ac48 100644 --- a/thaw/src/button/mod.rs +++ b/thaw/src/button/mod.rs @@ -4,6 +4,7 @@ pub use button_group::ButtonGroup; use crate::icon::Icon; use leptos::{ev, prelude::*}; +use send_wrapper::SendWrapper; use thaw_components::OptionComp; use thaw_utils::{class_list, mount_style, OptionalMaybeSignal, OptionalProp}; @@ -65,7 +66,6 @@ impl ButtonSize { #[component] pub fn Button( - #[prop(optional, into)] style: Option>, #[prop(optional, into)] class: OptionalProp>, #[prop(optional, into)] appearance: MaybeSignal, #[prop(optional, into)] shape: MaybeSignal, @@ -74,7 +74,7 @@ pub fn Button( #[prop(optional, into)] icon: OptionalMaybeSignal, #[prop(optional, into)] disabled: MaybeSignal, #[prop(optional, into)] disabled_focusable: MaybeSignal, - #[prop(optional, into)] on_click: Option>, + #[prop(optional, into)] on_click: Option>>, #[prop(optional)] children: Option, ) -> impl IntoView { mount_style("button", include_str!("./button.css")); @@ -91,7 +91,7 @@ pub fn Button( let Some(callback) = on_click.as_ref() else { return; }; - callback.call(e); + callback.call(SendWrapper::new(e)); }; view! { @@ -107,7 +107,6 @@ pub fn Button( class.map(| c | move || c.get()) ] - style=move || style.as_ref().map(|s| s.get()) disabled=move || disabled.get().then_some("") aria-disabled=move || disabled_focusable.get().then_some("true") on:click=on_click diff --git a/thaw/src/combobox/combobox_option.rs b/thaw/src/combobox/combobox_option.rs index b670f6b..25861ce 100644 --- a/thaw/src/combobox/combobox_option.rs +++ b/thaw/src/combobox/combobox_option.rs @@ -23,7 +23,7 @@ pub fn ComboboxOption( view! {
{ view! { - } + }.into_any() } PanelVariant::Month => { - view! { } + view! { }.into_any() } PanelVariant::Year => { - view! { } + view! { }.into_any() } } }} diff --git a/thaw/src/dialog/dialog_surface.rs b/thaw/src/dialog/dialog_surface.rs index 2775d22..3f7e2ce 100644 --- a/thaw/src/dialog/dialog_surface.rs +++ b/thaw/src/dialog/dialog_surface.rs @@ -19,7 +19,7 @@ pub fn DialogSurface(children: Children) -> impl IntoView { class="thaw-dialog-surface" node_ref=surface_ref role="dialog" - aria-modal="true" + // aria-modal="true" style:display=move || display.get().map(|_| "none") > {children()} diff --git a/thaw/src/divider/mod.rs b/thaw/src/divider/mod.rs index 7104479..925a888 100644 --- a/thaw/src/divider/mod.rs +++ b/thaw/src/divider/mod.rs @@ -13,7 +13,7 @@ pub fn Divider( view! { diff --git a/thaw/src/layout/mod.rs b/thaw/src/layout/mod.rs index d76cf59..1d2043e 100644 --- a/thaw/src/layout/mod.rs +++ b/thaw/src/layout/mod.rs @@ -27,7 +27,6 @@ impl LayoutPosition { #[component] pub fn Layout( #[prop(optional, into)] class: OptionalProp>, - #[prop(optional, into)] style: OptionalProp>, #[prop(optional, into)] content_class: OptionalProp>, #[prop(optional, into)] content_style: OptionalProp>, #[prop(optional)] position: LayoutPosition, @@ -46,7 +45,6 @@ pub fn Layout( view! {
diff --git a/thaw/src/progress_bar/progress_circle.rs b/thaw/src/progress_bar/progress_circle.rs index d78b55e..62464d5 100644 --- a/thaw/src/progress_bar/progress_circle.rs +++ b/thaw/src/progress_bar/progress_circle.rs @@ -42,9 +42,9 @@ pub fn ProgressCircle(
diff --git a/thaw/src/spin_button/mod.rs b/thaw/src/spin_button/mod.rs index 2f98e09..050fbc2 100644 --- a/thaw/src/spin_button/mod.rs +++ b/thaw/src/spin_button/mod.rs @@ -2,7 +2,7 @@ use leptos::prelude::*; use num_traits::Bounded; use std::ops::{Add, Sub}; use std::str::FromStr; -use thaw_utils::{mount_style, Model, StoredMaybeSignal}; +use thaw_utils::{mount_style, with, Model, StoredMaybeSignal}; #[component] pub fn SpinButton( @@ -60,7 +60,7 @@ where