use rumtk_core::strings::{rumtk_format, RUMString};
type EventHandler<'a> = (&'a str, &'a str);
type EventHandlers<'a> = Vec<EventHandler<'a>>;
#[derive(Debug, Clone, Default)]
pub struct InputProps<'a> {
pub id: Option<RUMString>,
pub name: Option<RUMString>,
pub typ: Option<RUMString>,
pub value: Option<RUMString>,
pub max: Option<RUMString>,
pub placeholder: Option<RUMString>,
pub pattern: Option<RUMString>,
pub accept: Option<RUMString>,
pub alt: Option<RUMString>,
pub aria_label: Option<RUMString>,
pub event_handlers: Option<EventHandlers<'a>>,
pub max_length: Option<usize>,
pub min_length: Option<usize>,
pub autocapitalize: bool,
pub autocomplete: bool,
pub autocorrect: bool,
pub autofocus: bool,
pub disabled: bool,
pub hidden: bool,
pub required: bool,
}
impl InputProps<'_> {
fn get_handler_string(&self, handlers: &EventHandlers) -> RUMString {
let mut handler_string = RUMString::default();
for (handler_name, handler_function) in handlers {
handler_string += &rumtk_format!(" {}={:?}", handler_name, handler_function);
}
handler_string
}
pub fn to_rumstring(&self) -> RUMString {
let default_text = RUMString::default();
rumtk_format!(
"{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}",
match &self.id {
Some(id) => rumtk_format!("id={:?}", id),
None => default_text.clone(),
},
match &self.name {
Some(name) => rumtk_format!("name={:?}", name),
None => default_text.clone(),
},
match &self.typ {
Some(typ) => rumtk_format!("type={:?}", typ),
None => default_text.clone(),
},
match &self.value {
Some(val) => rumtk_format!("value={:?}", val),
None => default_text.clone(),
},
match &self.max {
Some(val) => rumtk_format!("max={:?}", val),
None => default_text.clone(),
},
match &self.placeholder {
Some(placeholder) => rumtk_format!("placeholder={:?}", placeholder),
None => default_text.clone(),
},
match &self.pattern {
Some(pattern) => rumtk_format!("pattern={:?}", pattern),
None => default_text.clone(),
},
match &self.accept {
Some(accept) => rumtk_format!("accept={:?}", accept),
None => default_text.clone(),
},
match &self.alt {
Some(alt) => rumtk_format!("alt={:?}", alt),
None => default_text.clone(),
},
match &self.aria_label {
Some(aria_label) => rumtk_format!("aria-label={:?}", aria_label),
None => default_text.clone(),
},
match &self.event_handlers {
Some(handlers) => self.get_handler_string(handlers),
None => default_text.clone(),
},
match self.max_length {
Some(max_length) => rumtk_format!("maxlength={:?}", max_length),
None => default_text.clone(),
},
match self.min_length {
Some(min_length) => rumtk_format!("minlength={:?}", min_length),
None => default_text.clone(),
},
match self.autocapitalize {
true => rumtk_format!("autocapitalize"),
false => default_text.clone(),
},
match self.autocomplete {
true => rumtk_format!("autocomplete"),
false => default_text.clone(),
},
match self.autocorrect {
true => rumtk_format!("autocorrect"),
false => default_text.clone(),
},
match self.autofocus {
true => rumtk_format!("autofocus"),
false => default_text.clone(),
},
match self.disabled {
true => rumtk_format!("disabled"),
false => default_text.clone(),
},
match self.hidden {
true => rumtk_format!("hidden"),
false => default_text.clone(),
},
match self.required {
true => rumtk_format!("required"),
false => default_text.clone(),
},
)
}
pub fn to_string(&self) -> String {
self.to_rumstring().to_string()
}
}