Skip to content

Commit

Permalink
feat(LoadingIndicator): Added spinning loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
InfamousVague committed Jan 12, 2024
1 parent fe90712 commit b08b6d6
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 12 deletions.
6 changes: 3 additions & 3 deletions icons/src/icons/outline/loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion kit/src/elements/button/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dioxus::{events::MouseEvent, prelude::*};

use crate::elements::Appearance;
use crate::elements::{loader::Loader, Appearance};

use common::icons::outline::Shape as Icon;

Expand Down Expand Up @@ -118,6 +118,13 @@ pub fn Button<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
let _ = cx.props.onpress.as_ref().map(|f| f.call(e));
}
},
if let Some(loading) = cx.props.loading {
loading.then(|| rsx!(
Loader {
spinning: true
}
))
},
if let Some(_icon) = cx.props.icon {
rsx!(
// for props, copy the defaults passed in by IconButton
Expand Down
5 changes: 2 additions & 3 deletions kit/src/elements/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use uuid::Uuid;

pub type ValidationError = String;
use crate::elements::label::Label;
use crate::elements::loader::Loader;

use common::icons::outline::Shape as Icon;
use common::icons::Icon as IconElement;
Expand Down Expand Up @@ -483,9 +484,7 @@ pub fn Input<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
}
)),
cx.props.loading.unwrap_or(false).then(move || rsx!(
IconElement {
icon: Icon::Loader
}
Loader { spinning: true },
)),
},
(!error.is_empty()).then(|| rsx!(
Expand Down
21 changes: 21 additions & 0 deletions kit/src/elements/loader/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use common::icons::outline::Shape as Icon;
use common::icons::Icon as IconElement;
use dioxus::prelude::*;

#[derive(PartialEq, Eq, Props)]
pub struct Props {
#[props(optional)]
spinning: Option<bool>,
}

#[allow(non_snake_case)]
pub fn Loader(cx: Scope<Props>) -> Element {
cx.render(rsx!(
div {
class: "loader",
div {
class: "spin",
IconElement { icon: Icon::Loader }
}
}))
}
31 changes: 31 additions & 0 deletions kit/src/elements/loader/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.loader {
height: 20px;
width: 20px;
position: relative;
overflow: hidden;

.spin {
height: 20px;
width: 20px;
animation: spin 1s infinite ease-out;
top: 10px;
left: 10px;
position: relative;
display: inline-block;
}

svg {
fill: transparent;
stroke: var(--text-color);
}
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

1 change: 1 addition & 0 deletions kit/src/elements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod file;
pub mod folder;
pub mod input;
pub mod label;
pub mod loader;
pub mod multiline;
pub mod radio_list;
pub mod range;
Expand Down
10 changes: 6 additions & 4 deletions ui/src/layouts/chats/presentation/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use kit::{
message_reply::MessageReply,
user_image::UserImage,
},
elements::tooltip::{ArrowPosition, Tooltip},
elements::{
loader::Loader,
tooltip::{ArrowPosition, Tooltip},
},
};

use common::state::{pending_message::PendingMessage, Action, Identity, State};
Expand Down Expand Up @@ -102,9 +105,8 @@ pub fn get_messages(
rsx!(div {
class: "fetching",
p {
IconElement {
icon: Icon::Loader,
class: "spin",
Loader {
spinning: true
},
get_local_text("messages.fetching")
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/layouts/log_in/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub fn Layout(cx: Scope, page: UseState<AuthPages>, pin: UseRef<String>) -> Elem
},
aria_label: "create-account-button".into(),
appearance: kit::elements::Appearance::Primary,
icon: if *cmd_in_progress.get() {Icon::Loader} else {Icon::Check},
loading: if *cmd_in_progress.get() { true } else { false },
disabled: *cmd_in_progress.current() || validation_failure.current().is_some(),
onpress: move |_| {
// these are only for testing.
Expand Down

0 comments on commit b08b6d6

Please sign in to comment.