From 74be938fbc2585b2067fafd82c400e978eb727f2 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Sun, 7 Jul 2024 22:28:11 +0800 Subject: [PATCH] feat(lepots-v0.7): demo Home page --- demo/src/app.rs | 25 +++++++++++++------------ thaw/src/button/mod.rs | 12 ++++++++---- thaw/src/layout/layout_header.rs | 10 ++-------- thaw/src/layout/layout_sider.rs | 7 ++----- thaw/src/layout/mod.rs | 7 ++----- thaw/src/scrollbar/mod.rs | 21 +++++++++++++-------- thaw_utils/src/class_list.rs | 14 ++++++-------- 7 files changed, 46 insertions(+), 50 deletions(-) diff --git a/demo/src/app.rs b/demo/src/app.rs index 1cb1ec7..cc411cd 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -30,19 +30,18 @@ pub fn App() -> impl IntoView { #[component] fn TheRouter(is_routing: RwSignal) -> impl IntoView { - let loading_bar = use_loading_bar(); - _ = is_routing.watch(move |is_routing| { - if *is_routing { - loading_bar.start(); - } else { - loading_bar.finish(); - } - }); + // let loading_bar = use_loading_bar(); + // _ = is_routing.watch(move |is_routing| { + // if *is_routing { + // loading_bar.start(); + // } else { + // loading_bar.finish(); + // } + // }); view! { - // // // @@ -114,9 +113,11 @@ fn TheProvider(children: Children) -> impl IntoView { view! { - - {children()} - + // + // + {children()} + // + // } } diff --git a/thaw/src/button/mod.rs b/thaw/src/button/mod.rs index a50ac48..e77036f 100644 --- a/thaw/src/button/mod.rs +++ b/thaw/src/button/mod.rs @@ -3,7 +3,7 @@ mod button_group; pub use button_group::ButtonGroup; use crate::icon::Icon; -use leptos::{ev, prelude::*}; +use leptos::{either::Either, ev, prelude::*}; use send_wrapper::SendWrapper; use thaw_components::OptionComp; use thaw_utils::{class_list, mount_style, OptionalMaybeSignal, OptionalProp}; @@ -122,9 +122,13 @@ pub fn Button( } } } - - {children()} - + { + if let Some(children) = children { + Either::Left(children()) + } else { + Either::Right(()) + } + } } } diff --git a/thaw/src/layout/layout_header.rs b/thaw/src/layout/layout_header.rs index 075bb3f..1c75ace 100644 --- a/thaw/src/layout/layout_header.rs +++ b/thaw/src/layout/layout_header.rs @@ -1,15 +1,9 @@ use leptos::prelude::*; -use thaw_utils::{class_list, OptionalProp}; #[component] -pub fn LayoutHeader( - #[prop(optional, into)] class: OptionalProp>, - children: Children, -) -> impl IntoView { +pub fn LayoutHeader(children: Children) -> impl IntoView { view! { -
+
{children()}
} diff --git a/thaw/src/layout/layout_sider.rs b/thaw/src/layout/layout_sider.rs index 20ebbcf..744fc11 100644 --- a/thaw/src/layout/layout_sider.rs +++ b/thaw/src/layout/layout_sider.rs @@ -1,19 +1,16 @@ use crate::Scrollbar; use leptos::prelude::*; -use thaw_utils::{class_list, mount_style, OptionalProp}; +use thaw_utils::{mount_style, OptionalProp}; #[component] pub fn LayoutSider( - #[prop(optional, into)] class: OptionalProp>, #[prop(optional, into)] content_class: OptionalProp>, #[prop(optional, into)] content_style: OptionalProp>, children: Children, ) -> impl IntoView { mount_style("layout-sider", include_str!("./layout-sider.css")); view! { -
+
{children()} diff --git a/thaw/src/layout/mod.rs b/thaw/src/layout/mod.rs index 1d2043e..c1a6ce8 100644 --- a/thaw/src/layout/mod.rs +++ b/thaw/src/layout/mod.rs @@ -6,7 +6,7 @@ pub use layout_sider::*; use crate::Scrollbar; use leptos::prelude::*; -use thaw_utils::{class_list, mount_style, OptionalProp}; +use thaw_utils::{mount_style, OptionalProp}; #[derive(Default, PartialEq)] pub enum LayoutPosition { @@ -26,7 +26,6 @@ impl LayoutPosition { #[component] pub fn Layout( - #[prop(optional, into)] class: OptionalProp>, #[prop(optional, into)] content_class: OptionalProp>, #[prop(optional, into)] content_style: OptionalProp>, #[prop(optional)] position: LayoutPosition, @@ -43,9 +42,7 @@ pub fn Layout( } }); view! { -
+
Self::State { - let class_list = R::class_list(el); let mut class = String::new(); self.to_class_string(&mut class); if !class.is_empty() { - R::add_class(&class_list, &class); + R::set_attribute(el, "class", &class); } - (class_list, class) + (el.clone(), class) } fn rebuild(self, state: &mut Self::State) { let mut class = String::new(); self.to_class_string(&mut class); - let (class_list, prev_class) = state; + let (el, prev_class) = state; if class != *prev_class { - R::remove_class(class_list, prev_class); - R::add_class(class_list, &class); + R::set_attribute(el, "class", &class); } *prev_class = class; }