fix: Icon attr

This commit is contained in:
luoxiao 2024-07-10 17:26:00 +08:00
parent f33c012364
commit 8b122d0986
13 changed files with 36 additions and 39 deletions

View file

@ -50,7 +50,7 @@ fn TheRouter(is_routing: RwSignal<bool>) -> impl IntoView {
<Route path=(StaticSegment("development"), StaticSegment("components")) view=DevelopmentComponentsMdPage/> <Route path=(StaticSegment("development"), StaticSegment("components")) view=DevelopmentComponentsMdPage/>
</ParentRoute> </ParentRoute>
<ParentRoute path=StaticSegment("components") view=ComponentsPage> <ParentRoute path=StaticSegment("components") view=ComponentsPage>
// // <Route path="/tabbar" view=TabbarPage/> // // <Route path="/tabbar" view=TabbarPage/>
// // <Route path="/nav-bar" view=NavBarPage/> // // <Route path="/nav-bar" view=NavBarPage/>
// // <Route path="/toast" view=ToastPage/> // // <Route path="/toast" view=ToastPage/>

View file

@ -24,9 +24,7 @@ pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option<Children>) -
} else { } else {
css_vars.push_str("--demo-color: #00000060;"); css_vars.push_str("--demo-color: #00000060;");
css_vars.push_str("--demo-color-hover: #000000e0;"); css_vars.push_str("--demo-color-hover: #000000e0;");
css_vars.push_str(&format!( css_vars.push_str(&format!("--demo-border-color: var(--colorNeutralStroke2);",));
"--demo-border-color: var(--colorNeutralStroke2);",
));
css_vars.push_str("--demo-background-color: #f9fafb;"); css_vars.push_str("--demo-background-color: #f9fafb;");
} }
}); });

View file

@ -1,5 +1,5 @@
use crate::AccordionInjection; use crate::AccordionInjection;
use leptos::{prelude::*, html}; use leptos::{html, prelude::*};
use thaw_components::CSSTransition; use thaw_components::CSSTransition;
use thaw_utils::{mount_style, update, with, StoredMaybeSignal}; use thaw_utils::{mount_style, update, with, StoredMaybeSignal};

View file

@ -7,4 +7,4 @@ pub fn DialogBody(children: Children) -> impl IntoView {
{children()} {children()}
</div> </div>
} }
} }

View file

@ -7,4 +7,4 @@ pub fn DialogContent(children: Children) -> impl IntoView {
{children()} {children()}
</h2> </h2>
} }
} }

View file

@ -7,4 +7,4 @@ pub fn DialogTitle(children: Children) -> impl IntoView {
{children()} {children()}
</h2> </h2>
} }
} }

View file

@ -7,4 +7,4 @@ pub fn DrawerHeader(children: Children) -> impl IntoView {
{children()} {children()}
</header> </header>
} }
} }

View file

@ -83,7 +83,7 @@ pub fn Icon(
let svg = view! { let svg = view! {
<svg <svg
class=class_list!["thaw-icon", class.map(|c| move || c.get())] class=class_list!["thaw-icon", class.map(|c| move || c.get())]
style=move || take_signal(icon_style) style=move || take_signal(icon_style).unwrap_or_default()
x=move || take(icon_x) x=move || take(icon_x)
y=move || take(icon_y) y=move || take(icon_y)
width=move || take_signal(icon_width) width=move || take_signal(icon_width)
@ -102,18 +102,15 @@ pub fn Icon(
svg.inner_html(move || take(icon_data)) svg.inner_html(move || take(icon_data))
} }
fn take_signal(signal: RwSignal<Option<MaybeSignal<String>>>) -> String { fn take_signal(signal: RwSignal<Option<MaybeSignal<String>>>) -> Option<String> {
signal.with(|s| match s { signal.with(|s| match s {
Some(MaybeSignal::Static(value)) => value.clone(), Some(MaybeSignal::Static(value)) => Some(value.clone()),
Some(MaybeSignal::Dynamic(signal)) => signal.get(), Some(MaybeSignal::Dynamic(signal)) => Some(signal.get()),
_ => String::new(), _ => None,
}) })
} }
fn take(signal: RwSignal<Option<String>>) -> String { fn take(signal: RwSignal<Option<String>>) -> Option<String> {
signal.track(); signal.track();
signal signal.try_update_untracked(|value| value.take()).flatten()
.try_update_untracked(|value| value.take())
.flatten()
.unwrap_or_default()
} }

View file

@ -107,8 +107,8 @@ impl SpaceJustify {
mod test { mod test {
#[test] #[test]
fn main() { fn main() {
use leptos::prelude::*;
use super::Space; use super::Space;
use leptos::prelude::*;
view! { view! {
<Space> <Space>
@ -117,4 +117,4 @@ mod test {
</Space> </Space>
}; };
} }
} }

View file

@ -14,7 +14,7 @@ pub fn Toaster(
Effect::new(move |_| { Effect::new(move |_| {
for view in receiver.try_recv() { for view in receiver.try_recv() {
// toast_list.update(move |list| { // toast_list.update(move |list| {
// list.push(view.0); // list.push(view.0);
// }); // });
} }
}); });

View file

@ -1,6 +1,5 @@
use std::cell::Cell; use std::cell::Cell;
// use cfg_if::cfg_if;
use cfg_if::cfg_if;
use leptos::prelude::*; use leptos::prelude::*;
/// https://github.com/solidjs/solid/blob/main/packages/solid/web/src/index.ts#L56 /// https://github.com/solidjs/solid/blob/main/packages/solid/web/src/index.ts#L56

View file

@ -1,12 +1,10 @@
use leptos::{ use leptos::{
logging::debug_warn, logging::debug_warn,
reactive_graph::{ reactive_graph::{
effect::RenderEffect,
signal::RwSignal, signal::RwSignal,
traits::{Get, GetUntracked, Update}, traits::{Get, GetUntracked, Update},
}, },
}; };
use std::cell::Cell;
pub struct ComponentRef<T: 'static>(RwSignal<Option<T>>); pub struct ComponentRef<T: 'static>(RwSignal<Option<T>>);
@ -58,17 +56,17 @@ impl<T> ComponentRef<T> {
}); });
} }
pub fn on_load<F>(self, f: F) // pub fn on_load<F>(self, f: F)
where // where
T: Clone, // T: Clone,
F: FnOnce(T) + 'static, // F: FnOnce(T) + 'static,
{ // {
let f = Cell::new(Some(f)); // let f = Cell::new(Some(f));
RenderEffect::new(move |_| { // RenderEffect::new(move |_| {
if let Some(comp) = self.get() { // if let Some(comp) = self.get() {
f.take().unwrap()(comp); // f.take().unwrap()(comp);
} // }
}); // });
} // }
} }

View file

@ -1,4 +1,9 @@
use leptos::reactive_graph::{effect::Effect, signal::RwSignal, traits::{Dispose, With}, untrack}; use leptos::reactive_graph::{
effect::Effect,
signal::RwSignal,
traits::{Dispose, With},
untrack,
};
pub trait SignalWatch { pub trait SignalWatch {
type Value; type Value;