windjammer_ui/components/generated/
tabpanel.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use std::fmt::Write;
4
5use super::traits::Renderable;
6
7pub struct TabPanelTab {
8    id: String,
9    title: String,
10    content: String,
11}
12
13impl TabPanelTab {
14    #[inline]
15    pub fn new(id: String, title: String, content: String) -> TabPanelTab {
16        TabPanelTab { id, title, content }
17    }
18}
19
20pub struct TabPanel {
21    tabs: Vec<TabPanelTab>,
22    active: String,
23    orientation: String,
24}
25
26impl TabPanel {
27    #[inline]
28    pub fn new() -> TabPanel {
29        TabPanel {
30            tabs: Vec::new(),
31            active: "".to_string(),
32            orientation: "horizontal".to_string(),
33        }
34    }
35    #[inline]
36    pub fn tab(mut self, tab: TabPanelTab) -> TabPanel {
37        self.tabs.push(tab);
38        self
39    }
40    #[inline]
41    pub fn active(mut self, id: String) -> TabPanel {
42        self.active = id;
43        self
44    }
45    #[inline]
46    pub fn orientation(mut self, orientation: String) -> TabPanel {
47        self.orientation = orientation;
48        self
49    }
50}
51
52impl Renderable for TabPanel {
53    fn render(self) -> String {
54        let flex_direction = {
55            if self.orientation == "vertical" {
56                "row"
57            } else {
58                "column"
59            }
60        };
61        let mut tabs_html = {
62            let mut __s = String::with_capacity(64);
63            write!(
64                &mut __s,
65                "<div class='wj-tab-panel-tabs wj-tab-panel-{}'>
66",
67                self.orientation
68            )
69            .unwrap();
70            __s
71        };
72        let mut i = 0;
73        while i < self.tabs.len() {
74            let tab = &self.tabs[i];
75            let active_class = {
76                if tab.id == self.active {
77                    " wj-tab-active"
78                } else {
79                    ""
80                }
81            };
82            tabs_html = format!(
83                "{}  <button class='wj-tab-panel-tab{}' data-id='{}'>{}</button>
84",
85                tabs_html, active_class, tab.id, tab.title
86            );
87            i += 1;
88        }
89        tabs_html = format!(
90            "{}</div>
91",
92            tabs_html
93        );
94        let mut content_html = "<div class='wj-tab-panel-content'>
95"
96        .to_string();
97        let mut j = 0;
98        while j < self.tabs.len() {
99            let tab = &self.tabs[j];
100            let display = {
101                if tab.id == self.active {
102                    "block"
103                } else {
104                    "none"
105                }
106            };
107            content_html = format!(
108                "{}  <div class='wj-tab-panel-pane' data-id='{}' style='display: {};'>
109    {}
110  </div>
111",
112                content_html, tab.id, display, tab.content
113            );
114            j += 1;
115        }
116        content_html = format!("{}</div>", content_html);
117        format!(
118            "<div class='wj-tab-panel' style='display: flex; flex-direction: {};'>
119{}{}
120</div>",
121            flex_direction, tabs_html, content_html
122        )
123    }
124}