diff --git a/examples/basic/src/pages/slider/mod.rs b/examples/basic/src/pages/slider/mod.rs index 006bfa5..8155abb 100644 --- a/examples/basic/src/pages/slider/mod.rs +++ b/examples/basic/src/pages/slider/mod.rs @@ -3,11 +3,9 @@ use melt_ui::*; #[component] pub fn SliderPage(cx: Scope) -> impl IntoView { - let (value, set_value) = create_signal(cx, 0.0); - let on_value = SignalSetter::map(cx, move |value| { - set_value.set(value); - }); + let value = create_rw_signal(cx, 0.0); + view! { cx, - + } } diff --git a/src/mobile/nav_bar/mod.rs b/src/mobile/nav_bar/mod.rs index 2d081d4..f6a6f42 100644 --- a/src/mobile/nav_bar/mod.rs +++ b/src/mobile/nav_bar/mod.rs @@ -1,4 +1,4 @@ -use crate::utils::mount_style::mount_style; +use crate::{utils::mount_style::mount_style, components::*}; use leptos::*; use leptos_icons::*; use stylers::style_sheet_str; @@ -7,11 +7,11 @@ use web_sys::MouseEvent; #[component] pub fn NavBar( cx: Scope, - #[prop(optional, into)] title: MaybeSignal, + #[prop(optional, into)] title: MaybeSignal<&'static str>, #[prop(optional, into)] left_arrow: MaybeSignal, - #[prop(optional, into)] left_text: MaybeSignal, + #[prop(optional, into)] left_text: MaybeSignal<&'static str>, #[prop(optional, into)] click_left: Option>, - #[prop(optional, into)] right_text: MaybeSignal, + #[prop(optional, into)] right_text: MaybeSignal<&'static str>, #[prop(optional, into)] click_right: Option>, ) -> impl IntoView { @@ -30,47 +30,28 @@ pub fn NavBar( view! { cx, class=class_name,
- { - move || { - let left_text = left_text.get(); - if left_arrow.get() || !left_text.is_empty() { - view! { cx, class=class_name, -
- { - if left_arrow.get() { - view! { cx, - - }.into() - } else { - None - } - } - { left_text } -
- }.into() - } else { - None - } - } - } + + +
+ + + + + + { left_text.get() } +
+
+
{ move || title.get() }
- { - move || { - let right_text = right_text.get(); - if !right_text.is_empty() { - view! { cx, class=class_name, -
- { right_text } -
- }.into() - } else { - None - } - } - } - + + +
+ { right_text.get() } +
+
+
} } \ No newline at end of file diff --git a/src/progress/mod.rs b/src/progress/mod.rs index 5145449..90611fc 100644 --- a/src/progress/mod.rs +++ b/src/progress/mod.rs @@ -1,12 +1,12 @@ -use crate::utils::mount_style::mount_style; +use crate::{utils::mount_style::mount_style, components::*}; use leptos::*; use stylers::style_sheet_str; #[component] pub fn Progress( cx: Scope, - #[prop(optional)] left_tip: Option>, - #[prop(optional)] right_tip: Option>, + #[prop(optional, into)] left_tip: MaybeSignal<&'static str>, + #[prop(optional, into)] right_tip: MaybeSignal<&'static str>, percentage: ReadSignal, ) -> impl IntoView { let class_name = mount_style("progress", || style_sheet_str!("./src/progress/progress.css")); @@ -15,15 +15,11 @@ pub fn Progress( cx, class=class_name,
- { - move || { - if let Some(left_tip) = left_tip { - left_tip.get() - } else { - "".into() - } - } - } + + + { left_tip.get() } + + @@ -31,15 +27,11 @@ pub fn Progress( - { - move || { - if let Some(right_tip) = right_tip { - right_tip.get() - } else { - "".into() - } - } - } + + + { right_tip.get() } + +
} diff --git a/src/slider/mod.rs b/src/slider/mod.rs index c53382a..12fa4db 100644 --- a/src/slider/mod.rs +++ b/src/slider/mod.rs @@ -10,8 +10,7 @@ use wasm_bindgen::JsCast; #[component] pub fn Slider( cx: Scope, - #[prop(optional, into)] value: MaybeSignal, - #[prop(optional)] on_value: Option>, + #[prop(into)] value: RwSignal, #[prop(default = MaybeSignal::Static(100f64), into)] max: MaybeSignal, ) -> impl IntoView { let theme = use_theme(cx, Theme::light); @@ -35,10 +34,8 @@ pub fn Slider( }); let class_name = mount_style("slider", || style_sheet_str!("./src/slider/slider.css")); - let do_update_value = move |value| { - if let Some(on_value) = on_value { - on_value.set(value); - } + let do_update_value = move |val| { + value.set(val); }; let rail_ref = create_node_ref::(cx); @@ -47,7 +44,7 @@ pub fn Slider( let on_mouse_down = move |_| { set_mouse_move.set(true); }; - + let on_mouse_up = window_event_listener(ev::mouseup, move |_| { set_mouse_move.set(false); }); diff --git a/src/teleport/mod.rs b/src/teleport/mod.rs index dc2c446..7670793 100644 --- a/src/teleport/mod.rs +++ b/src/teleport/mod.rs @@ -3,9 +3,16 @@ use web_sys::Element; /// https://github.com/solidjs/solid/blob/main/packages/solid/web/src/index.ts#L56 #[component] -pub fn Teleport(cx: Scope, #[prop(optional)] to: Option, children: Children) -> impl IntoView { +pub fn Teleport( + cx: Scope, + #[prop(optional)] to: Option<&'static str>, + children: Children, +) -> impl IntoView { let parent = if let Some(to) = to { - document().query_selector(to.as_str()).expect("element not to exist").expect("element not to exist") + document() + .query_selector(to) + .expect("element not to exist") + .expect("element not to exist") } else { Element::from(document().body().expect("body element not to exist")) }; @@ -23,6 +30,6 @@ pub fn Teleport(cx: Scope, #[prop(optional)] to: Option, children: Child _ = parent; _ = children; } - + view! { cx, <> } -} \ No newline at end of file +}