diff --git a/demo/gh-pages b/demo/gh-pages deleted file mode 160000 index faaa4df..0000000 --- a/demo/gh-pages +++ /dev/null @@ -1 +0,0 @@ -Subproject commit faaa4dfa5547b4c3e117999f4ed4cf2332006f2b diff --git a/demo/src/app.rs b/demo/src/app.rs index 8d5307f..521d882 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -31,8 +31,16 @@ pub fn App() -> impl IntoView { #[component] fn TheRouter() -> impl IntoView { + let loading_bar = use_loading_bar(); + let set_is_routing = SignalSetter::map(move |is_routing| { + if is_routing { + loading_bar.start(); + } else { + loading_bar.finish(); + } + }); view! { - + @@ -66,6 +74,7 @@ fn TheRouter() -> impl IntoView { + @@ -81,7 +90,9 @@ fn Provider(theme: RwSignal, children: Children) -> impl IntoView { - {children()} + + {children()} + } diff --git a/demo/src/pages/components.rs b/demo/src/pages/components.rs index ac2627a..52a2172 100644 --- a/demo/src/pages/components.rs +++ b/demo/src/pages/components.rs @@ -167,6 +167,10 @@ fn gen_menu_data() -> Vec { MenuGroupOption { label: "Navigation Components".into(), children: vec![ + MenuItemOption { + value: "loading-bar".into(), + label: "Loading Bar".into(), + }, MenuItemOption { value: "menu".into(), label: "Menu".into(), diff --git a/demo/src/pages/loading_bar/mod.rs b/demo/src/pages/loading_bar/mod.rs new file mode 100644 index 0000000..29859f0 --- /dev/null +++ b/demo/src/pages/loading_bar/mod.rs @@ -0,0 +1,62 @@ +use crate::components::{Demo, DemoCode}; +use leptos::*; +use prisms::highlight_str; +use thaw::*; + +#[component] +pub fn LoadingBarPage() -> impl IntoView { + let loading_bar = use_loading_bar(); + let start = move |_| { + loading_bar.start(); + }; + let finish = move |_| { + loading_bar.finish(); + }; + let error = move |_| { + loading_bar.error(); + }; + view! { +
+

"Loading Bar"

+ + "If you want to use loading bar, you need to wrap the component where you call related methods inside LoadingBarProvider and use use_loading_bar to get the API." + + + + + + + + + + + + + } + "#, + "rust" + ) + > + + "" + "" + + +
+ } +} diff --git a/demo/src/pages/mod.rs b/demo/src/pages/mod.rs index 8422b70..e52e8e2 100644 --- a/demo/src/pages/mod.rs +++ b/demo/src/pages/mod.rs @@ -14,6 +14,7 @@ mod icon; mod image; mod input; mod input_number; +mod loading_bar; mod menu; mod message; mod mobile; @@ -48,6 +49,7 @@ pub use icon::*; pub use image::*; pub use input::*; pub use input_number::*; +pub use loading_bar::*; pub use menu::*; pub use message::*; pub use mobile::*; diff --git a/src/loading_bar/mod.rs b/src/loading_bar/mod.rs index fd4daf0..3db30ec 100644 --- a/src/loading_bar/mod.rs +++ b/src/loading_bar/mod.rs @@ -5,7 +5,7 @@ use leptos::*; pub use loading_bar_provider::{use_loading_bar, LoadingBarProvider}; #[derive(Clone)] -pub struct LoadingBarRef { +pub(crate) struct LoadingBarRef { start: Callback<()>, finish: Callback<()>, error: Callback<()>, @@ -24,7 +24,7 @@ impl LoadingBarRef { } #[component] -pub fn LoadingBar(#[prop(optional)] comp_ref: ComponentRef) -> impl IntoView { +pub(crate) fn LoadingBar(#[prop(optional)] comp_ref: ComponentRef) -> impl IntoView { mount_style("loading-bar", include_str!("./loading-bar.css")); let theme = use_theme(Theme::light); let css_vars = create_memo(move |_| { @@ -57,15 +57,20 @@ pub fn LoadingBar(#[prop(optional)] comp_ref: ComponentRef) -> im .style("max-width", "80%"); } }); + let is_on_transitionend = store_value(false); + let on_transitionend = move |_| { + if is_on_transitionend.get_value() { + is_on_transitionend.set_value(false); + loading.set(false); + } + }; let finish = Callback::new(move |_| { if let Some(loading_bar_ref) = loading_bar_ref.get_untracked() { - let loading_bar_ref = loading_bar_ref + loading_bar_ref .style("background-color", "var(--thaw-background-color)") .style("transition", "max-width 0.5s linear") - .style("max-width", "1000%"); - loading_bar_ref.on(ev::transitionend, move |_| { - loading.set(false); - }); + .style("max-width", "100%"); + is_on_transitionend.set_value(true); } }); let error = Callback::new(move |_| { @@ -78,13 +83,11 @@ pub fn LoadingBar(#[prop(optional)] comp_ref: ComponentRef) -> im .style("max-width", "0"); _ = loading_bar_ref.offset_width(); } - let loading_bar_ref = loading_bar_ref + loading_bar_ref .style("background-color", "var(--thaw-background-color-error)") .style("transition", "max-width 0.5s linear") .style("max-width", "100%"); - loading_bar_ref.on(ev::transitionend, move |_| { - loading.set(false); - }); + is_on_transitionend.set_value(true); } }); @@ -94,9 +97,16 @@ pub fn LoadingBar(#[prop(optional)] comp_ref: ComponentRef) -> im error, }); view! { -
-
-
+
+
} }