rumtk_web/components/form/
props.rs1use rumtk_core::strings::{rumtk_format, RUMString};
24
25type EventHandler<'a> = (&'a str, &'a str);
26type EventHandlers<'a> = Vec<EventHandler<'a>>;
27
28#[derive(Debug, Clone, Default)]
29pub struct InputProps<'a> {
30 pub name: Option<RUMString>,
31 pub typ: Option<RUMString>,
32 pub value: Option<RUMString>,
33 pub max: Option<RUMString>,
34 pub placeholder: Option<RUMString>,
35 pub pattern: Option<RUMString>,
36 pub accept: Option<RUMString>,
37 pub alt: Option<RUMString>,
38 pub aria_label: Option<RUMString>,
39 pub event_handlers: Option<EventHandlers<'a>>,
40 pub max_length: Option<usize>,
41 pub min_length: Option<usize>,
42 pub autocapitalize: bool,
43 pub autocomplete: bool,
44 pub autocorrect: bool,
45 pub autofocus: bool,
46 pub disabled: bool,
47 pub hidden: bool,
48 pub required: bool,
49}
50
51impl InputProps<'_> {
52 fn get_handler_string(&self, handlers: &EventHandlers) -> RUMString {
53 let mut handler_string = RUMString::default();
54
55 for (handler_name, handler_function) in handlers {
56 handler_string += &rumtk_format!(" {}={:?}", handler_name, handler_function);
57 }
58
59 handler_string
60 }
61
62 pub fn to_rumstring(&self) -> RUMString {
63 let default_text = RUMString::default();
64 rumtk_format!(
65 "{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}",
66 match &self.name {
67 Some(name) => rumtk_format!("id={:?}", name),
68 None => default_text.clone(),
69 },
70 match &self.name {
71 Some(name) => rumtk_format!("name={:?}", name),
72 None => default_text.clone(),
73 },
74 match &self.typ {
75 Some(typ) => rumtk_format!("type={:?}", typ),
76 None => default_text.clone(),
77 },
78 match &self.value {
79 Some(val) => rumtk_format!("value={:?}", val),
80 None => default_text.clone(),
81 },
82 match &self.max {
83 Some(val) => rumtk_format!("max={:?}", val),
84 None => default_text.clone(),
85 },
86 match &self.placeholder {
87 Some(placeholder) => rumtk_format!("placeholder={:?}", placeholder),
88 None => default_text.clone(),
89 },
90 match &self.pattern {
91 Some(pattern) => rumtk_format!("pattern={:?}", pattern),
92 None => default_text.clone(),
93 },
94 match &self.accept {
95 Some(accept) => rumtk_format!("accept={:?}", accept),
96 None => default_text.clone(),
97 },
98 match &self.alt {
99 Some(alt) => rumtk_format!("alt={:?}", alt),
100 None => default_text.clone(),
101 },
102 match &self.aria_label {
103 Some(aria_label) => rumtk_format!("aria-label={:?}", aria_label),
104 None => default_text.clone(),
105 },
106 match &self.event_handlers {
107 Some(handlers) => self.get_handler_string(handlers),
108 None => default_text.clone(),
109 },
110 match self.max_length {
111 Some(max_length) => rumtk_format!("maxlength={:?}", max_length),
112 None => default_text.clone(),
113 },
114 match self.min_length {
115 Some(min_length) => rumtk_format!("minlength={:?}", min_length),
116 None => default_text.clone(),
117 },
118 match self.autocapitalize {
119 true => rumtk_format!("autocapitalize"),
120 false => default_text.clone(),
121 },
122 match self.autocomplete {
123 true => rumtk_format!("autocomplete"),
124 false => default_text.clone(),
125 },
126 match self.autocorrect {
127 true => rumtk_format!("autocorrect"),
128 false => default_text.clone(),
129 },
130 match self.autofocus {
131 true => rumtk_format!("autofocus"),
132 false => default_text.clone(),
133 },
134 match self.disabled {
135 true => rumtk_format!("disabled"),
136 false => default_text.clone(),
137 },
138 match self.hidden {
139 true => rumtk_format!("hidden"),
140 false => default_text.clone(),
141 },
142 match self.required {
143 true => rumtk_format!("required"),
144 false => default_text.clone(),
145 },
146 )
147 }
148
149 pub fn to_string(&self) -> String {
150 self.to_rumstring().to_string()
151 }
152}