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