windjammer_ui/components/generated/
textarea.rs

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