1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
use crate::elem::{HtmlProp, HtmlProps}; use std::borrow::Cow; use web_sys::HtmlTextAreaElement; #[allow(non_camel_case_types)] #[derive(Clone, PartialEq)] pub enum TextAreaProp { autocomplete(Cow<'static, str>), autofocus(bool), cols(u32), disabled(bool), max_length(i32), min_length(i32), name(Cow<'static, str>), placeholder(Cow<'static, str>), read_only(bool), required(bool), rows(u32), wrap(Cow<'static, str>), value(Cow<'static, str>), } #[sealed::sealed] impl crate::elem::HtmlComponent for HtmlTextAreaElement { type PropEnum = TextAreaProp; } #[sealed::sealed] impl crate::elem::PropEnum<HtmlTextAreaElement> for TextAreaProp { fn unset_on(&self, elem: &HtmlTextAreaElement) { match self { TextAreaProp::autocomplete(_) => elem.remove_attribute("autocomplete").unwrap(), TextAreaProp::autofocus(_) => elem.remove_attribute("autofocus").unwrap(), TextAreaProp::cols(_) => elem.remove_attribute("cols").unwrap(), TextAreaProp::disabled(_) => elem.remove_attribute("disabled").unwrap(), TextAreaProp::max_length(_) => elem.remove_attribute("max_length").unwrap(), TextAreaProp::min_length(_) => elem.remove_attribute("min_length").unwrap(), TextAreaProp::name(_) => elem.remove_attribute("name").unwrap(), TextAreaProp::placeholder(_) => elem.remove_attribute("placeholder").unwrap(), TextAreaProp::read_only(_) => elem.remove_attribute("read_only").unwrap(), TextAreaProp::required(_) => elem.remove_attribute("required").unwrap(), TextAreaProp::rows(_) => elem.remove_attribute("rows").unwrap(), TextAreaProp::wrap(_) => elem.remove_attribute("wrap").unwrap(), TextAreaProp::value(_) => elem.remove_attribute("value").unwrap(), } } fn set_on(&self, elem: &HtmlTextAreaElement) { match self { TextAreaProp::autocomplete(v) => elem.set_autocomplete(v), TextAreaProp::autofocus(v) => elem.set_autofocus(*v), TextAreaProp::cols(v) => elem.set_cols(*v), TextAreaProp::disabled(v) => elem.set_disabled(*v), TextAreaProp::max_length(v) => elem.set_max_length(*v), TextAreaProp::min_length(v) => elem.set_min_length(*v), TextAreaProp::name(v) => elem.set_name(v), TextAreaProp::placeholder(v) => elem.set_placeholder(v), TextAreaProp::read_only(v) => elem.set_read_only(*v), TextAreaProp::required(v) => elem.set_required(*v), TextAreaProp::rows(v) => elem.set_rows(*v), TextAreaProp::wrap(v) => elem.set_wrap(v), TextAreaProp::value(v) => elem.set_value(v), } } } impl HtmlProps<HtmlTextAreaElement> { pub fn autocomplete(mut self, val: impl Into<Cow<'static, str>>) -> Self { let val = val.into(); self.0 .push_back(HtmlProp::Own(TextAreaProp::autocomplete(val))); self } pub fn autofocus(mut self, val: bool) -> Self { self.0 .push_back(HtmlProp::Own(TextAreaProp::autofocus(val))); self } pub fn cols(mut self, val: u32) -> Self { self.0.push_back(HtmlProp::Own(TextAreaProp::cols(val))); self } pub fn disabled(mut self, val: bool) -> Self { self.0.push_back(HtmlProp::Own(TextAreaProp::disabled(val))); self } pub fn max_length(mut self, val: i32) -> Self { self.0 .push_back(HtmlProp::Own(TextAreaProp::max_length(val))); self } pub fn min_length(mut self, val: i32) -> Self { self.0 .push_back(HtmlProp::Own(TextAreaProp::min_length(val))); self } pub fn name(mut self, val: impl Into<Cow<'static, str>>) -> Self { let val = val.into(); self.0.push_back(HtmlProp::Own(TextAreaProp::name(val))); self } pub fn placeholder(mut self, val: impl Into<Cow<'static, str>>) -> Self { let val = val.into(); self.0 .push_back(HtmlProp::Own(TextAreaProp::placeholder(val))); self } pub fn read_only(mut self, val: bool) -> Self { self.0 .push_back(HtmlProp::Own(TextAreaProp::read_only(val))); self } pub fn required(mut self, val: bool) -> Self { self.0.push_back(HtmlProp::Own(TextAreaProp::required(val))); self } pub fn rows(mut self, val: u32) -> Self { self.0.push_back(HtmlProp::Own(TextAreaProp::rows(val))); self } pub fn wrap(mut self, val: impl Into<Cow<'static, str>>) -> Self { let val = val.into(); self.0.push_back(HtmlProp::Own(TextAreaProp::wrap(val))); self } pub fn value(mut self, val: impl Into<Cow<'static, str>>) -> Self { let val = val.into(); self.0.push_back(HtmlProp::Own(TextAreaProp::value(val))); self } }