windjammer_ui/components/generated/
menu.rs

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