windjammer_ui/components/generated/
chatinput.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct ChatInput {
7    pub placeholder: String,
8    pub value: String,
9    pub disabled: bool,
10    pub multiline: bool,
11    pub rows: i32,
12}
13
14impl ChatInput {
15    #[inline]
16    pub fn new() -> ChatInput {
17        ChatInput {
18            placeholder: String::from("Type a message..."),
19            value: String::from(""),
20            disabled: false,
21            multiline: true,
22            rows: 3,
23        }
24    }
25    #[inline]
26    pub fn placeholder(mut self, placeholder: String) -> ChatInput {
27        self.placeholder = placeholder;
28        self
29    }
30    #[inline]
31    pub fn value(mut self, value: String) -> ChatInput {
32        self.value = value;
33        self
34    }
35    #[inline]
36    pub fn disabled(mut self, disabled: bool) -> ChatInput {
37        self.disabled = disabled;
38        self
39    }
40    #[inline]
41    pub fn multiline(mut self, multiline: bool) -> ChatInput {
42        self.multiline = multiline;
43        self
44    }
45    #[inline]
46    pub fn rows(mut self, rows: i32) -> ChatInput {
47        self.rows = rows;
48        self
49    }
50}
51
52impl Renderable for ChatInput {
53    #[inline]
54    fn render(self) -> String {
55        let disabled_attr = {
56            if self.disabled {
57                " disabled".to_string()
58            } else {
59                "".to_string()
60            }
61        };
62        let input_html = {
63            if self.multiline {
64                format!("<textarea class='wj-chat-input-field' placeholder='{}' rows='{}'{}>{}</textarea>", self.placeholder, self.rows, disabled_attr, self.value)
65            } else {
66                format!("<input type='text' class='wj-chat-input-field' placeholder='{}' value='{}'{}/>", self.placeholder, self.value, disabled_attr)
67            }
68        };
69        format!(
70            "<div class='wj-chat-input'>
71                {}
72                <button class='wj-chat-send-button'{}>
73                    <span>➤</span>
74                </button>
75            </div>",
76            input_html, disabled_attr
77        )
78    }
79}