windjammer_ui/components/generated/
popover.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3pub struct Popover {
4    trigger: String,
5    content: String,
6    position: PopoverPosition,
7    class: String,
8}
9
10pub enum PopoverPosition {
11    Top,
12    Bottom,
13    Left,
14    Right,
15}
16
17impl Popover {
18    #[inline]
19    pub fn new(trigger: String, content: String) -> Popover {
20        Popover {
21            trigger,
22            content,
23            position: PopoverPosition::Bottom,
24            class: String::new(),
25        }
26    }
27    #[inline]
28    pub fn position(mut self, position: PopoverPosition) -> Popover {
29        self.position = position;
30        self
31    }
32    #[inline]
33    pub fn class(mut self, class: String) -> Popover {
34        self.class = class;
35        self
36    }
37    pub fn render(&self) -> String {
38        let position_style = match self.position {
39            PopoverPosition::Top => {
40                "bottom: 100%; left: 50%; transform: translateX(-50%); margin-bottom: 8px;"
41            }
42            PopoverPosition::Bottom => {
43                "top: 100%; left: 50%; transform: translateX(-50%); margin-top: 8px;"
44            }
45            PopoverPosition::Left => {
46                "right: 100%; top: 50%; transform: translateY(-50%); margin-right: 8px;"
47            }
48            PopoverPosition::Right => {
49                "left: 100%; top: 50%; transform: translateY(-50%); margin-left: 8px;"
50            }
51        };
52        let mut html = String::new();
53        html.push_str("<div class=\"wj-popover ");
54        html.push_str(self.class.as_str());
55        html.push_str("\" style=\"position: relative; display: inline-block;\">");
56        html.push_str(self.trigger.as_str());
57        html.push_str("<div class=\"wj-popover-content\" style=\"position: absolute; ");
58        html.push_str(position_style);
59        html.push_str(" background: white; border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); min-width: 200px; z-index: 1000; display: none;\">");
60        html.push_str(self.content.as_str());
61        html.push_str("</div>");
62        html.push_str("</div>");
63        html.push_str("<style>.wj-popover:hover .wj-popover-content { display: block; }</style>");
64        html
65    }
66}