use crate::element::{Element, HtmlElementConfig};
use super::field::{create_input, create_labeled_input, AsHtmlConfig, InputFieldConfig};
pub struct TimeInputConfigs {
pub list: Option<String>,
pub max: Option<String>,
pub min: Option<String>,
pub read_only: Option<bool>,
}
pub fn create_labeled_time_input(
html_configs: InputFieldConfig,
input_configs: TimeInputConfigs,
value: Option<String>,
) -> Element {
create_labeled_input(html_configs, "time".to_string(), input_configs, value)
}
pub fn create_time_input(
html_configs: InputFieldConfig,
input_configs: TimeInputConfigs,
value: Option<String>,
) -> Element {
create_input(html_configs, "time".to_string(), input_configs, value)
}
impl TimeInputConfigs {
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_max(mut self, max: String) -> Self {
self.max = Some(max);
self
}
pub fn without_max(mut self) -> Self {
self.max = None;
self
}
pub fn with_min(mut self, min: String) -> Self {
self.min = Some(min);
self
}
pub fn without_min(mut self) -> Self {
self.min = 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 TimeInputConfigs {
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 let Some(min) = &self.min {
configs = configs.set_attribute("min".to_string(), Some(min.to_string()));
}
if let Some(max) = &self.max {
configs = configs.set_attribute("max".to_string(), Some(max.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 TimeInputConfigs {
fn default() -> Self {
Self {
list: None,
max: None,
min: None,
read_only: None,
}
}
}