1use crate::elem::{HtmlProp, HtmlProps};
2use std::borrow::Cow;
3use web_sys::HtmlInputElement;
4
5#[allow(non_camel_case_types)]
6#[derive(Clone, PartialEq)]
7pub enum InputProp {
8 accept(Cow<'static, str>),
9 alt(Cow<'static, str>),
10 autocomplete(Cow<'static, str>),
11 autofocus(bool),
12 default_checked(bool),
13 checked(bool),
14 disabled(bool),
15 files(web_sys::FileList),
16 form_action(Cow<'static, str>),
17 form_enctype(Cow<'static, str>),
18 form_method(Cow<'static, str>),
19 form_no_validate(bool),
20 form_target(Cow<'static, str>),
21 height(u32),
22 indeterminate(bool),
23 input_mode(Cow<'static, str>),
24 max(Cow<'static, str>),
25 max_length(i32),
26 min(Cow<'static, str>),
27 min_length(i32),
28 multiple(bool),
29 name(Cow<'static, str>),
30 pattern(Cow<'static, str>),
31 placeholder(Cow<'static, str>),
32 read_only(bool),
33 required(bool),
34 size(u32),
35 src(Cow<'static, str>),
36 step(Cow<'static, str>),
37 r#type(Cow<'static, str>),
38 default_value(Cow<'static, str>),
39 value(Cow<'static, str>),
40 value_as_number(f64),
41 width(u32),
42 align(Cow<'static, str>),
43 use_map(Cow<'static, str>),
44 webkitdirectory(bool),
45}
46
47#[sealed::sealed]
48impl crate::elem::HtmlComponent for HtmlInputElement {
49 type PropEnum = InputProp;
50}
51#[sealed::sealed]
52impl crate::elem::PropEnum<HtmlInputElement> for InputProp {
53 fn unset_on(&self, elem: &HtmlInputElement) {
54 match self {
55 InputProp::accept(_) => elem.remove_attribute("accept").unwrap(),
56 InputProp::alt(_) => elem.remove_attribute("alt").unwrap(),
57 InputProp::autocomplete(_) => elem.remove_attribute("autocomplete").unwrap(),
58 InputProp::autofocus(_) => elem.remove_attribute("autofocus").unwrap(),
59 InputProp::default_checked(_) => elem.remove_attribute("default_checked").unwrap(),
60 InputProp::checked(_) => elem.remove_attribute("checked").unwrap(),
61 InputProp::disabled(_) => elem.remove_attribute("disabled").unwrap(),
62 InputProp::files(_) => elem.set_files(None),
63 InputProp::form_action(_) => elem.remove_attribute("form_action").unwrap(),
64 InputProp::form_enctype(_) => elem.remove_attribute("form_enctype").unwrap(),
65 InputProp::form_method(_) => elem.remove_attribute("form_method").unwrap(),
66 InputProp::form_no_validate(_) => elem.remove_attribute("form_no_validate").unwrap(),
67 InputProp::form_target(_) => elem.remove_attribute("form_target").unwrap(),
68 InputProp::height(_) => elem.remove_attribute("height").unwrap(),
69 InputProp::indeterminate(_) => elem.remove_attribute("indeterminate").unwrap(),
70 InputProp::input_mode(_) => elem.remove_attribute("input_mode").unwrap(),
71 InputProp::max(_) => elem.remove_attribute("max").unwrap(),
72 InputProp::max_length(_) => elem.remove_attribute("max_length").unwrap(),
73 InputProp::min(_) => elem.remove_attribute("min").unwrap(),
74 InputProp::min_length(_) => elem.remove_attribute("min_length").unwrap(),
75 InputProp::multiple(_) => elem.remove_attribute("multiple").unwrap(),
76 InputProp::name(_) => elem.remove_attribute("name").unwrap(),
77 InputProp::pattern(_) => elem.remove_attribute("pattern").unwrap(),
78 InputProp::placeholder(_) => elem.remove_attribute("placeholder").unwrap(),
79 InputProp::read_only(_) => elem.remove_attribute("read_only").unwrap(),
80 InputProp::required(_) => elem.remove_attribute("required").unwrap(),
81 InputProp::size(_) => elem.remove_attribute("size").unwrap(),
82 InputProp::src(_) => elem.remove_attribute("src").unwrap(),
83 InputProp::step(_) => elem.remove_attribute("step").unwrap(),
84 InputProp::r#type(_) => elem.remove_attribute("type").unwrap(),
85 InputProp::default_value(_) => elem.remove_attribute("default_value").unwrap(),
86 InputProp::value(_) => elem.remove_attribute("value").unwrap(),
87 InputProp::value_as_number(_) => elem.remove_attribute("value_as_number").unwrap(),
88 InputProp::width(_) => elem.remove_attribute("width").unwrap(),
89 InputProp::align(_) => elem.remove_attribute("align").unwrap(),
90 InputProp::use_map(_) => elem.remove_attribute("use_map").unwrap(),
91 InputProp::webkitdirectory(_) => elem.remove_attribute("webkitdirectory").unwrap(),
92 }
93 }
94
95 fn set_on(&self, elem: &HtmlInputElement) {
96 match self {
97 InputProp::accept(v) => elem.set_accept(v),
98 InputProp::alt(v) => elem.set_alt(v),
99 InputProp::autocomplete(v) => elem.set_autocomplete(v),
100 InputProp::autofocus(v) => elem.set_autofocus(*v),
101 InputProp::default_checked(v) => elem.set_default_checked(*v),
102 InputProp::checked(v) => elem.set_checked(*v),
103 InputProp::disabled(v) => elem.set_disabled(*v),
104 InputProp::files(v) => elem.set_files(Some(v)),
105 InputProp::form_action(v) => elem.set_form_action(v),
106 InputProp::form_enctype(v) => elem.set_form_enctype(v),
107 InputProp::form_method(v) => elem.set_form_method(v),
108 InputProp::form_no_validate(v) => elem.set_form_no_validate(*v),
109 InputProp::form_target(v) => elem.set_form_target(v),
110 InputProp::height(v) => elem.set_height(*v),
111 InputProp::indeterminate(v) => elem.set_indeterminate(*v),
112 InputProp::input_mode(v) => elem.set_input_mode(v),
113 InputProp::max(v) => elem.set_max(v),
114 InputProp::max_length(v) => elem.set_max_length(*v),
115 InputProp::min(v) => elem.set_min(v),
116 InputProp::min_length(v) => elem.set_min_length(*v),
117 InputProp::multiple(v) => elem.set_multiple(*v),
118 InputProp::name(v) => elem.set_name(v),
119 InputProp::pattern(v) => elem.set_pattern(v),
120 InputProp::placeholder(v) => elem.set_placeholder(v),
121 InputProp::read_only(v) => elem.set_read_only(*v),
122 InputProp::required(v) => elem.set_required(*v),
123 InputProp::size(v) => elem.set_size(*v),
124 InputProp::src(v) => elem.set_src(v),
125 InputProp::step(v) => elem.set_step(v),
126 InputProp::r#type(v) => elem.set_type(v),
127 InputProp::default_value(v) => elem.set_default_value(v),
128 InputProp::value(v) => elem.set_value(v),
129 InputProp::value_as_number(v) => elem.set_value_as_number(*v),
130 InputProp::width(v) => elem.set_width(*v),
131 InputProp::align(v) => elem.set_align(v),
132 InputProp::use_map(v) => elem.set_use_map(v),
133 InputProp::webkitdirectory(v) => elem.set_webkitdirectory(*v),
134 }
135 }
136}
137
138impl HtmlProps<HtmlInputElement> {
139 pub fn accept(mut self, val: impl Into<Cow<'static, str>>) -> Self {
140 let val = val.into();
141 self.0.push_back(HtmlProp::Own(InputProp::accept(val)));
142 self
143 }
144
145 pub fn alt(mut self, val: impl Into<Cow<'static, str>>) -> Self {
146 let val = val.into();
147 self.0.push_back(HtmlProp::Own(InputProp::alt(val)));
148 self
149 }
150
151 pub fn autocomplete(mut self, val: impl Into<Cow<'static, str>>) -> Self {
152 let val = val.into();
153 self.0
154 .push_back(HtmlProp::Own(InputProp::autocomplete(val)));
155 self
156 }
157
158 pub fn autofocus(mut self, val: bool) -> Self {
159 self.0.push_back(HtmlProp::Own(InputProp::autofocus(val)));
160 self
161 }
162
163 pub fn default_checked(mut self, val: bool) -> Self {
164 self.0
165 .push_back(HtmlProp::Own(InputProp::default_checked(val)));
166 self
167 }
168
169 pub fn checked(mut self, val: bool) -> Self {
170 self.0.push_back(HtmlProp::Own(InputProp::checked(val)));
171 self
172 }
173
174 pub fn disabled(mut self, val: bool) -> Self {
175 self.0.push_back(HtmlProp::Own(InputProp::disabled(val)));
176 self
177 }
178
179 pub fn files(mut self, val: web_sys::FileList) -> Self {
180 self.0.push_back(HtmlProp::Own(InputProp::files(val)));
181 self
182 }
183
184 pub fn form_action(mut self, val: impl Into<Cow<'static, str>>) -> Self {
185 let val = val.into();
186 self.0.push_back(HtmlProp::Own(InputProp::form_action(val)));
187 self
188 }
189
190 pub fn form_enctype(mut self, val: impl Into<Cow<'static, str>>) -> Self {
191 let val = val.into();
192 self.0
193 .push_back(HtmlProp::Own(InputProp::form_enctype(val)));
194 self
195 }
196
197 pub fn form_method(mut self, val: impl Into<Cow<'static, str>>) -> Self {
198 let val = val.into();
199 self.0.push_back(HtmlProp::Own(InputProp::form_method(val)));
200 self
201 }
202
203 pub fn form_no_validate(mut self, val: bool) -> Self {
204 self.0
205 .push_back(HtmlProp::Own(InputProp::form_no_validate(val)));
206 self
207 }
208
209 pub fn form_target(mut self, val: impl Into<Cow<'static, str>>) -> Self {
210 let val = val.into();
211 self.0.push_back(HtmlProp::Own(InputProp::form_target(val)));
212 self
213 }
214
215 pub fn height(mut self, val: u32) -> Self {
216 self.0.push_back(HtmlProp::Own(InputProp::height(val)));
217 self
218 }
219
220 pub fn indeterminate(mut self, val: bool) -> Self {
221 self.0
222 .push_back(HtmlProp::Own(InputProp::indeterminate(val)));
223 self
224 }
225
226 pub fn input_mode(mut self, val: impl Into<Cow<'static, str>>) -> Self {
227 let val = val.into();
228 self.0.push_back(HtmlProp::Own(InputProp::input_mode(val)));
229 self
230 }
231
232 pub fn max(mut self, val: impl Into<Cow<'static, str>>) -> Self {
233 let val = val.into();
234 self.0.push_back(HtmlProp::Own(InputProp::max(val)));
235 self
236 }
237
238 pub fn max_length(mut self, val: i32) -> Self {
239 self.0.push_back(HtmlProp::Own(InputProp::max_length(val)));
240 self
241 }
242
243 pub fn min(mut self, val: impl Into<Cow<'static, str>>) -> Self {
244 let val = val.into();
245 self.0.push_back(HtmlProp::Own(InputProp::min(val)));
246 self
247 }
248
249 pub fn min_length(mut self, val: i32) -> Self {
250 self.0.push_back(HtmlProp::Own(InputProp::min_length(val)));
251 self
252 }
253
254 pub fn multiple(mut self, val: bool) -> Self {
255 self.0.push_back(HtmlProp::Own(InputProp::multiple(val)));
256 self
257 }
258
259 pub fn name(mut self, val: impl Into<Cow<'static, str>>) -> Self {
260 let val = val.into();
261 self.0.push_back(HtmlProp::Own(InputProp::name(val)));
262 self
263 }
264
265 pub fn pattern(mut self, val: impl Into<Cow<'static, str>>) -> Self {
266 let val = val.into();
267 self.0.push_back(HtmlProp::Own(InputProp::pattern(val)));
268 self
269 }
270
271 pub fn placeholder(mut self, val: impl Into<Cow<'static, str>>) -> Self {
272 let val = val.into();
273 self.0.push_back(HtmlProp::Own(InputProp::placeholder(val)));
274 self
275 }
276
277 pub fn read_only(mut self, val: bool) -> Self {
278 self.0.push_back(HtmlProp::Own(InputProp::read_only(val)));
279 self
280 }
281
282 pub fn required(mut self, val: bool) -> Self {
283 self.0.push_back(HtmlProp::Own(InputProp::required(val)));
284 self
285 }
286
287 pub fn size(mut self, val: u32) -> Self {
288 self.0.push_back(HtmlProp::Own(InputProp::size(val)));
289 self
290 }
291
292 pub fn src(mut self, val: impl Into<Cow<'static, str>>) -> Self {
293 let val = val.into();
294 self.0.push_back(HtmlProp::Own(InputProp::src(val)));
295 self
296 }
297
298 pub fn step(mut self, val: impl Into<Cow<'static, str>>) -> Self {
299 let val = val.into();
300 self.0.push_back(HtmlProp::Own(InputProp::step(val)));
301 self
302 }
303
304 pub fn r#type(mut self, val: Cow<'static, str>) -> Self {
305 self.0.push_back(HtmlProp::Own(InputProp::r#type(val)));
306 self
307 }
308
309 pub fn default_value(mut self, val: impl Into<Cow<'static, str>>) -> Self {
310 let val = val.into();
311 self.0
312 .push_back(HtmlProp::Own(InputProp::default_value(val)));
313 self
314 }
315
316 pub fn value(mut self, val: impl Into<Cow<'static, str>>) -> Self {
317 let val = val.into();
318 self.0.push_back(HtmlProp::Own(InputProp::value(val)));
319 self
320 }
321
322 pub fn value_as_number(mut self, val: f64) -> Self {
323 self.0
324 .push_back(HtmlProp::Own(InputProp::value_as_number(val)));
325 self
326 }
327
328 pub fn width(mut self, val: u32) -> Self {
329 self.0.push_back(HtmlProp::Own(InputProp::width(val)));
330 self
331 }
332
333 pub fn align(mut self, val: impl Into<Cow<'static, str>>) -> Self {
334 let val = val.into();
335 self.0.push_back(HtmlProp::Own(InputProp::align(val)));
336 self
337 }
338
339 pub fn use_map(mut self, val: impl Into<Cow<'static, str>>) -> Self {
340 let val = val.into();
341 self.0.push_back(HtmlProp::Own(InputProp::use_map(val)));
342 self
343 }
344
345 pub fn webkitdirectory(mut self, val: bool) -> Self {
346 self.0
347 .push_back(HtmlProp::Own(InputProp::webkitdirectory(val)));
348 self
349 }
350}