-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::time::Duration; | ||
|
||
use dioxus::prelude::*; | ||
use freya_elements as dioxus_elements; | ||
use freya_hooks::use_get_theme; | ||
use tokio::time::interval; | ||
|
||
/// [`Loader`] component properties. Currently empty. | ||
#[derive(Props, PartialEq)] | ||
pub struct LoaderProps {} | ||
|
||
/// `Loader` component. | ||
/// | ||
/// # Props | ||
/// See [`LoaderProps`]. | ||
/// | ||
/// # Styling | ||
/// Inherits the [`LoaderTheme`](freya_hooks::LoaderTheme) theme. | ||
/// | ||
#[allow(non_snake_case)] | ||
pub fn Loader(cx: Scope<LoaderProps>) -> Element { | ||
let theme = use_get_theme(cx); | ||
let degrees = use_state(cx, || 0); | ||
|
||
let loader_theme = theme.loader; | ||
|
||
use_effect(cx, (), move |_| { | ||
to_owned![degrees]; | ||
async move { | ||
let mut ticker = interval(Duration::from_millis(28)); | ||
loop { | ||
ticker.tick().await; | ||
if *degrees.get() > 360 { | ||
degrees.set(0); | ||
} else { | ||
degrees += 10; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
render!(svg { | ||
rotate: "{degrees}", | ||
width: "31", | ||
height: "31", | ||
svg_content: r#" | ||
<svg width="31" height="31" viewBox="0 0 31 31" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M15.5235 27.6652C22.2292 27.6652 27.6652 22.2292 27.6652 15.5235C27.6652 8.81783 22.2292 3.38182 15.5235 3.38182C8.81783 3.38182 3.38182 8.81783 3.38182 15.5235C3.38182 22.2292 8.81783 27.6652 15.5235 27.6652Z" stroke="{loader_theme.primary_color}" stroke-width="4"/> | ||
<path d="M27.6652 15.5235C27.6652 8.81859 22.2284 3.38182 15.5235 3.38182" stroke="{loader_theme.secondary_color}" stroke-width="4"/> | ||
</svg> | ||
"# | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters