windjammer_ui/components/generated/
contextmenu.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
6pub struct ContextMenuItem {
7 pub label: String,
8 pub icon: String,
9 pub action: String,
10 pub disabled: bool,
11}
12
13impl ContextMenuItem {
14 #[inline]
15 pub fn new(label: String) -> ContextMenuItem {
16 ContextMenuItem {
17 label,
18 icon: String::from(""),
19 action: String::from(""),
20 disabled: false,
21 }
22 }
23 #[inline]
24 pub fn icon(mut self, icon: String) -> ContextMenuItem {
25 self.icon = icon;
26 self
27 }
28 #[inline]
29 pub fn action(mut self, action: String) -> ContextMenuItem {
30 self.action = action;
31 self
32 }
33 #[inline]
34 pub fn disabled(mut self, disabled: bool) -> ContextMenuItem {
35 self.disabled = disabled;
36 self
37 }
38}
39
40#[derive(Debug, Clone, Default)]
41pub struct ContextMenu {
42 pub items: Vec<ContextMenuItem>,
43 pub trigger_id: String,
44}
45
46impl ContextMenu {
47 #[inline]
48 pub fn new(trigger_id: String) -> ContextMenu {
49 ContextMenu {
50 items: Vec::new(),
51 trigger_id,
52 }
53 }
54 #[inline]
55 pub fn item(mut self, item: ContextMenuItem) -> ContextMenu {
56 self.items.push(item);
57 self
58 }
59}
60
61impl Renderable for ContextMenu {
62 #[inline]
63 fn render(self) -> String {
64 let mut items_html = Vec::new();
65 for item in &self.items {
66 let icon_html = {
67 if item.icon.clone().len() > 0 {
68 format!("<span class='wj-context-icon'>{}</span>", item.icon.clone())
69 } else {
70 String::from("")
71 }
72 };
73 let disabled_class = {
74 if item.disabled.clone() {
75 " wj-context-item-disabled".to_string()
76 } else {
77 "".to_string()
78 }
79 };
80 let disabled_attr = {
81 if item.disabled.clone() {
82 " disabled".to_string()
83 } else {
84 "".to_string()
85 }
86 };
87 items_html.push(format!(
88 "<button class='wj-context-item{}' onclick='{}'{}>
89 {}
90 <span>{}</span>
91 </button>",
92 disabled_class,
93 item.action.clone(),
94 disabled_attr,
95 icon_html,
96 item.label.clone()
97 ));
98 }
99 format!(
100 "<div class='wj-context-menu' id='context-{}' style='display: none'>
101 {}
102 </div>",
103 self.trigger_id,
104 items_html.join("")
105 )
106 }
107}