Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(LoadingIndicator): Added spinning loading indicator #1704

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
stavares843 marked this conversation as resolved.
Show resolved Hide resolved
disabled: *cmd_in_progress.current() || validation_failure.current().is_some(),
onpress: move |_| {
// these are only for testing.
Expand Down
Loading