windjammer_ui/components/generated/
textarea.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3pub struct Textarea {
4    value: String,
5    placeholder: String,
6    rows: i32,
7    disabled: bool,
8    readonly: bool,
9    max_length: i32,
10    resize: TextareaResize,
11    class: String,
12}
13
14pub enum TextareaResize {
15    None,
16    Vertical,
17    Horizontal,
18    Both,
19}
20
21impl Textarea {
22    #[inline]
23    pub fn new() -> Textarea {
24        Textarea {
25            value: String::new(),
26            placeholder: String::new(),
27            rows: 4,
28            disabled: false,
29            readonly: false,
30            max_length: 0,
31            resize: TextareaResize::Vertical,
32            class: String::new(),
33        }
34    }
35    #[inline]
36    pub fn value(mut self, value: String) -> Textarea {
37        self.value = value;
38        self
39    }
40    #[inline]
41    pub fn placeholder(mut self, placeholder: String) -> Textarea {
42        self.placeholder = placeholder;
43        self
44    }
45    #[inline]
46    pub fn rows(mut self, rows: i32) -> Textarea {
47        self.rows = rows;
48        self
49    }
50    #[inline]
51    pub fn disabled(mut self, disabled: bool) -> Textarea {
52        self.disabled = disabled;
53        self
54    }
55    #[inline]
56    pub fn readonly(mut self, readonly: bool) -> Textarea {
57        self.readonly = readonly;
58        self
59    }
60    #[inline]
61    pub fn max_length(mut self, max_length: i32) -> Textarea {
62        self.max_length = max_length;
63        self
64    }
65    #[inline]
66    pub fn resize(mut self, resize: TextareaResize) -> Textarea {
67        self.resize = resize;
68        self
69    }
70    #[inline]
71    pub fn class(mut self, class: String) -> Textarea {
72        self.class = class;
73        self
74    }
75    pub fn render(&self) -> String {
76        let resize_style = match self.resize {
77            TextareaResize::None => "resize: none;",
78            TextareaResize::Vertical => "resize: vertical;",
79            TextareaResize::Horizontal => "resize: horizontal;",
80            TextareaResize::Both => "resize: both;",
81        };
82        let disabled_attr = {
83            if self.disabled {
84                " disabled"
85            } else {
86                ""
87            }
88        };
89        let readonly_attr = {
90            if self.readonly {
91                " readonly"
92            } else {
93                ""
94            }
95        };
96        let mut html = String::new();
97        html.push_str("<textarea class=\"wj-textarea ");
98        html.push_str(self.class.as_str());
99        html.push_str("\" rows=\"");
100        html.push_str(self.rows.to_string().as_str());
101        html.push('"');
102        if !self.placeholder.is_empty() {
103            html.push_str(" placeholder=\"");
104            html.push_str(self.placeholder.as_str());
105            html.push('"')
106        }
107        if self.max_length > 0 {
108            html.push_str(" maxlength=\"");
109            html.push_str(self.max_length.to_string().as_str());
110            html.push('"')
111        }
112        html.push_str(disabled_attr);
113        html.push_str(readonly_attr);
114        html.push_str(" style=\"");
115        html.push_str(resize_style);
116        html.push_str(" padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; font-family: inherit; width: 100%; box-sizing: border-box;\">");
117        html.push_str(self.value.as_str());
118        html.push_str("</textarea>");
119        html
120    }
121}