use super::{BuilderFn, ControlBuilder, ControlData, ControlRenderData, ValidatedControlData}; use crate::{form::FormToolData, form_builder::FormBuilder, styles::FormStyle}; use leptos::{Signal, View}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TextInputData { pub(crate) name: String, pub(crate) placeholder: Option, pub(crate) label: Option, pub(crate) initial_text: String, pub(crate) input_type: &'static str, } impl Default for TextInputData { fn default() -> Self { TextInputData { name: String::new(), placeholder: None, label: None, initial_text: String::new(), input_type: "input", } } } impl ControlData for TextInputData { type ReturnType = String; fn build_control( fs: &FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, validation_state: Signal>, ) -> View { fs.text_input(control, value_getter, value_setter, validation_state) } } impl ValidatedControlData for TextInputData {} impl FormBuilder { pub fn text_input( self, builder: impl BuilderFn, FD::Context>, ) -> Self { self.new_control(builder) } } impl ControlBuilder { pub fn named(mut self, control_name: impl ToString) -> Self { self.data.name = control_name.to_string(); self } pub fn placeholder(mut self, placeholder: impl ToString) -> Self { self.data.placeholder = Some(placeholder.to_string()); self } pub fn label(mut self, label: impl ToString) -> Self { self.data.label = Some(label.to_string()); self } pub fn initial_text(mut self, text: impl ToString) -> Self { self.data.initial_text = text.to_string(); self } pub fn password(mut self) -> Self { self.data.input_type = "password"; self } }