freya_components/
loader.rs1use dioxus::prelude::*;
2use freya_elements as dioxus_elements;
3use freya_hooks::{
4 use_animation,
5 use_applied_theme,
6 AnimNum,
7 LoaderTheme,
8 LoaderThemeWith,
9 OnFinish,
10};
11
12#[derive(Props, Clone, PartialEq)]
14pub struct LoaderProps {
15 pub theme: Option<LoaderThemeWith>,
17}
18
19#[cfg_attr(feature = "docs",
44 doc = embed_doc_image::embed_image!("loader", "images/gallery_loader.png")
45)]
46#[allow(non_snake_case)]
47pub fn Loader(props: LoaderProps) -> Element {
48 let theme = use_applied_theme!(&props.theme, loader);
49 let animation = use_animation(|conf| {
50 conf.auto_start(true);
51 conf.on_finish(OnFinish::Restart);
52 AnimNum::new(0.0, 360.0).time(650)
53 });
54
55 let LoaderTheme { primary_color } = theme;
56
57 let degrees = animation.get().read().read();
58
59 rsx!(svg {
60 rotate: "{degrees}deg",
61 width: "48",
62 height: "48",
63 svg_content: r#"
64 <svg viewBox="0 0 600 600" xmlns="http://www.w3.org/2000/svg">
65 <circle class="spin" cx="300" cy="300" fill="none"
66 r="250" stroke-width="64" stroke="{primary_color}"
67 stroke-dasharray="256 1400"
68 stroke-linecap="round" />
69 </svg>
70 "#
71 })
72}