windjammer_ui/components/generated/
progress.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5pub enum ProgressVariant {
6    Default,
7    Success,
8    Warning,
9    Danger,
10}
11
12pub struct Progress {
13    value: f64,
14    max: f64,
15    variant: ProgressVariant,
16    show_label: bool,
17}
18
19impl Progress {
20    #[inline]
21    pub fn new(value: f64) -> Progress {
22        Progress {
23            value,
24            max: 100.0,
25            variant: ProgressVariant::Default,
26            show_label: true,
27        }
28    }
29    #[inline]
30    pub fn max(mut self, max: f64) -> Progress {
31        self.max = max;
32        self
33    }
34    #[inline]
35    pub fn variant(mut self, variant: ProgressVariant) -> Progress {
36        self.variant = variant;
37        self
38    }
39    #[inline]
40    pub fn show_label(mut self, show: bool) -> Progress {
41        self.show_label = show;
42        self
43    }
44}
45
46impl Renderable for Progress {
47    #[inline]
48    fn render(self) -> String {
49        let percentage = (self.value / self.max * 100.0).clamp(0.0, 100.0);
50        let variant_class = match self.variant {
51            ProgressVariant::Default => "wj-progress-default",
52            ProgressVariant::Success => "wj-progress-success",
53            ProgressVariant::Warning => "wj-progress-warning",
54            ProgressVariant::Danger => "wj-progress-danger",
55        };
56        let color = match self.variant {
57            ProgressVariant::Default => "#3498db",
58            ProgressVariant::Success => "#2ecc71",
59            ProgressVariant::Warning => "#f39c12",
60            ProgressVariant::Danger => "#e74c3c",
61        };
62        let label_html = {
63            if self.show_label {
64                format!("{:.0}%", percentage)
65            } else {
66                "".to_string()
67            }
68        };
69        format!("<div class='wj-progress-container' style='width: 100%; background-color: #e0e0e0; border-radius: 4px; overflow: hidden;'>
70  <div class='wj-progress-bar {}' style='width: {}%; height: 24px; background-color: {}; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; transition: width 0.3s ease;'>
71    {}
72  </div>
73</div>", variant_class, percentage, color, label_html)
74    }
75}