windjammer_ui/components/generated/
stepper.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5pub struct StepperStep {
6    label: String,
7    description: String,
8    completed: bool,
9}
10
11impl StepperStep {
12    #[inline]
13    pub fn new(label: String) -> StepperStep {
14        StepperStep {
15            label,
16            description: String::new(),
17            completed: false,
18        }
19    }
20    #[inline]
21    pub fn description(mut self, desc: String) -> StepperStep {
22        self.description = desc;
23        self
24    }
25    #[inline]
26    pub fn completed(mut self, completed: bool) -> StepperStep {
27        self.completed = completed;
28        self
29    }
30}
31
32pub struct Stepper {
33    steps: Vec<StepperStep>,
34    current_step: i32,
35}
36
37impl Stepper {
38    #[inline]
39    pub fn new() -> Stepper {
40        Stepper {
41            steps: Vec::new(),
42            current_step: 0,
43        }
44    }
45    #[inline]
46    pub fn step(mut self, step: StepperStep) -> Stepper {
47        self.steps.push(step);
48        self
49    }
50    #[inline]
51    pub fn current_step(mut self, index: i32) -> Stepper {
52        self.current_step = index;
53        self
54    }
55}
56
57impl Renderable for Stepper {
58    #[inline]
59    fn render(self) -> String {
60        let mut html = String::new();
61        html.push_str("<div style='display: flex; align-items: center; justify-content: space-between; padding: 24px 0;'>");
62        let total_steps = self.steps.len() as i32;
63        for (step_index, step) in self.steps.iter().enumerate() {
64            let step_index = step_index as i32;
65            let is_current = step_index == self.current_step;
66            let is_completed = step.completed || step_index < self.current_step;
67            html.push_str("<div style='display: flex; flex-direction: column; align-items: center; flex: 1;'>");
68            let bg_color = {
69                if is_completed {
70                    "#10b981"
71                } else {
72                    if is_current {
73                        "#3b82f6"
74                    } else {
75                        "#e2e8f0"
76                    }
77                }
78            };
79            let text_color = {
80                if is_completed || is_current {
81                    "white"
82                } else {
83                    "#718096"
84                }
85            };
86            html.push_str(
87                "<div style='width: 40px; height: 40px; border-radius: 50%; background: ",
88            );
89            html.push_str(bg_color);
90            html.push_str("; color: ");
91            html.push_str(text_color);
92            html.push_str("; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; margin-bottom: 8px;'>");
93            if is_completed {
94                html.push('✓')
95            } else {
96                html.push_str(&format!("{}", step_index + 1))
97            }
98            html.push_str("</div>");
99            html.push_str("<div style='text-align: center;'>");
100            html.push_str("<div style='font-weight: 600; font-size: 14px; color: ");
101            if is_current {
102                html.push_str("#1a202c")
103            } else {
104                html.push_str("#718096")
105            }
106            html.push_str("; margin-bottom: 4px;'>");
107            html.push_str(&step.label);
108            html.push_str("</div>");
109            if step.description.len() > 0 {
110                html.push_str("<div style='font-size: 12px; color: #a0aec0;'>");
111                html.push_str(&step.description);
112                html.push_str("</div>")
113            }
114            html.push_str("</div>");
115            html.push_str("</div>");
116            if step_index < total_steps - 1 {
117                let line_color = {
118                    if is_completed {
119                        "#10b981"
120                    } else {
121                        "#e2e8f0"
122                    }
123                };
124                html.push_str("<div style='flex: 1; height: 2px; background: ");
125                html.push_str(line_color);
126                html.push_str("; margin: 0 8px; margin-bottom: 48px;'></div>")
127            }
128        }
129        html.push_str("</div>");
130        html
131    }
132}