use crate::element::{Element, HtmlElementConfig};
use super::field::{create_input, create_labeled_input, AsHtmlConfig, InputFieldConfig};
pub struct TelInputConfigs {
pub list: Option<String>,
pub pattern: Option<String>,
pub place_holder: Option<String>,
pub min_length: Option<usize>,
pub max_length: Option<usize>,
pub size: Option<usize>,
pub read_only: Option<bool>,
}
pub fn create_labeled_tel_input(
html_configs: InputFieldConfig,
input_configs: TelInputConfigs,
value: Option<String>,
) -> Element {
create_labeled_input(html_configs, "tel".to_string(), input_configs, value)
}
pub fn create_tel_input(
html_configs: InputFieldConfig,
input_configs: TelInputConfigs,
value: Option<String>,
) -> Element {
create_input(html_configs, "tel".to_string(), input_configs, value)
}
impl TelInputConfigs {
pub fn new() -> Self {
Self::default()
}
pub fn with_list(mut self, list: String) -> Self {
self.list = Some(list);
self
}
pub fn without_list(mut self) -> Self {
self.list = None;
self
}
pub fn with_pattern(mut self, pattern: String) -> Self {
self.pattern = Some(pattern);
self
}
pub fn without_pattern(mut self) -> Self {
self.pattern = None;
self
}
pub fn with_place_holder(mut self, place_holder: String) -> Self {
self.place_holder = Some(place_holder);
self
}
pub fn without_place_holder(mut self) -> Self {
self.place_holder = None;
self
}
pub fn with_min_length(mut self, min_length: usize) -> Self {
self.min_length = Some(min_length);
self
}
pub fn without_min_length(mut self) -> Self {
self.min_length = None;
self
}
pub fn with_max_length(mut self, max_length: usize) -> Self {
self.max_length = Some(max_length);
self
}
pub fn without_max_length(mut self) -> Self {
self.max_length = None;
self
}
pub fn with_size(mut self, size: usize) -> Self {
self.size = Some(size);
self
}
pub fn without_size(mut self) -> Self {
self.size = None;
self
}
pub fn with_read_only(mut self, read_only: bool) -> Self {
self.read_only = Some(read_only);
self
}
pub fn without_read_only(mut self) -> Self {
self.read_only = None;
self
}
}
impl AsHtmlConfig for TelInputConfigs {
fn set_html_configs(&self, mut configs: HtmlElementConfig) -> HtmlElementConfig {
if self.list.is_some() {
configs = configs.set_attribute("list".to_string(), self.list.clone());
}
if self.pattern.is_some() {
configs = configs.set_attribute("pattern".to_string(), self.pattern.clone());
}
if self.place_holder.is_some() {
configs = configs.set_attribute("placeholder".to_string(), self.place_holder.clone());
}
if let Some(min_length) = self.min_length {
configs = configs.set_attribute("minlength".to_string(), Some(min_length.to_string()));
}
if let Some(max_length) = self.max_length {
configs = configs.set_attribute("maxlength".to_string(), Some(max_length.to_string()));
}
if let Some(size) = self.size {
configs = configs.set_attribute("size".to_string(), Some(size.to_string()));
}
if let Some(read_only) = self.read_only {
if read_only {
configs = configs.set_attribute("readonly".to_string(), None);
}
}
configs
}
}
impl Default for TelInputConfigs {
fn default() -> Self {
Self {
list: None,
pattern: None,
place_holder: None,
min_length: None,
max_length: None,
size: None,
read_only: None,
}
}
}