windjammer_ui/components/generated/
menu.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3pub struct Menu {
4    items: Vec<String>,
5    trigger: String,
6    class: String,
7}
8
9impl Menu {
10    #[inline]
11    pub fn new(trigger: String) -> Menu {
12        Menu {
13            items: Vec::new(),
14            trigger,
15            class: String::new(),
16        }
17    }
18    #[inline]
19    pub fn item(mut self, item: String) -> Menu {
20        self.items.push(item);
21        self
22    }
23    #[inline]
24    pub fn class(mut self, class: String) -> Menu {
25        self.class = class;
26        self
27    }
28    pub fn render(&self) -> String {
29        let mut html = String::new();
30        html.push_str("<div class=\"wj-menu ");
31        html.push_str(self.class.as_str());
32        html.push_str("\" style=\"position: relative; display: inline-block;\">");
33        html.push_str(self.trigger.as_str());
34        html.push_str("<div class=\"wj-menu-items\" style=\"position: absolute; top: 100%; left: 0; margin-top: 4px; background: white; border: 1px solid #e5e7eb; border-radius: 8px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); min-width: 200px; z-index: 1000; display: none;\">");
35        for item in self.items.iter() {
36            html.push_str(item.as_str());
37        }
38        html.push_str("</div>");
39        html.push_str("</div>");
40        html.push_str("<style>.wj-menu:hover .wj-menu-items { display: block; }</style>");
41        html
42    }
43}
44
45pub struct MenuItem {
46    label: String,
47    icon: String,
48    href: String,
49    disabled: bool,
50    class: String,
51}
52
53impl MenuItem {
54    #[inline]
55    pub fn new(label: String) -> MenuItem {
56        MenuItem {
57            label,
58            icon: String::new(),
59            href: "#".to_string(),
60            disabled: false,
61            class: String::new(),
62        }
63    }
64    #[inline]
65    pub fn icon(mut self, icon: String) -> MenuItem {
66        self.icon = icon;
67        self
68    }
69    #[inline]
70    pub fn href(mut self, href: String) -> MenuItem {
71        self.href = href;
72        self
73    }
74    #[inline]
75    pub fn disabled(mut self, disabled: bool) -> MenuItem {
76        self.disabled = disabled;
77        self
78    }
79    #[inline]
80    pub fn class(mut self, class: String) -> MenuItem {
81        self.class = class;
82        self
83    }
84    pub fn render(&self) -> String {
85        let disabled_style = {
86            if self.disabled {
87                " opacity: 0.5; cursor: not-allowed;"
88            } else {
89                " cursor: pointer;"
90            }
91        };
92        let mut html = String::new();
93        html.push_str("<a href=\"");
94        html.push_str(self.href.as_str());
95        html.push_str("\" class=\"wj-menu-item ");
96        html.push_str(self.class.as_str());
97        html.push_str("\" style=\"display: flex; align-items: center; gap: 8px; padding: 10px 16px; color: #374151; text-decoration: none;");
98        html.push_str(disabled_style);
99        html.push_str(" transition: background-color 0.2s;\">");
100        if !self.icon.is_empty() {
101            html.push_str("<span>");
102            html.push_str(self.icon.as_str());
103            html.push_str("</span>")
104        }
105        html.push_str("<span>");
106        html.push_str(self.label.as_str());
107        html.push_str("</span>");
108        html.push_str("</a>");
109        html.push_str("<style>.wj-menu-item:hover:not([style*='cursor: not-allowed']) { background-color: #f3f4f6; }</style>");
110        html
111    }
112}