windjammer_ui/components/generated/
sidebar.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum SidebarPosition {
7 Left,
8 Right,
9}
10
11#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
12pub struct SidebarItem {
13 pub label: String,
14 pub icon: String,
15 pub href: String,
16}
17
18impl SidebarItem {
19 #[inline]
20 pub fn new(label: String) -> SidebarItem {
21 SidebarItem {
22 label,
23 icon: String::from(""),
24 href: String::from("#"),
25 }
26 }
27 #[inline]
28 pub fn icon(mut self, icon: String) -> SidebarItem {
29 self.icon = icon;
30 self
31 }
32 #[inline]
33 pub fn href(mut self, href: String) -> SidebarItem {
34 self.href = href;
35 self
36 }
37}
38
39#[derive(Debug, Clone)]
40pub struct Sidebar {
41 pub items: Vec<SidebarItem>,
42 pub position: SidebarPosition,
43 pub width: String,
44 pub collapsed: bool,
45}
46
47impl Sidebar {
48 #[inline]
49 pub fn new() -> Sidebar {
50 Sidebar {
51 items: Vec::new(),
52 position: SidebarPosition::Left,
53 width: String::from("250px"),
54 collapsed: false,
55 }
56 }
57 #[inline]
58 pub fn item(mut self, item: SidebarItem) -> Sidebar {
59 self.items.push(item);
60 self
61 }
62 #[inline]
63 pub fn position(mut self, pos: SidebarPosition) -> Sidebar {
64 self.position = pos;
65 self
66 }
67 #[inline]
68 pub fn width(mut self, width: String) -> Sidebar {
69 self.width = width;
70 self
71 }
72 #[inline]
73 pub fn collapsed(mut self, collapsed: bool) -> Sidebar {
74 self.collapsed = collapsed;
75 self
76 }
77}
78
79impl Renderable for Sidebar {
80 #[inline]
81 fn render(self) -> String {
82 let mut items_html = Vec::new();
83 for item in &self.items {
84 let icon_html = {
85 if item.icon.clone().len() > 0 {
86 format!("<span class='wj-sidebar-icon'>{}</span>", item.icon.clone())
87 } else {
88 String::from("")
89 }
90 };
91 items_html.push(format!("<a href='{}' class='wj-sidebar-item'>{}<span class='wj-sidebar-label'>{}</span></a>", item.href.clone(), icon_html, item.label.clone()));
92 }
93 let position_class = match self.position {
94 SidebarPosition::Left => "wj-sidebar-left".to_string(),
95 SidebarPosition::Right => "wj-sidebar-right".to_string(),
96 };
97 let collapsed_class = {
98 if self.collapsed {
99 " wj-sidebar-collapsed".to_string()
100 } else {
101 "".to_string()
102 }
103 };
104 format!("<aside class='wj-sidebar {} {}' style='width: {}'>
105 <div class='wj-sidebar-toggle' onclick='this.parentElement.classList.toggle(\"wj-sidebar-collapsed\")'>
106 <span class='wj-sidebar-toggle-icon'>☰</span>
107 </div>
108 <nav class='wj-sidebar-nav'>{}</nav>
109 </aside>", position_class, collapsed_class, self.width, items_html.join(""))
110 }
111}