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