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