windjammer_ui/components/generated/
loading.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3pub struct Loading {
4    text: String,
5    size: LoadingSize,
6    overlay: bool,
7    class: String,
8}
9
10pub enum LoadingSize {
11    Small,
12    Medium,
13    Large,
14}
15
16impl Loading {
17    #[inline]
18    pub fn new() -> Loading {
19        Loading {
20            text: String::new(),
21            size: LoadingSize::Medium,
22            overlay: false,
23            class: String::new(),
24        }
25    }
26    #[inline]
27    pub fn text(mut self, text: String) -> Loading {
28        self.text = text;
29        self
30    }
31    #[inline]
32    pub fn size(mut self, size: LoadingSize) -> Loading {
33        self.size = size;
34        self
35    }
36    #[inline]
37    pub fn overlay(mut self, overlay: bool) -> Loading {
38        self.overlay = overlay;
39        self
40    }
41    #[inline]
42    pub fn class(mut self, class: String) -> Loading {
43        self.class = class;
44        self
45    }
46    pub fn render(&self) -> String {
47        let spinner_size = match self.size {
48            LoadingSize::Small => "24px",
49            LoadingSize::Medium => "40px",
50            LoadingSize::Large => "64px",
51        };
52        let border_width = match self.size {
53            LoadingSize::Small => "2px",
54            LoadingSize::Medium => "3px",
55            LoadingSize::Large => "4px",
56        };
57        let mut html = String::new();
58        if self.overlay {
59            html.push_str("<div class=\"wj-loading-overlay\" style=\"position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 9999;\">")
60        }
61        html.push_str("<div class=\"wj-loading ");
62        html.push_str(self.class.as_str());
63        html.push_str(
64            "\" style=\"display: flex; flex-direction: column; align-items: center; gap: 12px;\">",
65        );
66        html.push_str("<div style=\"width: ");
67        html.push_str(spinner_size);
68        html.push_str("; height: ");
69        html.push_str(spinner_size);
70        html.push_str("; border: ");
71        html.push_str(border_width);
72        html.push_str(" solid #f3f4f6; border-top-color: #3b82f6; border-radius: 50%; animation: spin 0.8s linear infinite;\"></div>");
73        if !self.text.is_empty() {
74            html.push_str("<span style=\"color: ");
75            if self.overlay {
76                html.push_str("white")
77            } else {
78                html.push_str("#6b7280")
79            }
80            html.push_str("; font-size: 14px;\">");
81            html.push_str(self.text.as_str());
82            html.push_str("</span>")
83        }
84        html.push_str("</div>");
85        if self.overlay {
86            html.push_str("</div>")
87        }
88        html.push_str("<style>@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }</style>");
89        html
90    }
91}