windjammer_ui/components/generated/
drawer.rs

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