windjammer_ui/components/generated/
modal.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum ModalSize {
7    Small,
8    Medium,
9    Large,
10    FullScreen,
11}
12
13#[derive(Debug, Clone, PartialEq)]
14pub struct Modal {
15    pub id: String,
16    pub title: String,
17    pub content: String,
18    pub footer: String,
19    pub size: ModalSize,
20    pub closeable: bool,
21    pub visible: bool,
22}
23
24impl Modal {
25    #[inline]
26    pub fn new(id: String, title: String) -> Modal {
27        Modal {
28            id,
29            title,
30            content: String::new(),
31            footer: String::new(),
32            size: ModalSize::Medium,
33            closeable: true,
34            visible: false,
35        }
36    }
37    #[inline]
38    pub fn content(mut self, content: String) -> Modal {
39        self.content = content;
40        self
41    }
42    #[inline]
43    pub fn footer(mut self, footer: String) -> Modal {
44        self.footer = footer;
45        self
46    }
47    #[inline]
48    pub fn size(mut self, size: ModalSize) -> Modal {
49        self.size = size;
50        self
51    }
52    #[inline]
53    pub fn closeable(mut self, closeable: bool) -> Modal {
54        self.closeable = closeable;
55        self
56    }
57    #[inline]
58    pub fn visible(mut self, visible: bool) -> Modal {
59        self.visible = visible;
60        self
61    }
62}
63
64impl Renderable for Modal {
65    #[inline]
66    fn render(self) -> String {
67        let width = match self.size {
68            ModalSize::Small => "400px".to_string(),
69            ModalSize::Medium => "600px".to_string(),
70            ModalSize::Large => "800px".to_string(),
71            ModalSize::FullScreen => "100vw".to_string(),
72        };
73        let height = match self.size {
74            ModalSize::FullScreen => "100vh".to_string(),
75            _ => "auto".to_string(),
76        };
77        let display = {
78            if self.visible {
79                "flex".to_string()
80            } else {
81                "none".to_string()
82            }
83        };
84        let mut html = String::new();
85        html.push_str("<div id='");
86        html.push_str(&self.id);
87        html.push_str("-backdrop' style='position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); display: ");
88        html.push_str(&display);
89        html.push_str("; align-items: center; justify-content: center; z-index: 1000;'>");
90        html.push_str("<div id='");
91        html.push_str(&self.id);
92        html.push_str("' style='background: white; border-radius: 8px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1); max-width: ");
93        html.push_str(&width);
94        html.push_str("; width: 100%; max-height: ");
95        html.push_str(&height);
96        html.push_str("; display: flex; flex-direction: column; margin: 16px;'>");
97        html.push_str("<div style='padding: 16px 24px; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; justify-content: space-between;'>");
98        html.push_str("<h2 style='margin: 0; font-size: 18px; font-weight: 600; color: #1a202c;'>");
99        html.push_str(&self.title);
100        html.push_str("</h2>");
101        if self.closeable {
102            html.push_str("<button onclick='document.getElementById(\"");
103            html.push_str(&self.id);
104            html.push_str("-backdrop\").style.display=\"none\"' style='background: none; border: none; font-size: 24px; cursor: pointer; color: #718096; padding: 0; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;'>&times;</button>")
105        }
106        html.push_str("</div>");
107        html.push_str("<div style='padding: 24px; flex: 1; overflow-y: auto;'>");
108        html.push_str(&self.content);
109        html.push_str("</div>");
110        if self.footer.len() > (0 as usize) {
111            html.push_str("<div style='padding: 16px 24px; border-top: 1px solid #e2e8f0; display: flex; justify-content: flex-end; gap: 8px;'>");
112            html.push_str(&self.footer);
113            html.push_str("</div>")
114        }
115        html.push_str("</div>");
116        html.push_str("</div>");
117        html
118    }
119}