windjammer_ui/components/generated/
tabs.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
6pub struct Tab {
7    pub id: String,
8    pub label: String,
9    pub content: String,
10    pub disabled: bool,
11}
12
13impl Tab {
14    #[inline]
15    pub fn new(id: String, label: String, content: String) -> Tab {
16        Tab {
17            id,
18            label,
19            content,
20            disabled: false,
21        }
22    }
23    #[inline]
24    pub fn disabled(mut self, disabled: bool) -> Tab {
25        self.disabled = disabled;
26        self
27    }
28}
29
30#[derive(Debug, Clone, Default)]
31pub struct Tabs {
32    pub tabs: Vec<Tab>,
33    pub active: String,
34}
35
36impl Tabs {
37    #[inline]
38    pub fn new() -> Tabs {
39        Tabs {
40            tabs: Vec::new(),
41            active: "".to_string(),
42        }
43    }
44    #[inline]
45    pub fn tab(mut self, tab: Tab) -> Tabs {
46        self.tabs.push(tab);
47        self
48    }
49    #[inline]
50    pub fn active(mut self, id: String) -> Tabs {
51        self.active = id;
52        self
53    }
54}
55
56impl Renderable for Tabs {
57    #[inline]
58    fn render(self) -> String {
59        let mut tabs_html = "<div class='wj-tabs-header'>".to_string();
60        let mut i = 0;
61        while i < (self.tabs.len() as i64) {
62            let tab = &self.tabs[i as usize];
63            let active_class = {
64                if tab.id == self.active {
65                    " wj-tab-active".to_string()
66                } else {
67                    "".to_string()
68                }
69            };
70            let disabled_class = {
71                if tab.disabled {
72                    " wj-tab-disabled".to_string()
73                } else {
74                    "".to_string()
75                }
76            };
77            tabs_html = format!(
78                "{}<button class='wj-tab{}{}' data-tab-id='{}'>{}</button>",
79                tabs_html, active_class, disabled_class, tab.id, tab.label
80            );
81            i += 1;
82        }
83        tabs_html = format!("{}</div>", tabs_html);
84        let mut content_html = "<div class='wj-tabs-content'>".to_string();
85        let mut j = 0;
86        while j < (self.tabs.len() as i64) {
87            let tab = &self.tabs[j as usize];
88            let display_style = {
89                if tab.id == self.active {
90                    "display: block;".to_string()
91                } else {
92                    "display: none;".to_string()
93                }
94            };
95            content_html = format!(
96                "{}<div class='wj-tab-panel' data-tab-id='{}' style='{}'>{}</div>",
97                content_html, tab.id, display_style, tab.content
98            );
99            j += 1;
100        }
101        content_html = format!("{}</div>", content_html);
102        format!("<div class='wj-tabs'>{}{}</div>", tabs_html, content_html)
103    }
104}