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