use crate::element::{Element, HtmlElementConfig};
use super::field::{create_input, create_labeled_input, AsHtmlConfig, InputFieldConfig};
pub struct WeekInputConfigs {
pub max: Option<String>,
pub min: Option<String>,
pub step: Option<String>,
pub read_only: Option<bool>,
}
pub fn create_labeled_week_input(
html_configs: InputFieldConfig,
input_configs: WeekInputConfigs,
value: Option<String>,
) -> Element {
create_labeled_input(html_configs, "week".to_string(), input_configs, value)
}
pub fn create_week_input(
html_configs: InputFieldConfig,
input_configs: WeekInputConfigs,
value: Option<String>,
) -> Element {
create_input(html_configs, "week".to_string(), input_configs, value)
}
impl WeekInputConfigs {
pub fn new() -> Self {
Self::default()
}
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_step(mut self, step: String) -> Self {
self.step = Some(step);
self
}
pub fn without_step(mut self) -> Self {
self.step = 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 WeekInputConfigs {
fn set_html_configs(&self, mut configs: HtmlElementConfig) -> HtmlElementConfig {
if self.max.is_some() {
configs = configs.set_attribute("max".to_string(), self.max.clone());
}
if self.min.is_some() {
configs = configs.set_attribute("min".to_string(), self.min.clone());
}
if self.step.is_some() {
configs = configs.set_attribute("step".to_string(), self.step.clone());
}
if let Some(read_only) = self.read_only {
if read_only {
configs = configs.set_attribute("readonly".to_string(), None);
}
}
configs
}
}
impl Default for WeekInputConfigs {
fn default() -> Self {
Self {
max: None,
min: None,
step: None,
read_only: None,
}
}
}