windjammer_ui/components/generated/
loading.rs

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