windjammer_ui/components/generated/
drawer.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3pub struct Drawer {
4    children: Vec<String>,
5    position: DrawerPosition,
6    width: String,
7    open: bool,
8    class: String,
9}
10
11pub enum DrawerPosition {
12    Left,
13    Right,
14    Top,
15    Bottom,
16}
17
18impl Drawer {
19    #[inline]
20    pub fn new() -> Drawer {
21        Drawer {
22            children: Vec::new(),
23            position: DrawerPosition::Right,
24            width: "320px".to_string(),
25            open: false,
26            class: String::new(),
27        }
28    }
29    #[inline]
30    pub fn child(mut self, child: String) -> Drawer {
31        self.children.push(child);
32        self
33    }
34    #[inline]
35    pub fn position(mut self, position: DrawerPosition) -> Drawer {
36        self.position = position;
37        self
38    }
39    #[inline]
40    pub fn width(mut self, width: String) -> Drawer {
41        self.width = width;
42        self
43    }
44    #[inline]
45    pub fn open(mut self, open: bool) -> Drawer {
46        self.open = open;
47        self
48    }
49    #[inline]
50    pub fn class(mut self, class: String) -> Drawer {
51        self.class = class;
52        self
53    }
54    pub fn render(&self) -> String {
55        let (position_style, size_prop) = match self.position {
56            DrawerPosition::Left => (
57                "left: 0; top: 0; bottom: 0;",
58                format!("width: {};", self.width),
59            ),
60            DrawerPosition::Right => (
61                "right: 0; top: 0; bottom: 0;",
62                format!("width: {};", self.width),
63            ),
64            DrawerPosition::Top => (
65                "top: 0; left: 0; right: 0;",
66                format!("height: {};", self.width),
67            ),
68            DrawerPosition::Bottom => (
69                "bottom: 0; left: 0; right: 0;",
70                format!("height: {};", self.width),
71            ),
72        };
73        let transform = {
74            if self.open {
75                "transform: translateX(0);"
76            } else {
77                match self.position {
78                    DrawerPosition::Left => "transform: translateX(-100%);",
79                    DrawerPosition::Right => "transform: translateX(100%);",
80                    DrawerPosition::Top => "transform: translateY(-100%);",
81                    DrawerPosition::Bottom => "transform: translateY(100%);",
82                }
83            }
84        };
85        let display = {
86            if self.open {
87                "display: block;"
88            } else {
89                "display: none;"
90            }
91        };
92        let mut html = String::new();
93        html.push_str("<div class=\"wj-drawer-backdrop\" style=\"");
94        html.push_str(display);
95        html.push_str(" position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); z-index: 999;\"></div>");
96        html.push_str("<div class=\"wj-drawer ");
97        html.push_str(self.class.as_str());
98        html.push_str("\" style=\"position: fixed; ");
99        html.push_str(position_style);
100        html.push(' ');
101        html.push_str(size_prop.as_str());
102        html.push(' ');
103        html.push_str(transform);
104        html.push_str(" background: white; box-shadow: 0 0 20px rgba(0, 0, 0, 0.3); z-index: 1000; transition: transform 0.3s ease; overflow-y: auto; padding: 24px;\">");
105        for child in self.children.iter() {
106            html.push_str(child.as_str());
107        }
108        html.push_str("</div>");
109        html
110    }
111}