use crate::element::{Element, HtmlElementConfig};
use super::field::{create_input, AsHtmlConfig, InputFieldConfig};
pub struct ImageInputConfigs {
pub alt: Option<String>,
pub width: Option<usize>,
pub height: Option<usize>,
pub formaction: Option<String>,
pub formenctype: Option<String>,
pub formmethod: Option<String>,
pub formnovalidate: Option<bool>,
pub formtarget: Option<String>,
}
pub fn create_image_input(
html_configs: InputFieldConfig,
input_configs: ImageInputConfigs,
) -> Element {
create_input(html_configs, "image".to_string(), input_configs, None)
}
impl ImageInputConfigs {
pub fn new() -> Self {
Self::default()
}
pub fn with_alt(mut self, alt: String) -> Self {
self.alt = Some(alt);
self
}
pub fn without_alt(mut self) -> Self {
self.alt = None;
self
}
pub fn with_width(mut self, width: usize) -> Self {
self.width = Some(width);
self
}
pub fn without_width(mut self) -> Self {
self.width = None;
self
}
pub fn with_height(mut self, height: usize) -> Self {
self.height = Some(height);
self
}
pub fn without_height(mut self) -> Self {
self.height = None;
self
}
pub fn with_formaction(mut self, formaction: String) -> Self {
self.formaction = Some(formaction);
self
}
pub fn without_formaction(mut self) -> Self {
self.formaction = None;
self
}
pub fn with_formenctype(mut self, formenctype: String) -> Self {
self.formenctype = Some(formenctype);
self
}
pub fn without_formenctype(mut self) -> Self {
self.formenctype = None;
self
}
pub fn with_formmethod(mut self, formmethod: String) -> Self {
self.formmethod = Some(formmethod);
self
}
pub fn without_formmethod(mut self) -> Self {
self.formmethod = None;
self
}
pub fn with_formnovalidate(mut self, formnovalidate: bool) -> Self {
self.formnovalidate = Some(formnovalidate);
self
}
pub fn without_formnovalidate(mut self) -> Self {
self.formnovalidate = None;
self
}
pub fn with_formtarget(mut self, formtarget: String) -> Self {
self.formtarget = Some(formtarget);
self
}
pub fn without_formtarget(mut self) -> Self {
self.formtarget = None;
self
}
}
impl AsHtmlConfig for ImageInputConfigs {
fn set_html_configs(&self, mut configs: HtmlElementConfig) -> HtmlElementConfig {
if self.alt.is_some() {
configs = configs.set_attribute("alt".to_string(), self.alt.clone())
}
if self.formaction.is_some() {
configs = configs.set_attribute("formaction".to_string(), self.formaction.clone());
}
if self.formenctype.is_some() {
configs = configs.set_attribute("formenctype".to_string(), self.formenctype.clone());
}
if self.formmethod.is_some() {
configs = configs.set_attribute("formmethod".to_string(), self.formmethod.clone());
}
if let Some(formnovalidate) = self.formnovalidate {
if formnovalidate {
configs = configs.set_attribute("formnovalidate".to_string(), None);
}
}
if self.formtarget.is_some() {
configs = configs.set_attribute("formtarget".to_string(), self.formtarget.clone());
}
if let Some(width) = self.width {
configs = configs.set_attribute("width".to_string(), Some(width.to_string()));
}
if let Some(height) = self.height {
configs = configs.set_attribute("height".to_string(), Some(height.to_string()));
}
configs
}
}
impl Default for ImageInputConfigs {
fn default() -> Self {
Self {
alt: None,
width: None,
height: None,
formaction: None,
formenctype: None,
formmethod: None,
formnovalidate: None,
formtarget: None,
}
}
}